Skip to content

Call ProcessParentBlockHash during InternalTxStartBlock #3129

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

Merged
merged 7 commits into from
Apr 15, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions arbos/internal_tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"math/big"

"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/core/vm"
"github.com/ethereum/go-ethereum/log"
Expand Down Expand Up @@ -55,6 +56,15 @@ func ApplyInternalTxUpdate(tx *types.ArbitrumInternalTx, state *arbosState.Arbos
return err
}

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

if l1BlockNumber > oldL1BlockNumber {
var prevHash common.Hash
if evm.Context.BlockNumber.Sign() > 0 {
prevHash = evm.Context.GetHash(evm.Context.BlockNumber.Uint64() - 1)
}
state.Restrict(state.Blockhashes().RecordNewL1Block(l1BlockNumber-1, prevHash, state.ArbOSVersion()))
}

Expand Down
2 changes: 1 addition & 1 deletion go-ethereum
59 changes: 59 additions & 0 deletions system_tests/historical_block_hash_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package arbtest

import (
"bytes"
"context"
"encoding/binary"
"math/big"
"testing"

"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/params"

"github.com/offchainlabs/nitro/statetransfer"
)

func TestHistoricalBlockHash(t *testing.T) {
t.Parallel()
ctx, cancel := context.WithCancel(context.Background())
defer cancel()

builder := NewNodeBuilder(ctx).DefaultConfig(t, true)
contractInfo := &statetransfer.AccountInitContractInfo{
Code: params.HistoryStorageCodeArbitrum,
ContractStorage: make(map[common.Hash]common.Hash),
}
accountInfo := statetransfer.AccountInitializationInfo{
Addr: params.HistoryStorageAddress,
EthBalance: big.NewInt(0),
Nonce: 1,
ContractInfo: contractInfo,
}
builder.L2Info.ArbInitData.Accounts = append(builder.L2Info.ArbInitData.Accounts, accountInfo)
cleanup := builder.Build(t)
defer cleanup()

for {
builder.L2.TransferBalance(t, "Faucet", "Faucet", common.Big1, builder.L2Info)
number, err := builder.L2.Client.BlockNumber(ctx)
Require(t, err)
if number > 300 {
break
}
}

block, err := builder.L2.Client.BlockByNumber(ctx, nil)
Require(t, err)

for i := uint64(0); i < block.Number().Uint64(); i++ {
var key common.Hash
binary.BigEndian.PutUint64(key[24:], i)
expectedBlock, err := builder.L2.Client.BlockByNumber(ctx, new(big.Int).SetUint64(i))
Require(t, err)
blockHash := sendContractCall(t, ctx, params.HistoryStorageAddress, builder.L2.Client, key.Bytes())
if !bytes.Equal(blockHash, expectedBlock.Hash().Bytes()) {
t.Fatalf("Expected block hash %s, got %s", expectedBlock.Hash(), blockHash)
}
}

}
Loading