From c40cb1be5f2ed350de4d1a31e9035adbbc8163d3 Mon Sep 17 00:00:00 2001 From: kourin Date: Wed, 18 Dec 2024 18:47:53 +0900 Subject: [PATCH] core: align overflow checks in IntrinsicGas --- core/state_transition.go | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/core/state_transition.go b/core/state_transition.go index 58728e470e46..af86e046a57e 100644 --- a/core/state_transition.go +++ b/core/state_transition.go @@ -110,11 +110,24 @@ func IntrinsicGas(data []byte, accessList types.AccessList, authList []types.Aut } } if accessList != nil { - gas += uint64(len(accessList)) * params.TxAccessListAddressGas - gas += uint64(accessList.StorageKeys()) * params.TxAccessListStorageKeyGas + numItems := uint64(len(accessList)) + if (math.MaxUint64-gas)/params.TxAccessListAddressGas < numItems { + return 0, ErrGasUintOverflow + } + gas += numItems * params.TxAccessListAddressGas + + numStorageKeys := uint64(accessList.StorageKeys()) + if (math.MaxUint64-gas)/params.TxAccessListStorageKeyGas < numStorageKeys { + return 0, ErrGasUintOverflow + } + gas += numStorageKeys * params.TxAccessListStorageKeyGas } if authList != nil { - gas += uint64(len(authList)) * params.CallNewAccountGas + numItems := uint64(len(authList)) + if (math.MaxUint64-gas)/params.CallNewAccountGas < numItems { + return 0, ErrGasUintOverflow + } + gas += numItems * params.CallNewAccountGas } return gas, nil }