Skip to content

Commit 0689b35

Browse files
authored
Merge branch 'develop' into feat-mainnet-euclid-params
2 parents 25eb95c + 6451c80 commit 0689b35

File tree

3 files changed

+45
-20
lines changed

3 files changed

+45
-20
lines changed

core/blockchain.go

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,18 @@ var defaultCacheConfig = &CacheConfig{
149149
SnapshotWait: true,
150150
}
151151

152+
func updateHeadL1msgGauge(block *types.Block) {
153+
for _, tx := range block.Transactions() {
154+
if msg := tx.AsL1MessageTx(); msg != nil {
155+
// Queue index is guaranteed to fit into int64.
156+
headL1MessageGauge.Update(int64(msg.QueueIndex))
157+
} else {
158+
// No more L1 messages in this block.
159+
break
160+
}
161+
}
162+
}
163+
152164
// BlockChain represents the canonical chain given a database with a genesis
153165
// block. The Blockchain manages chain imports, reverts, chain reorganisations.
154166
//
@@ -423,6 +435,9 @@ func NewBlockChain(db ethdb.Database, cacheConfig *CacheConfig, chainConfig *par
423435
triedb.SaveCachePeriodically(bc.cacheConfig.TrieCleanJournal, bc.cacheConfig.TrieCleanRejournal, bc.quit)
424436
}()
425437
}
438+
439+
updateHeadL1msgGauge(bc.CurrentBlock())
440+
426441
return bc, nil
427442
}
428443

@@ -1255,15 +1270,7 @@ func (bc *BlockChain) writeBlockWithState(block *types.Block, receipts []*types.
12551270
}
12561271

12571272
// Note the latest relayed L1 message queue index (if any)
1258-
for _, tx := range block.Transactions() {
1259-
if msg := tx.AsL1MessageTx(); msg != nil {
1260-
// Queue index is guaranteed to fit into int64.
1261-
headL1MessageGauge.Update(int64(msg.QueueIndex))
1262-
} else {
1263-
// No more L1 messages in this block.
1264-
break
1265-
}
1266-
}
1273+
updateHeadL1msgGauge(block)
12671274

12681275
parent := bc.GetHeaderByHash(block.ParentHash())
12691276
// block.Time is guaranteed to be larger than parent.Time,

