Skip to content

Commit 1f73305

Browse files
authored
Merge pull request #3129 from OffchainLabs/eip_2935_fix
Call ProcessParentBlockHash during InternalTxStartBlock
2 parents beb3b9a + a1c5699 commit 1f73305

File tree

3 files changed

+70
-5
lines changed

3 files changed

+70
-5
lines changed

arbos/internal_tx.go

+10-4
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"math/big"
1010

1111
"github.com/ethereum/go-ethereum/common"
12+
"github.com/ethereum/go-ethereum/core"
1213
"github.com/ethereum/go-ethereum/core/types"
1314
"github.com/ethereum/go-ethereum/core/vm"
1415
"github.com/ethereum/go-ethereum/log"
@@ -55,6 +56,15 @@ func ApplyInternalTxUpdate(tx *types.ArbitrumInternalTx, state *arbosState.Arbos
5556
return err
5657
}
5758

59+
var prevHash common.Hash
60+
if evm.Context.BlockNumber.Sign() > 0 {
61+
prevHash = evm.Context.GetHash(evm.Context.BlockNumber.Uint64() - 1)
62+
}
63+
// For ArbOS versions >= 40 we need to call ProcessParentBlockHash to fill
64+
// the historyStorage with the block hash to support EIP-2935.
65+
if state.ArbOSVersion() >= params.ArbosVersion_40 {
66+
core.ProcessParentBlockHash(prevHash, evm)
67+
}
5868
l1BlockNumber := util.SafeMapGet[uint64](inputs, "l1BlockNumber")
5969
timePassed := util.SafeMapGet[uint64](inputs, "timePassed")
6070
if state.ArbOSVersion() < params.ArbosVersion_3 {
@@ -73,10 +83,6 @@ func ApplyInternalTxUpdate(tx *types.ArbitrumInternalTx, state *arbosState.Arbos
7383
state.Restrict(err)
7484

7585
if l1BlockNumber > oldL1BlockNumber {
76-
var prevHash common.Hash
77-
if evm.Context.BlockNumber.Sign() > 0 {
78-
prevHash = evm.Context.GetHash(evm.Context.BlockNumber.Uint64() - 1)
79-
}
8086
state.Restrict(state.Blockhashes().RecordNewL1Block(l1BlockNumber-1, prevHash, state.ArbOSVersion()))
8187
}
8288

+59
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
package arbtest
2+
3+
import (
4+
"bytes"
5+
"context"
6+
"encoding/binary"
7+
"math/big"
8+
"testing"
9+
10+
"github.com/ethereum/go-ethereum/common"
11+
"github.com/ethereum/go-ethereum/params"
12+
13+
"github.com/offchainlabs/nitro/statetransfer"
14+
)
15+
16+
func TestHistoricalBlockHash(t *testing.T) {
17+
t.Parallel()
18+
ctx, cancel := context.WithCancel(context.Background())
19+
defer cancel()
20+
21+
builder := NewNodeBuilder(ctx).DefaultConfig(t, true)
22+
contractInfo := &statetransfer.AccountInitContractInfo{
23+
Code: params.HistoryStorageCodeArbitrum,
24+
ContractStorage: make(map[common.Hash]common.Hash),
25+
}
26+
accountInfo := statetransfer.AccountInitializationInfo{
27+
Addr: params.HistoryStorageAddress,
28+
EthBalance: big.NewInt(0),
29+
Nonce: 1,
30+
ContractInfo: contractInfo,
31+
}
32+
builder.L2Info.ArbInitData.Accounts = append(builder.L2Info.ArbInitData.Accounts, accountInfo)
33+
cleanup := builder.Build(t)
34+
defer cleanup()
35+
36+
for {
37+
builder.L2.TransferBalance(t, "Faucet", "Faucet", common.Big1, builder.L2Info)
38+
number, err := builder.L2.Client.BlockNumber(ctx)
39+
Require(t, err)
40+
if number > 300 {
41+
break
42+
}
43+
}
44+
45+
block, err := builder.L2.Client.BlockByNumber(ctx, nil)
46+
Require(t, err)
47+
48+
for i := uint64(0); i < block.Number().Uint64(); i++ {
49+
var key common.Hash
50+
binary.BigEndian.PutUint64(key[24:], i)
51+
expectedBlock, err := builder.L2.Client.BlockByNumber(ctx, new(big.Int).SetUint64(i))
52+
Require(t, err)
53+
blockHash := sendContractCall(t, ctx, params.HistoryStorageAddress, builder.L2.Client, key.Bytes())
54+
if !bytes.Equal(blockHash, expectedBlock.Hash().Bytes()) {
55+
t.Fatalf("Expected block hash %s, got %s", expectedBlock.Hash(), blockHash)
56+
}
57+
}
58+
59+
}

0 commit comments

Comments
 (0)