From ddd35d0112eb2e0e5d8d1b4cef2252f691907f8b Mon Sep 17 00:00:00 2001 From: Nodar Ambroladze Date: Tue, 30 Apr 2024 12:12:04 +0200 Subject: [PATCH 1/8] Add test to check p256Verify is enabled from arbOS 30 --- arbos/arbosState/arbosstate.go | 4 ++-- system_tests/outbox_test.go | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+), 2 deletions(-) diff --git a/arbos/arbosState/arbosstate.go b/arbos/arbosState/arbosstate.go index f7b7f0e7f6..7a6941f0ac 100644 --- a/arbos/arbosState/arbosstate.go +++ b/arbos/arbosState/arbosstate.go @@ -163,7 +163,7 @@ var ( ) // Returns a list of precompiles that only appear in Arbitrum chains (i.e. ArbOS precompiles) at the genesis block -func getArbitrumOnlyGenesisPrecompiles(chainConfig *params.ChainConfig) []common.Address { +func GetArbitrumOnlyGenesisPrecompiles(chainConfig *params.ChainConfig) []common.Address { rules := chainConfig.Rules(big.NewInt(0), false, 0, chainConfig.ArbitrumChainParams.InitialArbOSVersion) arbPrecompiles := vm.ActivePrecompiles(rules) rules.IsArbitrum = false @@ -204,7 +204,7 @@ func InitializeArbosState(stateDB vm.StateDB, burner burn.Burner, chainConfig *p // Solidity requires call targets have code, but precompiles don't. // To work around this, we give precompiles fake code. - for _, genesisPrecompile := range getArbitrumOnlyGenesisPrecompiles(chainConfig) { + for _, genesisPrecompile := range GetArbitrumOnlyGenesisPrecompiles(chainConfig) { stateDB.SetCode(genesisPrecompile, []byte{byte(vm.INVALID)}) } diff --git a/system_tests/outbox_test.go b/system_tests/outbox_test.go index d0ca0ccda3..e80c837b58 100644 --- a/system_tests/outbox_test.go +++ b/system_tests/outbox_test.go @@ -16,6 +16,8 @@ import ( "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/crypto" + "github.com/ethereum/go-ethereum/params" + "github.com/offchainlabs/nitro/arbos/arbosState" "github.com/offchainlabs/nitro/gethhook" "github.com/offchainlabs/nitro/solgen/go/node_interfacegen" "github.com/offchainlabs/nitro/solgen/go/precompilesgen" @@ -23,6 +25,37 @@ import ( "github.com/offchainlabs/nitro/util/merkletree" ) +func TestP256VerifyEnabled(t *testing.T) { + gethhook.RequireHookedGeth() + for _, tc := range []struct { + arbOSVersion uint64 + wantP256Verify bool + }{ + { + arbOSVersion: 20, + wantP256Verify: false, + }, + { + arbOSVersion: 30, + wantP256Verify: true, + }, + } { + addresses := arbosState.GetArbitrumOnlyGenesisPrecompiles(¶ms.ChainConfig{ + ArbitrumChainParams: params.ArbitrumChainParams{ + EnableArbOS: true, + InitialArbOSVersion: tc.arbOSVersion, + }, + }) + got := false + for _, a := range addresses { + got = got || (a == common.BytesToAddress([]byte{0x01, 0x00})) + } + if got != tc.wantP256Verify { + t.Errorf("Got P256Verify enabled: %t, want: %t", got, tc.wantP256Verify) + } + } +} + func TestOutboxProofs(t *testing.T) { t.Parallel() gethhook.RequireHookedGeth() From 086c74a5671d7f3b363927122fd9028a0a14cbbc Mon Sep 17 00:00:00 2001 From: Nodar Ambroladze Date: Fri, 3 May 2024 15:54:37 +0200 Subject: [PATCH 2/8] Merge master --- system_tests/outbox_test.go | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/system_tests/outbox_test.go b/system_tests/outbox_test.go index e80c837b58..739d756a31 100644 --- a/system_tests/outbox_test.go +++ b/system_tests/outbox_test.go @@ -15,9 +15,9 @@ import ( "github.com/ethereum/go-ethereum/accounts/abi/bind" "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/core/types" + "github.com/ethereum/go-ethereum/core/vm" "github.com/ethereum/go-ethereum/crypto" "github.com/ethereum/go-ethereum/params" - "github.com/offchainlabs/nitro/arbos/arbosState" "github.com/offchainlabs/nitro/gethhook" "github.com/offchainlabs/nitro/solgen/go/node_interfacegen" "github.com/offchainlabs/nitro/solgen/go/precompilesgen" @@ -28,26 +28,20 @@ import ( func TestP256VerifyEnabled(t *testing.T) { gethhook.RequireHookedGeth() for _, tc := range []struct { - arbOSVersion uint64 + stylusEnabled bool wantP256Verify bool }{ { - arbOSVersion: 20, + stylusEnabled: false, wantP256Verify: false, }, { - arbOSVersion: 30, + stylusEnabled: true, wantP256Verify: true, }, } { - addresses := arbosState.GetArbitrumOnlyGenesisPrecompiles(¶ms.ChainConfig{ - ArbitrumChainParams: params.ArbitrumChainParams{ - EnableArbOS: true, - InitialArbOSVersion: tc.arbOSVersion, - }, - }) got := false - for _, a := range addresses { + for _, a := range vm.ActivePrecompiles(params.Rules{IsStylus: tc.stylusEnabled}) { got = got || (a == common.BytesToAddress([]byte{0x01, 0x00})) } if got != tc.wantP256Verify { From ad7776873ba5dcd340a4fcaa2dcbfadf7323c939 Mon Sep 17 00:00:00 2001 From: Nodar Ambroladze Date: Fri, 3 May 2024 16:15:33 +0200 Subject: [PATCH 3/8] Add e2e test --- system_tests/transfer_test.go | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/system_tests/transfer_test.go b/system_tests/transfer_test.go index a270cca76b..be091ba5ab 100644 --- a/system_tests/transfer_test.go +++ b/system_tests/transfer_test.go @@ -4,10 +4,14 @@ package arbtest import ( + "bytes" "context" "fmt" "math/big" "testing" + + "github.com/ethereum/go-ethereum" + "github.com/ethereum/go-ethereum/common" ) func TestTransfer(t *testing.T) { @@ -36,3 +40,27 @@ func TestTransfer(t *testing.T) { Fatal(t, "Unexpected recipient balance: ", bal2) } } + +func TestP256Verify(t *testing.T) { + ctx, cancel := context.WithCancel(context.Background()) + defer cancel() + builder := NewNodeBuilder(ctx).DefaultConfig(t, false) + builder.chainConfig.ArbitrumChainParams.InitialArbOSVersion = 30 + cleanup := builder.Build(t) + defer cleanup() + addr := common.BytesToAddress([]byte{0x01, 0x00}) + got, err := builder.L2.Client.CallContract(ctx, ethereum.CallMsg{ + From: builder.L2Info.GetAddress("Owner"), + To: &addr, + Gas: builder.L2Info.TransferGas, + Data: common.Hex2Bytes("4cee90eb86eaa050036147a12d49004b6b9c72bd725d39d4785011fe190f0b4da73bd4903f0ce3b639bbbf6e8e80d16931ff4bcf5993d58468e8fb19086e8cac36dbcd03009df8c59286b162af3bd7fcc0450c9aa81be5d10d312af6c66b1d604aebd3099c618202fcfe16ae7770b0c49ab5eadf74b754204a3bb6060e44eff37618b065f9832de4ca6ca971a7a1adc826d0f7c00181a5fb2ddf79ae00b4e10e"), + Value: big.NewInt(1e12), + }, nil) + if err != nil { + t.Fatalf("Calling p256 precompile, unexpected error: %v", err) + } + want := common.Hex2Bytes("0000000000000000000000000000000000000000000000000000000000000001") + if !bytes.Equal(got, want) { + t.Errorf("P256Verify() = %v, want: %v", got, want) + } +} From db9c77adfb2b211899f5039907be6a2bfb6634ab Mon Sep 17 00:00:00 2001 From: Pepper Lebeck-Jobe Date: Mon, 6 May 2024 10:54:17 +0200 Subject: [PATCH 4/8] Enable system tests to work from VS Code Debugger. Before this change, when launching some of the system tests from the VS Code debugger UI, the machine loader was unable to locate the jit binary because the system tests don't actually have "test" in path leading up to the test executable. --- validator/server_jit/machine_loader.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/validator/server_jit/machine_loader.go b/validator/server_jit/machine_loader.go index 3a831928b7..b2bdb65322 100644 --- a/validator/server_jit/machine_loader.go +++ b/validator/server_jit/machine_loader.go @@ -27,13 +27,16 @@ var DefaultJitMachineConfig = JitMachineConfig{ func getJitPath() (string, error) { var jitBinary string executable, err := os.Executable() + println("executable: ", executable) if err == nil { - if strings.Contains(filepath.Base(executable), "test") { + if strings.Contains(filepath.Base(executable), "test") || strings.Contains(filepath.Dir(executable), "system_tests") { _, thisfile, _, _ := runtime.Caller(0) projectDir := filepath.Dir(filepath.Dir(filepath.Dir(thisfile))) + println("projectDir: ", projectDir) jitBinary = filepath.Join(projectDir, "target", "bin", "jit") } else { jitBinary = filepath.Join(filepath.Dir(executable), "jit") + println("inside else: ", jitBinary) } _, err = os.Stat(jitBinary) } From ae26127b489ec75235aac8f18593be92945606a7 Mon Sep 17 00:00:00 2001 From: Nodar Ambroladze Date: Mon, 6 May 2024 14:15:02 +0200 Subject: [PATCH 5/8] Add test-case for arbOS 20 --- system_tests/transfer_test.go | 54 +++++++++++++++++++++++------------ 1 file changed, 36 insertions(+), 18 deletions(-) diff --git a/system_tests/transfer_test.go b/system_tests/transfer_test.go index be091ba5ab..a49e059351 100644 --- a/system_tests/transfer_test.go +++ b/system_tests/transfer_test.go @@ -44,23 +44,41 @@ func TestTransfer(t *testing.T) { func TestP256Verify(t *testing.T) { ctx, cancel := context.WithCancel(context.Background()) defer cancel() - builder := NewNodeBuilder(ctx).DefaultConfig(t, false) - builder.chainConfig.ArbitrumChainParams.InitialArbOSVersion = 30 - cleanup := builder.Build(t) - defer cleanup() - addr := common.BytesToAddress([]byte{0x01, 0x00}) - got, err := builder.L2.Client.CallContract(ctx, ethereum.CallMsg{ - From: builder.L2Info.GetAddress("Owner"), - To: &addr, - Gas: builder.L2Info.TransferGas, - Data: common.Hex2Bytes("4cee90eb86eaa050036147a12d49004b6b9c72bd725d39d4785011fe190f0b4da73bd4903f0ce3b639bbbf6e8e80d16931ff4bcf5993d58468e8fb19086e8cac36dbcd03009df8c59286b162af3bd7fcc0450c9aa81be5d10d312af6c66b1d604aebd3099c618202fcfe16ae7770b0c49ab5eadf74b754204a3bb6060e44eff37618b065f9832de4ca6ca971a7a1adc826d0f7c00181a5fb2ddf79ae00b4e10e"), - Value: big.NewInt(1e12), - }, nil) - if err != nil { - t.Fatalf("Calling p256 precompile, unexpected error: %v", err) - } - want := common.Hex2Bytes("0000000000000000000000000000000000000000000000000000000000000001") - if !bytes.Equal(got, want) { - t.Errorf("P256Verify() = %v, want: %v", got, want) + for _, tc := range []struct { + desc string + initialVersion uint64 + want []byte + }{ + { + desc: "p256 should not be enabled on arbOS 20", + initialVersion: 20, + want: nil, + }, + { + desc: "p256 should be enabled on arbOS 20", + initialVersion: 30, + want: common.Hex2Bytes("0000000000000000000000000000000000000000000000000000000000000001"), + }, + } { + t.Run(tc.desc, func(t *testing.T) { + builder := NewNodeBuilder(ctx).DefaultConfig(t, false) + builder.chainConfig.ArbitrumChainParams.InitialArbOSVersion = tc.initialVersion + cleanup := builder.Build(t) + defer cleanup() + addr := common.BytesToAddress([]byte{0x01, 0x00}) + got, err := builder.L2.Client.CallContract(ctx, ethereum.CallMsg{ + From: builder.L2Info.GetAddress("Owner"), + To: &addr, + Gas: builder.L2Info.TransferGas, + Data: common.Hex2Bytes("4cee90eb86eaa050036147a12d49004b6b9c72bd725d39d4785011fe190f0b4da73bd4903f0ce3b639bbbf6e8e80d16931ff4bcf5993d58468e8fb19086e8cac36dbcd03009df8c59286b162af3bd7fcc0450c9aa81be5d10d312af6c66b1d604aebd3099c618202fcfe16ae7770b0c49ab5eadf74b754204a3bb6060e44eff37618b065f9832de4ca6ca971a7a1adc826d0f7c00181a5fb2ddf79ae00b4e10e"), + Value: big.NewInt(1e12), + }, nil) + if err != nil { + t.Fatalf("CallContract() unexpected error: %v", err) + } + if !bytes.Equal(got, tc.want) { + t.Errorf("P256Verify() = %v, want: %v", got, tc.want) + } + }) } } From 794c199ad251f1913e0f052159388083005c3fc2 Mon Sep 17 00:00:00 2001 From: Tristan Wilson Date: Tue, 7 May 2024 11:19:13 -0700 Subject: [PATCH 6/8] Add extra DataPoster log first time batch is sent --- arbnode/dataposter/data_poster.go | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/arbnode/dataposter/data_poster.go b/arbnode/dataposter/data_poster.go index 614711249b..6de8013e79 100644 --- a/arbnode/dataposter/data_poster.go +++ b/arbnode/dataposter/data_poster.go @@ -844,14 +844,15 @@ func (p *DataPoster) sendTx(ctx context.Context, prevTx *storage.QueuedTransacti if err != nil { return fmt.Errorf("couldn't get preceding tx in DataPoster to check if should send tx with nonce %d: %w", newTx.FullTx.Nonce(), err) } + var latestBlockNumber, prevBlockNumber, reorgResistantNonce uint64 if precedingTx != nil && // precedingTx == nil -> the actual preceding tx was already confirmed (precedingTx.FullTx.Type() != newTx.FullTx.Type() || !precedingTx.Sent) { - latestBlockNumber, err := p.client.BlockNumber(ctx) + latestBlockNumber, err = p.client.BlockNumber(ctx) if err != nil { return fmt.Errorf("couldn't get block number in DataPoster to check if should send tx with nonce %d: %w", newTx.FullTx.Nonce(), err) } - prevBlockNumber := arbmath.SaturatingUSub(latestBlockNumber, 1) - reorgResistantNonce, err := p.client.NonceAt(ctx, p.Sender(), new(big.Int).SetUint64(prevBlockNumber)) + prevBlockNumber = arbmath.SaturatingUSub(latestBlockNumber, 1) + reorgResistantNonce, err = p.client.NonceAt(ctx, p.Sender(), new(big.Int).SetUint64(prevBlockNumber)) if err != nil { return fmt.Errorf("couldn't determine reorg resistant nonce in DataPoster to check if should send tx with nonce %d: %w", newTx.FullTx.Nonce(), err) } @@ -860,6 +861,8 @@ func (p *DataPoster) sendTx(ctx context.Context, prevTx *storage.QueuedTransacti log.Info("DataPoster is avoiding creating a mempool nonce gap (the tx remains queued and will be retried)", "nonce", newTx.FullTx.Nonce(), "prevType", precedingTx.FullTx.Type(), "type", newTx.FullTx.Type(), "prevSent", precedingTx.Sent) return nil } + } else { + log.Info("DataPoster will send previously unsent batch tx", "nonce", newTx.FullTx.Nonce(), "prevType", precedingTx.FullTx.Type(), "type", newTx.FullTx.Type(), "prevSent", precedingTx.Sent, "latestBlockNumber", latestBlockNumber, "prevBlockNumber", prevBlockNumber, "reorgResistantNonce", reorgResistantNonce) } } From 3b05dcb9cb392805c6c8e524d52c97ff88afd89b Mon Sep 17 00:00:00 2001 From: Ganesh Vanahalli Date: Thu, 9 May 2024 14:47:23 -0500 Subject: [PATCH 7/8] Merge v1.13.12 --- go-ethereum | 2 +- go.mod | 2 +- go.sum | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/go-ethereum b/go-ethereum index da519ddc4f..9874ec397a 160000 --- a/go-ethereum +++ b/go-ethereum @@ -1 +1 @@ -Subproject commit da519ddc4fd5113a46da734e41b37369a1dce098 +Subproject commit 9874ec397a5b499eefc98f7f9ae9632c3fc1e17f diff --git a/go.mod b/go.mod index 22b6b8b4af..6b350a4008 100644 --- a/go.mod +++ b/go.mod @@ -92,7 +92,7 @@ require ( github.com/dop251/goja v0.0.0-20230806174421-c933cf95e127 // indirect github.com/dustin/go-humanize v1.0.0 // indirect github.com/ethereum/c-kzg-4844 v0.4.0 // indirect - github.com/fjl/memsize v0.0.0-20190710130421-bcb5799ab5e5 // indirect + github.com/fjl/memsize v0.0.2 // indirect github.com/fsnotify/fsnotify v1.6.0 // indirect github.com/gammazero/deque v0.2.1 // indirect github.com/gballet/go-libpcsclite v0.0.0-20190607065134-2772fd86a8ff // indirect diff --git a/go.sum b/go.sum index 9d685c0abc..1b63dfb496 100644 --- a/go.sum +++ b/go.sum @@ -233,8 +233,8 @@ github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5Kwzbycv github.com/fatih/structs v1.1.0/go.mod h1:9NiDSp5zOcgEDl+j00MP/WkGVPOlPRLejGD8Ga6PJ7M= github.com/fatih/structtag v1.2.0 h1:/OdNE99OxoI/PqaW/SuSK9uxxT3f/tcSZgon/ssNSx4= github.com/fatih/structtag v1.2.0/go.mod h1:mBJUNpUnHmRKrKlQQlmCrh5PuhftFbNv8Ys4/aAZl94= -github.com/fjl/memsize v0.0.0-20190710130421-bcb5799ab5e5 h1:FtmdgXiUlNeRsoNMFlKLDt+S+6hbjVMEW6RGQ7aUf7c= -github.com/fjl/memsize v0.0.0-20190710130421-bcb5799ab5e5/go.mod h1:VvhXpOYNQvB+uIk2RvXzuaQtkQJzzIx6lSBe1xv7hi0= +github.com/fjl/memsize v0.0.2 h1:27txuSD9or+NZlnOWdKUxeBzTAUkWCVh+4Gf2dWFOzA= +github.com/fjl/memsize v0.0.2/go.mod h1:VvhXpOYNQvB+uIk2RvXzuaQtkQJzzIx6lSBe1xv7hi0= github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ= github.com/fsnotify/fsnotify v1.6.0 h1:n+5WquG0fcWoWp6xPWfHdbskMCQaFnG6PfBrh1Ky4HY= From debfb75f382f5af42f90e0ee8e0a28398f2f396c Mon Sep 17 00:00:00 2001 From: Tristan Wilson Date: Thu, 9 May 2024 17:14:34 -0700 Subject: [PATCH 8/8] Fix logging npe --- arbnode/dataposter/data_poster.go | 35 ++++++++++++++++--------------- 1 file changed, 18 insertions(+), 17 deletions(-) diff --git a/arbnode/dataposter/data_poster.go b/arbnode/dataposter/data_poster.go index 6de8013e79..b34552a9b9 100644 --- a/arbnode/dataposter/data_poster.go +++ b/arbnode/dataposter/data_poster.go @@ -844,25 +844,26 @@ func (p *DataPoster) sendTx(ctx context.Context, prevTx *storage.QueuedTransacti if err != nil { return fmt.Errorf("couldn't get preceding tx in DataPoster to check if should send tx with nonce %d: %w", newTx.FullTx.Nonce(), err) } - var latestBlockNumber, prevBlockNumber, reorgResistantNonce uint64 - if precedingTx != nil && // precedingTx == nil -> the actual preceding tx was already confirmed - (precedingTx.FullTx.Type() != newTx.FullTx.Type() || !precedingTx.Sent) { - latestBlockNumber, err = p.client.BlockNumber(ctx) - if err != nil { - return fmt.Errorf("couldn't get block number in DataPoster to check if should send tx with nonce %d: %w", newTx.FullTx.Nonce(), err) - } - prevBlockNumber = arbmath.SaturatingUSub(latestBlockNumber, 1) - reorgResistantNonce, err = p.client.NonceAt(ctx, p.Sender(), new(big.Int).SetUint64(prevBlockNumber)) - if err != nil { - return fmt.Errorf("couldn't determine reorg resistant nonce in DataPoster to check if should send tx with nonce %d: %w", newTx.FullTx.Nonce(), err) - } + if precedingTx != nil { // precedingTx == nil -> the actual preceding tx was already confirmed + var latestBlockNumber, prevBlockNumber, reorgResistantNonce uint64 + if precedingTx.FullTx.Type() != newTx.FullTx.Type() || !precedingTx.Sent { + latestBlockNumber, err = p.client.BlockNumber(ctx) + if err != nil { + return fmt.Errorf("couldn't get block number in DataPoster to check if should send tx with nonce %d: %w", newTx.FullTx.Nonce(), err) + } + prevBlockNumber = arbmath.SaturatingUSub(latestBlockNumber, 1) + reorgResistantNonce, err = p.client.NonceAt(ctx, p.Sender(), new(big.Int).SetUint64(prevBlockNumber)) + if err != nil { + return fmt.Errorf("couldn't determine reorg resistant nonce in DataPoster to check if should send tx with nonce %d: %w", newTx.FullTx.Nonce(), err) + } - if precedingTx.FullTx.Nonce() > reorgResistantNonce { - log.Info("DataPoster is avoiding creating a mempool nonce gap (the tx remains queued and will be retried)", "nonce", newTx.FullTx.Nonce(), "prevType", precedingTx.FullTx.Type(), "type", newTx.FullTx.Type(), "prevSent", precedingTx.Sent) - return nil + if precedingTx.FullTx.Nonce() > reorgResistantNonce { + log.Info("DataPoster is avoiding creating a mempool nonce gap (the tx remains queued and will be retried)", "nonce", newTx.FullTx.Nonce(), "prevType", precedingTx.FullTx.Type(), "type", newTx.FullTx.Type(), "prevSent", precedingTx.Sent) + return nil + } + } else { + log.Info("DataPoster will send previously unsent batch tx", "nonce", newTx.FullTx.Nonce(), "prevType", precedingTx.FullTx.Type(), "type", newTx.FullTx.Type(), "prevSent", precedingTx.Sent, "latestBlockNumber", latestBlockNumber, "prevBlockNumber", prevBlockNumber, "reorgResistantNonce", reorgResistantNonce) } - } else { - log.Info("DataPoster will send previously unsent batch tx", "nonce", newTx.FullTx.Nonce(), "prevType", precedingTx.FullTx.Type(), "type", newTx.FullTx.Type(), "prevSent", precedingTx.Sent, "latestBlockNumber", latestBlockNumber, "prevBlockNumber", prevBlockNumber, "reorgResistantNonce", reorgResistantNonce) } }