Skip to content
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

Precompile revert test #2655

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from
Draft
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
2 changes: 1 addition & 1 deletion contracts
17 changes: 17 additions & 0 deletions precompiles/ArbDebug.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -64,3 +65,19 @@ 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) {
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) {
err := c.State.Burner.Burn(5)
if err != nil {
return 0, err
}
return 0, vm.ErrExecutionReverted
}
2 changes: 1 addition & 1 deletion precompiles/precompile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ func TestPrecompilesPerArbosVersion(t *testing.T) {
log.SetDefault(log.NewLogger(glogger))

expectedNewMethodsPerArbosVersion := map[uint64]int{
0: 89,
0: 91,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should probably just ignore ArbDebug in this test since it's not on prod chains

5: 3,
10: 2,
11: 4,
Expand Down
51 changes: 51 additions & 0 deletions system_tests/precompile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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()
Expand Down
Loading