-
Notifications
You must be signed in to change notification settings - Fork 13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fill fixes continued #519
Fill fixes continued #519
Changes from 4 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,8 @@ on: | |
push: | ||
branches: [master] | ||
pull_request: | ||
branches: [master, kaustinen-with-shapella] | ||
branches: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ditto. |
||
[master, kaustinen-with-shapella, witness-charging-order-with-limits] | ||
gballet marked this conversation as resolved.
Show resolved
Hide resolved
|
||
workflow_dispatch: | ||
|
||
env: | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,7 +20,6 @@ import ( | |
"encoding/binary" | ||
|
||
"github.com/ethereum/go-ethereum/common" | ||
"github.com/ethereum/go-ethereum/common/math" | ||
"github.com/ethereum/go-ethereum/core/state" | ||
"github.com/ethereum/go-ethereum/core/types" | ||
"github.com/ethereum/go-ethereum/crypto" | ||
|
@@ -459,11 +458,11 @@ func opGasprice(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) ([ | |
return nil, nil | ||
} | ||
|
||
func getBlockHashFromContract(number uint64, statedb StateDB, witness *state.AccessWitness) (common.Hash, uint64) { | ||
func getBlockHashFromContract(number uint64, statedb StateDB, witness *state.AccessWitness, availableGas uint64) (common.Hash, uint64) { | ||
ringIndex := number % params.Eip2935BlockHashHistorySize | ||
var pnum common.Hash | ||
binary.BigEndian.PutUint64(pnum[24:], ringIndex) | ||
statelessGas := witness.TouchSlotAndChargeGas(params.HistoryStorageAddress[:], pnum, false, math.MaxUint64, false) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This was incorrect -- we don't have infinite amount of gas. This method is only called from |
||
statelessGas := witness.TouchSlotAndChargeGas(params.HistoryStorageAddress[:], pnum, false, availableGas, false) | ||
return statedb.GetState(params.HistoryStorageAddress, pnum), statelessGas | ||
} | ||
|
||
|
@@ -487,7 +486,7 @@ func opBlockhash(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) ( | |
if num64 >= lower && num64 < upper { | ||
// if Verkle is active, read it from the history contract (EIP 2935). | ||
if evm.chainRules.IsVerkle { | ||
blockHash, statelessGas := getBlockHashFromContract(num64, evm.StateDB, evm.Accesses) | ||
blockHash, statelessGas := getBlockHashFromContract(num64, evm.StateDB, evm.Accesses, scope.Contract.Gas) | ||
if interpreter.evm.chainRules.IsEIP4762 { | ||
if !scope.Contract.UseGas(statelessGas) { | ||
return nil, ErrOutOfGas | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -111,7 +111,12 @@ func gasSelfdestructEIP4762(evm *EVM, contract *Contract, stack *Stack, mem *Mem | |
beneficiaryAddr := common.Address(stack.peek().Bytes20()) | ||
contractAddr := contract.Address() | ||
|
||
statelessGas := evm.Accesses.TouchBasicData(contractAddr[:], false, contract.Gas, false) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. TL;DR: everything in SELFDESTRUCT was ignoring if we had enough gas. |
||
wanted := evm.Accesses.TouchBasicData(contractAddr[:], false, contract.Gas, false) | ||
if wanted > contract.Gas { | ||
return wanted, nil | ||
} | ||
statelessGas := wanted | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we could change |
||
|
||
balanceIsZero := evm.StateDB.GetBalance(contractAddr).Sign() == 0 | ||
_, isPrecompile := evm.precompile(beneficiaryAddr) | ||
isSystemContract := evm.isSystemContract(beneficiaryAddr) | ||
|
@@ -121,21 +126,30 @@ func gasSelfdestructEIP4762(evm *EVM, contract *Contract, stack *Stack, mem *Mem | |
} | ||
|
||
if contractAddr != beneficiaryAddr { | ||
statelessGas += evm.Accesses.TouchBasicData(beneficiaryAddr[:], false, contract.Gas-statelessGas, false) | ||
wanted := evm.Accesses.TouchBasicData(beneficiaryAddr[:], false, contract.Gas-statelessGas, false) | ||
if wanted > contract.Gas-statelessGas { | ||
return statelessGas + wanted, nil | ||
} | ||
statelessGas += wanted | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. right, but it would only save one line and not be used for anything afterwards. No point in making the PR footprint larger for that. |
||
} | ||
// Charge write costs if it transfers value | ||
if !balanceIsZero { | ||
statelessGas += evm.Accesses.TouchBasicData(contractAddr[:], true, contract.Gas-statelessGas, false) | ||
wanted := evm.Accesses.TouchBasicData(contractAddr[:], true, contract.Gas-statelessGas, false) | ||
if wanted > contract.Gas-statelessGas { | ||
return statelessGas + wanted, nil | ||
} | ||
statelessGas += wanted | ||
|
||
if contractAddr != beneficiaryAddr { | ||
if evm.StateDB.Exist(beneficiaryAddr) { | ||
statelessGas += evm.Accesses.TouchBasicData(beneficiaryAddr[:], true, contract.Gas-statelessGas, false) | ||
wanted = evm.Accesses.TouchBasicData(beneficiaryAddr[:], true, contract.Gas-statelessGas, false) | ||
} else { | ||
wanted := evm.Accesses.TouchFullAccount(beneficiaryAddr[:], true, contract.Gas-statelessGas) | ||
if wanted > contract.Gas-statelessGas { | ||
return statelessGas + wanted, nil | ||
} | ||
statelessGas += wanted | ||
wanted = evm.Accesses.TouchFullAccount(beneficiaryAddr[:], true, contract.Gas-statelessGas) | ||
} | ||
if wanted > contract.Gas-statelessGas { | ||
return statelessGas + wanted, nil | ||
} | ||
statelessGas += wanted | ||
} | ||
} | ||
return statelessGas, nil | ||
|
@@ -158,7 +172,7 @@ func gasExtCodeCopyEIP4762(evm *EVM, contract *Contract, stack *Stack, mem *Memo | |
} | ||
return gas, nil | ||
} | ||
wgas := evm.Accesses.TouchBasicData(addr[:], false, contract.Gas, true) | ||
wgas := evm.Accesses.TouchBasicData(addr[:], false, contract.Gas-gas, true) | ||
Comment on lines
-161
to
+175
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We where using more gas than truly available. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
var overflow bool | ||
if gas, overflow = math.SafeAdd(gas, wgas); overflow { | ||
return 0, ErrGasUintOverflow | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove this diff when the PR is about to be merged.