From 3777222b865d0b289cd0ae779fb0d41be361b5af Mon Sep 17 00:00:00 2001 From: Guillaume Ballet <3272758+gballet@users.noreply.github.com> Date: Thu, 2 May 2024 17:00:44 +0200 Subject: [PATCH] Focus on gas charges and remove witness-building parts Co-authored-by: Gary Rong --- consensus/beacon/consensus.go | 6 ------ core/state/access_events.go | 6 +----- core/state/statedb.go | 3 +++ core/state_processor.go | 3 --- params/config.go | 7 ++++--- 5 files changed, 8 insertions(+), 17 deletions(-) diff --git a/consensus/beacon/consensus.go b/consensus/beacon/consensus.go index 7d5007f241..4e3fbeb09a 100644 --- a/consensus/beacon/consensus.go +++ b/consensus/beacon/consensus.go @@ -360,12 +360,6 @@ func (beacon *Beacon) Finalize(chain consensus.ChainHeaderReader, header *types. amount := new(uint256.Int).SetUint64(w.Amount) amount = amount.Mul(amount, uint256.NewInt(params.GWei)) state.AddBalance(w.Address, amount, tracing.BalanceIncreaseWithdrawal) - - // Add the balance of each withdrawal to the witness, no gas will - // be charged. - if chain.Config().IsEIP4762(header.Number, header.Time) { - state.AccessEvents().BalanceGas(w.Address[:], true) - } } // No block reward which is issued by consensus layer instead. } diff --git a/core/state/access_events.go b/core/state/access_events.go index 025237b339..e8f58318af 100644 --- a/core/state/access_events.go +++ b/core/state/access_events.go @@ -66,7 +66,7 @@ func (ae *AccessEvents) Merge(other *AccessEvents) { } } -// Key returns, predictably, the list of keys that were touched during the +// Keys returns, predictably, the list of keys that were touched during the // buildup of the access witness. func (ae *AccessEvents) Keys() [][]byte { // TODO: consider if parallelizing this is worth it, probably depending on len(ae.chunks). @@ -173,7 +173,6 @@ func (ae *AccessEvents) touchAddressAndChargeGas(addr []byte, treeIndex uint256. if selectorFill { gas += params.WitnessChunkFillCost } - return gas } @@ -206,10 +205,8 @@ func (ae *AccessEvents) touchAddress(addr []byte, treeIndex uint256.Int, subInde chunkWrite = true ae.chunks[chunkKey] |= AccessWitnessWriteFlag } - // TODO: charge chunk filling costs if the leaf was previously empty in the state } - return branchRead, chunkRead, branchWrite, chunkWrite, chunkFill } @@ -268,7 +265,6 @@ func (ae *AccessEvents) CodeChunksRangeGas(contractAddr []byte, startPC, size ui panic("overflow when adding gas") } } - return statelessGasCharged } diff --git a/core/state/statedb.go b/core/state/statedb.go index 008de7994e..7345b1348b 100644 --- a/core/state/statedb.go +++ b/core/state/statedb.go @@ -1297,6 +1297,9 @@ func (s *StateDB) Commit(block uint64, deleteEmptyObjects bool) (common.Hash, er // - Add coinbase to access list (EIP-3651) // - Reset transient storage (EIP-1153) func (s *StateDB) Prepare(rules params.Rules, sender, coinbase common.Address, dst *common.Address, precompiles []common.Address, list types.AccessList) { + if rules.IsEIP2929 && rules.IsEIP4762 { + panic("eip2929 and eip4762 are both activated") + } if rules.IsEIP2929 { // Clear out any leftover from previous executions al := newAccessList() diff --git a/core/state_processor.go b/core/state_processor.go index 66de959543..f73a908ad2 100644 --- a/core/state_processor.go +++ b/core/state_processor.go @@ -208,8 +208,5 @@ func ProcessBeaconBlockRoot(beaconRoot common.Hash, vmenv *vm.EVM, statedb *stat statedb.AddAddressToAccessList(params.BeaconRootsAddress) } _, _, _ = vmenv.Call(vm.AccountRef(msg.From), *msg.To, msg.Data, 30_000_000, common.U2560) - if vmenv.ChainConfig().Rules(vmenv.Context.BlockNumber, true, vmenv.Context.Time).IsEIP4762 { - statedb.AccessEvents().Merge(txctx.AccessEvents) - } statedb.Finalise(true) } diff --git a/params/config.go b/params/config.go index 176738b868..5fedfd3519 100644 --- a/params/config.go +++ b/params/config.go @@ -921,6 +921,7 @@ func (c *ChainConfig) Rules(num *big.Int, isMerge bool, timestamp uint64) Rules } // disallow setting Merge out of order isMerge = isMerge && c.IsLondon(num) + isVerkle := isMerge && c.IsVerkle(num, timestamp) return Rules{ ChainID: new(big.Int).Set(chainID), IsHomestead: c.IsHomestead(num), @@ -932,13 +933,13 @@ func (c *ChainConfig) Rules(num *big.Int, isMerge bool, timestamp uint64) Rules IsPetersburg: c.IsPetersburg(num), IsIstanbul: c.IsIstanbul(num), IsBerlin: c.IsBerlin(num), - IsEIP2929: c.IsBerlin(num) && !c.IsVerkle(num, timestamp), - IsEIP4762: c.IsVerkle(num, timestamp), + IsEIP2929: c.IsBerlin(num) && !isVerkle, IsLondon: c.IsLondon(num), IsMerge: isMerge, IsShanghai: isMerge && c.IsShanghai(num, timestamp), IsCancun: isMerge && c.IsCancun(num, timestamp), IsPrague: isMerge && c.IsPrague(num, timestamp), - IsVerkle: isMerge && c.IsVerkle(num, timestamp), + IsVerkle: isVerkle, + IsEIP4762: isVerkle, } }