Skip to content

Commit 80320a0

Browse files
committed
add block hash to witness, plus various cleanups
1 parent 9624a66 commit 80320a0

File tree

7 files changed

+26
-5
lines changed

7 files changed

+26
-5
lines changed

core/state/statedb.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,11 @@ func (s *StateDB) WithWitness(witness *stateless.Witness) {
167167
s.witness = witness
168168
}
169169

170+
// Witness returns the current witness for the state database.
171+
func (s *StateDB) Witness() *stateless.Witness {
172+
return s.witness
173+
}
174+
170175
// StartPrefetcher initializes a new trie prefetcher to pull in nodes from the
171176
// state trie concurrently while the state is mutated so that when we reach the
172177
// commit phase, most of the needed data is already hot.

core/state_processor.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ func ApplyTransaction(config *params.ChainConfig, bc ChainContext, author *commo
206206

207207
// ProcessParentBlockHash stores the parent block hash in the history storage contract
208208
// as per EIP-2935.
209-
func ProcessParentBlockHash(prevHash common.Hash, vmenv *vm.EVM, statedb *state.StateDB) {
209+
func ProcessParentBlockHash(prevHash common.Hash, evm *vm.EVM, statedb *state.StateDB) {
210210
msg := types.NewMessage(
211211
params.SystemAddress, // from
212212
&params.HistoryStorageAddress, // to
@@ -222,8 +222,11 @@ func ProcessParentBlockHash(prevHash common.Hash, vmenv *vm.EVM, statedb *state.
222222
nil, // setCodeAuthorizations
223223
)
224224

225-
vmenv.Reset(NewEVMTxContext(msg), statedb)
225+
evm.Reset(NewEVMTxContext(msg), statedb)
226226
statedb.AddAddressToAccessList(params.HistoryStorageAddress)
227-
_, _, _ = vmenv.Call(vm.AccountRef(msg.From()), *msg.To(), msg.Data(), 30_000_000, common.Big0, nil)
227+
_, _, err := evm.Call(vm.AccountRef(msg.From()), *msg.To(), msg.Data(), 30_000_000, common.Big0, nil)
228+
if err != nil {
229+
panic(err)
230+
}
228231
statedb.Finalise(true)
229232
}

core/state_transition.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -398,6 +398,7 @@ func (st *StateTransition) TransitionDb() (*ExecutionResult, error) {
398398
// Check clauses 4-5, subtract intrinsic gas if everything is correct
399399
gas, err := IntrinsicGas(st.data, st.msg.AccessList(), st.msg.SetCodeAuthorizations(), contractCreation, rules.IsHomestead, rules.IsIstanbul, rules.IsShanghai)
400400
if err != nil {
401+
// Note: The L1 message queue contract ensures that this cannot happen for L1 messages.
401402
return nil, err
402403
}
403404
if st.gas < gas {
@@ -481,8 +482,7 @@ func (st *StateTransition) TransitionDb() (*ExecutionResult, error) {
481482
}
482483

483484
// Compute refund counter, capped to a refund quotient.
484-
gasRefund := st.calcRefund()
485-
st.gas += gasRefund
485+
st.gas += st.calcRefund()
486486
if rules.IsFeynman {
487487
// After EIP-7623: Data-heavy transactions pay the floor gas.
488488
if st.gasUsed() < floorDataGas {

core/vm/instructions.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -486,6 +486,9 @@ func opBlockhashPostFeynman(pc *uint64, interpreter *EVMInterpreter, scope *Scop
486486
}
487487
if num64 >= lower && num64 < upper {
488488
res := interpreter.evm.Context.GetHash(num64)
489+
if witness := interpreter.evm.StateDB.Witness(); witness != nil {
490+
witness.AddBlockHash(num64)
491+
}
489492
num.SetBytes(res[:])
490493
} else {
491494
num.Clear()

core/vm/interface.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
"math/big"
2121

2222
"github.com/scroll-tech/go-ethereum/common"
23+
"github.com/scroll-tech/go-ethereum/core/stateless"
2324
"github.com/scroll-tech/go-ethereum/core/types"
2425
"github.com/scroll-tech/go-ethereum/params"
2526
)
@@ -85,6 +86,8 @@ type StateDB interface {
8586
AddPreimage(common.Hash, []byte)
8687

8788
ForEachStorage(common.Address, func(common.Hash, common.Hash) bool) error
89+
90+
Witness() *stateless.Witness
8891
}
8992

9093
// CallContext provides a basic interface for the EVM calling conventions. The EVM

miner/scroll_worker.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -627,16 +627,19 @@ func (w *worker) tryCommitNewWork(now time.Time, parent common.Hash, reorging bo
627627

628628
// handleForks
629629
func (w *worker) handleForks() (bool, error) {
630+
// Apply Curie predeployed contract update
630631
if w.chainConfig.CurieBlock != nil && w.chainConfig.CurieBlock.Cmp(w.current.header.Number) == 0 {
631632
misc.ApplyCurieHardFork(w.current.state)
632633
return true, nil
633634
}
634635

636+
// Stop/start miner at Euclid fork boundary on zktrie/mpt nodes
635637
if w.chainConfig.IsEuclid(w.current.header.Time) {
636638
parent := w.chain.GetBlockByHash(w.current.header.ParentHash)
637639
return parent != nil && !w.chainConfig.IsEuclid(parent.Time()), nil
638640
}
639641

642+
// Apply EIP-2935
640643
if w.chainConfig.IsFeynman(w.current.header.Time) {
641644
context := core.NewEVMBlockContext(w.current.header, w.chain, w.chainConfig, nil)
642645
vmenv := vm.NewEVM(context, vm.TxContext{}, w.current.state, w.chainConfig, vm.Config{})

params/protocol_params.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,12 +181,16 @@ const (
181181
// Gas discount table for BLS12-381 G1 and G2 multi exponentiation operations
182182
var Bls12381MultiExpDiscountTable = [128]uint64{1200, 888, 764, 641, 594, 547, 500, 453, 438, 423, 408, 394, 379, 364, 349, 334, 330, 326, 322, 318, 314, 310, 306, 302, 298, 294, 289, 285, 281, 277, 273, 269, 268, 266, 265, 263, 262, 260, 259, 257, 256, 254, 253, 251, 250, 248, 247, 245, 244, 242, 241, 239, 238, 236, 235, 233, 232, 231, 229, 228, 226, 225, 223, 222, 221, 220, 219, 219, 218, 217, 216, 216, 215, 214, 213, 213, 212, 211, 211, 210, 209, 208, 208, 207, 206, 205, 205, 204, 203, 202, 202, 201, 200, 199, 199, 198, 197, 196, 196, 195, 194, 193, 193, 192, 191, 191, 190, 189, 188, 188, 187, 186, 185, 185, 184, 183, 182, 182, 181, 180, 179, 179, 178, 177, 176, 176, 175, 174}
183183

184+
// Difficulty parameters.
184185
var (
185186
DifficultyBoundDivisor = big.NewInt(2048) // The bound divisor of the difficulty, used in the update calculations.
186187
GenesisDifficulty = big.NewInt(131072) // Difficulty of the Genesis block.
187188
MinimumDifficulty = big.NewInt(131072) // The minimum that the difficulty may ever be.
188189
DurationLimit = big.NewInt(13) // The decision boundary on the blocktime duration used to determine whether difficulty should go up or not.
190+
)
189191

192+
// System contracts.
193+
var (
190194
// SystemAddress is where the system-transaction is sent from as per EIP-4788
191195
SystemAddress = common.HexToAddress("0xfffffffffffffffffffffffffffffffffffffffe")
192196

0 commit comments

Comments
 (0)