From ee19a8afb5bbfcf118917adab02a1179000db71d Mon Sep 17 00:00:00 2001 From: Tsahi Zidenberg Date: Mon, 9 Sep 2024 18:58:08 -0600 Subject: [PATCH 1/4] contracts: support arbdebug test --- contracts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contracts b/contracts index 23fc796282..2950fe3a1f 160000 --- a/contracts +++ b/contracts @@ -1 +1 @@ -Subproject commit 23fc79628292aa5d604d449fed48937ae7faeb2f +Subproject commit 2950fe3a1fac64850e69ade0ecf3a58350894e07 From da378dd3d4aeb912a1ab1b4e4ebbec8759ecc0a8 Mon Sep 17 00:00:00 2001 From: Tsahi Zidenberg Date: Mon, 9 Sep 2024 18:58:44 -0600 Subject: [PATCH 2/4] system_tests: test arbdebug revert --- precompiles/ArbDebug.go | 11 +++++++ system_tests/precompile_test.go | 51 +++++++++++++++++++++++++++++++++ 2 files changed, 62 insertions(+) diff --git a/precompiles/ArbDebug.go b/precompiles/ArbDebug.go index bf85d5e18f..f3573679ce 100644 --- a/precompiles/ArbDebug.go +++ b/precompiles/ArbDebug.go @@ -7,6 +7,7 @@ import ( "errors" "github.com/ethereum/go-ethereum/common" + "github.com/ethereum/go-ethereum/core/vm" ) // All calls to this precompile are authorized by the DebugPrecompile wrapper, @@ -64,3 +65,13 @@ func (con ArbDebug) Panic(c ctx, evm mech) error { func (con ArbDebug) LegacyError(c ctx) error { return errors.New("example legacy error") } + +func (con ArbDebug) RevertPackingOutput(c ctx, evm mech) (uint64, error) { + c.State.Burner.Burn(5) + return 0xffff, nil +} + +func (con ArbDebug) EmulateRevertPackingOutput(c ctx, evm mech) (uint8, error) { + c.State.Burner.Burn(5) + return 0, vm.ErrExecutionReverted +} diff --git a/system_tests/precompile_test.go b/system_tests/precompile_test.go index 9e829124ee..8221810a95 100644 --- a/system_tests/precompile_test.go +++ b/system_tests/precompile_test.go @@ -11,6 +11,7 @@ import ( "github.com/ethereum/go-ethereum/accounts/abi/bind" "github.com/ethereum/go-ethereum/common" + "github.com/ethereum/go-ethereum/core/vm" "github.com/ethereum/go-ethereum/params" "github.com/offchainlabs/nitro/arbos" "github.com/offchainlabs/nitro/solgen/go/mocksgen" @@ -125,6 +126,56 @@ func TestPrecompileErrorGasLeft(t *testing.T) { assertNotAllGasConsumed(common.HexToAddress("0xff"), arbDebug.Methods["legacyError"].ID) } +func TestPrecompileEmulatedRevert(t *testing.T) { + ctx, cancel := context.WithCancel(context.Background()) + defer cancel() + + builder := NewNodeBuilder(ctx).DefaultConfig(t, false) + cleanup := builder.Build(t) + defer cleanup() + + auth := builder.L2Info.GetDefaultTransactOpts("Faucet", ctx) + _, _, simple, err := mocksgen.DeploySimple(&auth, builder.L2.Client) + Require(t, err) + + arbDebug, err := precompilesgen.ArbDebugMetaData.GetAbi() + Require(t, err) + + gasEmulRevertPack, err := simple.CheckGasUsed(&bind.CallOpts{Context: ctx}, common.HexToAddress("0xff"), arbDebug.Methods["emulateRevertPackingOutput"].ID) + Require(t, err) + + gasRevertPack, err := simple.CheckGasUsed(&bind.CallOpts{Context: ctx}, common.HexToAddress("0xff"), arbDebug.Methods["revertPackingOutput"].ID) + Require(t, err) + + if gasRevertPack.Cmp(gasEmulRevertPack) != 0 { + Fatal(t, "gasRevert: ", gasRevertPack, " emulated: ", gasEmulRevertPack) + } + + _, _, multiCaller, err := mocksgen.DeployMultiCallTest(&auth, builder.L2.Client) + Require(t, err) + + checkDebugFuncReverts := func(methodName string) { + funcId := arbDebug.Methods[methodName].ID + args := argsForMulticall(vm.CALL, common.HexToAddress("0xff"), nil, funcId) + // emit event and allow revert + args[5] = args[5] | 0xC + tx, err := multiCaller.Fallback(&auth, args) + Require(t, err) + receipt, err := EnsureTxSucceeded(ctx, builder.L2.Client, tx) + Require(t, err) + if len(receipt.Logs) != 1 { + Fatal(t, methodName, " calling from multi got wrong num of logs") + } + calledEvt, err := multiCaller.ParseCalled(*receipt.Logs[0]) + Require(t, err) + if calledEvt.Success { + Fatal(t, methodName, "did not revert") + } + } + checkDebugFuncReverts("revertPackingOutput") + checkDebugFuncReverts("emulateRevertPackingOutput") +} + func TestScheduleArbosUpgrade(t *testing.T) { ctx, cancel := context.WithCancel(context.Background()) defer cancel() From 4060c3fa61256b85d2fbbf5caf976ca3c7fde459 Mon Sep 17 00:00:00 2001 From: Tsahi Zidenberg Date: Mon, 9 Sep 2024 19:23:12 -0600 Subject: [PATCH 3/4] arbdebug: lint --- precompiles/ArbDebug.go | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/precompiles/ArbDebug.go b/precompiles/ArbDebug.go index f3573679ce..e44cf7661e 100644 --- a/precompiles/ArbDebug.go +++ b/precompiles/ArbDebug.go @@ -67,11 +67,17 @@ func (con ArbDebug) LegacyError(c ctx) error { } func (con ArbDebug) RevertPackingOutput(c ctx, evm mech) (uint64, error) { - c.State.Burner.Burn(5) + err := c.State.Burner.Burn(5) + if err != nil { + return 0, err + } return 0xffff, nil } func (con ArbDebug) EmulateRevertPackingOutput(c ctx, evm mech) (uint8, error) { - c.State.Burner.Burn(5) + err := c.State.Burner.Burn(5) + if err != nil { + return 0, err + } return 0, vm.ErrExecutionReverted } From 0053bf7b7e99f792ee774be8a64e9de60c58d07b Mon Sep 17 00:00:00 2001 From: Tsahi Zidenberg Date: Mon, 9 Sep 2024 19:41:29 -0600 Subject: [PATCH 4/4] added 2 arbdebug contracts --- precompiles/precompile_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/precompiles/precompile_test.go b/precompiles/precompile_test.go index ecce77088a..204cce54d4 100644 --- a/precompiles/precompile_test.go +++ b/precompiles/precompile_test.go @@ -188,7 +188,7 @@ func TestPrecompilesPerArbosVersion(t *testing.T) { log.SetDefault(log.NewLogger(glogger)) expectedNewMethodsPerArbosVersion := map[uint64]int{ - 0: 89, + 0: 91, 5: 3, 10: 2, 11: 4,