core/vm/gas_table.go

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,10 @@ func gasSStore(evm *EVM, contract *Contract, stack *Stack, mem *Memory, memorySi
100100
y, x = stack.Back(1), stack.Back(0)
101101
current = evm.StateDB.GetState(contract.Address(), x.Bytes32())
102102
)
103+
104+
// Try updating the witness of SSTORE at first to align with reth's witness implementation.
105+
original := evm.StateDB.GetCommittedState(contract.Address(), x.Bytes32())
106+
103107
// The legacy gas metering only takes into consideration the current state
104108
// Legacy rules should be applied if we are in Petersburg (removal of EIP-1283)
105109
// OR Constantinople is not active
@@ -137,7 +141,6 @@ func gasSStore(evm *EVM, contract *Contract, stack *Stack, mem *Memory, memorySi
137141
if current == value { // noop (1)
138142
return params.NetSstoreNoopGas, nil
139143
}
140-
original := evm.StateDB.GetCommittedState(contract.Address(), x.Bytes32())
141144
if original == current {
142145
if original == (common.Hash{}) { // create slot (2.1.1)
143146
return params.NetSstoreInitGas, nil
@@ -178,21 +181,24 @@ func gasSStore(evm *EVM, contract *Contract, stack *Stack, mem *Memory, memorySi
178181
// 2.2.2.1. If original value is 0, add SSTORE_SET_GAS - SLOAD_GAS to refund counter.
179182
// 2.2.2.2. Otherwise, add SSTORE_RESET_GAS - SLOAD_GAS gas to refund counter.
180183
func gasSStoreEIP2200(evm *EVM, contract *Contract, stack *Stack, mem *Memory, memorySize uint64) (uint64, error) {
181-
// If we fail the minimum gas availability invariant, fail (0)
182-
if contract.Gas <= params.SstoreSentryGasEIP2200 {
183-
return 0, errors.New("not enough gas for reentrancy sentry")
184-
}
185184
// Gas sentry honoured, do the actual gas calculation based on the stored value
186185
var (
187186
y, x = stack.Back(1), stack.Back(0)
188187
current = evm.StateDB.GetState(contract.Address(), x.Bytes32())
189188
)
190189
value := common.Hash(y.Bytes32())
191190

191+
// Try updating the witness of SSTORE at first to align with reth's witness implementation.
192+
original := evm.StateDB.GetCommittedState(contract.Address(), x.Bytes32())
193+
194+
// If we fail the minimum gas availability invariant, fail (0)
195+
if contract.Gas <= params.SstoreSentryGasEIP2200 {
196+
return 0, errors.New("not enough gas for reentrancy sentry")
197+
}
198+
192199
if current == value { // noop (1)
193200
return params.SloadGasEIP2200, nil
194201
}
195-
original := evm.StateDB.GetCommittedState(contract.Address(), x.Bytes32())
196202
if original == current {
197203
if original == (common.Hash{}) { // create slot (2.1.1)
198204
return params.SstoreSetGasEIP2200, nil

core/vm/operations_acl.go

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,17 +27,22 @@ import (
2727

2828
func makeGasSStoreFunc(clearingRefund uint64) gasFunc {
2929
return func(evm *EVM, contract *Contract, stack *Stack, mem *Memory, memorySize uint64) (uint64, error) {
30-
// If we fail the minimum gas availability invariant, fail (0)
31-
if contract.Gas <= params.SstoreSentryGasEIP2200 {
32-
return 0, errors.New("not enough gas for reentrancy sentry")
33-
}
3430
// Gas sentry honoured, do the actual gas calculation based on the stored value
3531
var (
3632
y, x = stack.Back(1), stack.peek()
3733
slot = common.Hash(x.Bytes32())
3834
current = evm.StateDB.GetState(contract.Address(), slot)
3935
cost = uint64(0)
4036
)
37+
38+
// Try updating the witness of SSTORE at first to align with reth's witness implementation.
39+
original := evm.StateDB.GetCommittedState(contract.Address(), x.Bytes32())
40+
41+
// If we fail the minimum gas availability invariant, fail (0)
42+
if contract.Gas <= params.SstoreSentryGasEIP2200 {
43+
return 0, errors.New("not enough gas for reentrancy sentry")
44+
}
45+
4146
// Check slot presence in the access list
4247
if addrPresent, slotPresent := evm.StateDB.SlotInAccessList(contract.Address(), slot); !slotPresent {
4348
cost = params.ColdSloadCostEIP2929
@@ -57,7 +62,6 @@ func makeGasSStoreFunc(clearingRefund uint64) gasFunc {
5762
// return params.SloadGasEIP2200, nil
5863
return cost + params.WarmStorageReadCostEIP2929, nil // SLOAD_GAS
5964
}
60-
original := evm.StateDB.GetCommittedState(contract.Address(), x.Bytes32())
6165
if original == current {
6266
if original == (common.Hash{}) { // create slot (2.1.1)
6367
return cost + params.SstoreSetGasEIP2200, nil
@@ -109,6 +113,14 @@ func gasSLoadEIP2929(evm *EVM, contract *Contract, stack *Stack, mem *Memory, me
109113
// If the caller cannot afford the cost, this change will be rolled back
110114
// If he does afford it, we can skip checking the same thing later on, during execution
111115
evm.StateDB.AddSlotToAccessList(contract.Address(), slot)
116+
117+
// Try updating the witness of SLOAD to align with reth's witness implementation.
118+
// Another place that needs to change is when calculating the gas cost after Frontier and before EIP-2929.
119+
// Frontier gas cost simply uses params.SloadGasFrontier (i.e., 50 gas), so changing the gas cost there
120+
// might affect code cleanliness. Usually, this won't be a problem because EIP-2929 is enabled by default.
121+
// Thus, adding the SLOAD witness before EIP-2929 is left as a TODO here.
122+
evm.StateDB.GetCommittedState(contract.Address(), loc.Bytes32())
123+
112124
return params.ColdSloadCostEIP2929, nil
113125
}
114126
return params.WarmStorageReadCostEIP2929, nil

0 commit comments

Comments
 (0)