Skip to content

Commit

Permalink
core: fix underflow issues, move contract creation
Browse files Browse the repository at this point in the history
  • Loading branch information
MariusVanDerWijden committed Feb 28, 2024
1 parent 6bd424f commit b04762c
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions core/state_transition.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,15 @@ func IntrinsicGas(data []byte, accessList types.AccessList, isContractCreation b
dataLen := uint64(len(data))
// Bump the required gas by the amount of transactional data
if dataLen > 0 {
// Charge for the contract creation
if isContractCreation && isEIP3860 {
lenWords := toWordSize(dataLen)
if (math.MaxUint64-gas)/params.InitCodeWordGas < lenWords {
return 0, ErrGasUintOverflow
}
gas += lenWords * params.InitCodeWordGas
}

// Zero and non-zero bytes are priced differently
var nz uint64
for _, byt := range data {
Expand All @@ -97,19 +106,11 @@ func IntrinsicGas(data []byte, accessList types.AccessList, isContractCreation b
gasForData += nz * nonZeroGas

z := dataLen - nz
if (math.MaxUint64-gas)/params.TxDataZeroGas < z {
if (math.MaxUint64-gas-gasForData)/params.TxDataZeroGas < z {
return 0, ErrGasUintOverflow
}
gasForData += z * params.TxDataZeroGas

if isContractCreation && isEIP3860 {
lenWords := toWordSize(dataLen)
if (math.MaxUint64-gas)/params.InitCodeWordGas < lenWords {
return 0, ErrGasUintOverflow
}
gas += lenWords * params.InitCodeWordGas
}

if isEIP7623 {
tokens := z + nz*params.TokenPerNonZeroByte7623
if (math.MaxUint64-gas-gasForData)/params.CostFloorPerToken7623 < tokens {
Expand Down

0 comments on commit b04762c

Please sign in to comment.