Skip to content

Commit

Permalink
core: align overflow checks in IntrinsicGas
Browse files Browse the repository at this point in the history
  • Loading branch information
Kourin1996 committed Dec 18, 2024
1 parent 1321a42 commit c40cb1b
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions core/state_transition.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down

0 comments on commit c40cb1b

Please sign in to comment.