diff --git a/.github/buildspec.yml b/.github/buildspec.yml new file mode 100644 index 0000000000..9b6503bb5d --- /dev/null +++ b/.github/buildspec.yml @@ -0,0 +1,36 @@ +version: 0.2 + +phases: + pre_build: + commands: + - git submodule update --init + - echo Logging in to Dockerhub.... + - docker login --username $DOCKERHUB_USERNAME --password $DOCKERHUB_PASSWORD + - aws ecr get-login-password --region us-west-2 | docker login --username AWS --password-stdin $REPOSITORY_URI + - COMMIT_HASH=$(git rev-parse --short=7 HEAD || echo "latest") + - VERSION_TAG=$(git tag --points-at HEAD | sed '/-/!s/$/_/' | sort -rV | sed 's/_$//' | head -n 1 | grep ^ || git show -s --pretty=%D | sed 's/, /\n/g' | grep -v '^origin/' |grep -v '^grafted\|HEAD\|master\|main$' || echo "dev") + - NITRO_VERSION=${VERSION_TAG}-${COMMIT_HASH} + - IMAGE_TAG=${NITRO_VERSION} + - NITRO_DATETIME=$(git show -s --date=iso-strict --format=%cd) + - NITRO_MODIFIED="false" + - echo ${NITRO_VERSION} > ./.nitro-tag.txt + build: + commands: + - echo Build started on `date` + - echo Building the Docker image ${NITRO_VERSION}... + - DOCKER_BUILDKIT=1 docker build . -t nitro-node-slim --target nitro-node-slim --build-arg version=$NITRO_VERSION --build-arg datetime=$NITRO_DATETIME --build-arg modified=$NITRO_MODIFIED + - DOCKER_BUILDKIT=1 docker build . -t nitro-node --target nitro-node --build-arg version=$NITRO_VERSION --build-arg datetime=$NITRO_DATETIME --build-arg modified=$NITRO_MODIFIED + - DOCKER_BUILDKIT=1 docker build . -t nitro-node-dev --target nitro-node-dev --build-arg version=$NITRO_VERSION --build-arg datetime=$NITRO_DATETIME --build-arg modified=$NITRO_MODIFIED + - DOCKER_BUILDKIT=1 docker build . -t nitro-node-validator --target nitro-node-validator --build-arg version=$NITRO_VERSION --build-arg datetime=$NITRO_DATETIME --build-arg modified=$NITRO_MODIFIED + - docker tag nitro-node:latest $REPOSITORY_URI:$IMAGE_TAG-$ARCH_TAG + - docker tag nitro-node-slim:latest $REPOSITORY_URI:$IMAGE_TAG-slim-$ARCH_TAG + - docker tag nitro-node-dev:latest $REPOSITORY_URI:$IMAGE_TAG-dev-$ARCH_TAG + - docker tag nitro-node-validator:latest $REPOSITORY_URI:$IMAGE_TAG-validator-$ARCH_TAG + post_build: + commands: + - echo Build completed on `date` + - echo pushing to repo + - docker push $REPOSITORY_URI:$IMAGE_TAG-$ARCH_TAG + - docker push $REPOSITORY_URI:$IMAGE_TAG-slim-$ARCH_TAG + - docker push $REPOSITORY_URI:$IMAGE_TAG-dev-$ARCH_TAG + - docker push $REPOSITORY_URI:$IMAGE_TAG-validator-$ARCH_TAG diff --git a/Makefile b/Makefile index 88bbd8dabe..12dfb07cf8 100644 --- a/Makefile +++ b/Makefile @@ -155,6 +155,8 @@ stylus_test_hostio-test_src = $(call get_stylus_test_rust,hostio-test) stylus_test_wasms = $(stylus_test_keccak_wasm) $(stylus_test_keccak-100_wasm) $(stylus_test_fallible_wasm) $(stylus_test_storage_wasm) $(stylus_test_multicall_wasm) $(stylus_test_log_wasm) $(stylus_test_create_wasm) $(stylus_test_math_wasm) $(stylus_test_sdk-storage_wasm) $(stylus_test_erc20_wasm) $(stylus_test_read-return-data_wasm) $(stylus_test_evm-data_wasm) $(stylus_test_hostio-test_wasm) $(stylus_test_bfs:.b=.wasm) stylus_benchmarks = $(wildcard $(stylus_dir)/*.toml $(stylus_dir)/src/*.rs) $(stylus_test_wasms) +CBROTLI_WASM_BUILD_ARGS ?=-d + # user targets .PHONY: push @@ -579,9 +581,9 @@ contracts/test/prover/proofs/%.json: $(arbitrator_cases)/%.wasm $(prover_bin) @touch $@ .make/cbrotli-wasm: $(DEP_PREDICATE) $(ORDER_ONLY_PREDICATE) .make - test -f target/lib-wasm/libbrotlicommon-static.a || ./scripts/build-brotli.sh -w -d - test -f target/lib-wasm/libbrotlienc-static.a || ./scripts/build-brotli.sh -w -d - test -f target/lib-wasm/libbrotlidec-static.a || ./scripts/build-brotli.sh -w -d + test -f target/lib-wasm/libbrotlicommon-static.a || ./scripts/build-brotli.sh -w $(CBROTLI_WASM_BUILD_ARGS) + test -f target/lib-wasm/libbrotlienc-static.a || ./scripts/build-brotli.sh -w $(CBROTLI_WASM_BUILD_ARGS) + test -f target/lib-wasm/libbrotlidec-static.a || ./scripts/build-brotli.sh -w $(CBROTLI_WASM_BUILD_ARGS) @touch $@ .make/wasm-lib: $(DEP_PREDICATE) arbitrator/wasm-libraries/soft-float/SoftFloat/build/Wasm-Clang/softfloat.a $(ORDER_ONLY_PREDICATE) .make diff --git a/arbnode/batch_poster.go b/arbnode/batch_poster.go index d534c39c5e..46a0160b71 100644 --- a/arbnode/batch_poster.go +++ b/arbnode/batch_poster.go @@ -171,6 +171,7 @@ type BatchPosterConfig struct { Dangerous BatchPosterDangerousConfig `koanf:"dangerous"` ReorgResistanceMargin time.Duration `koanf:"reorg-resistance-margin" reload:"hot"` CheckBatchCorrectness bool `koanf:"check-batch-correctness"` + MaxEmptyBatchDelay time.Duration `koanf:"max-empty-batch-delay"` gasRefunder common.Address l1BlockBound l1BlockBound @@ -224,6 +225,7 @@ func BatchPosterConfigAddOptions(prefix string, f *pflag.FlagSet) { f.Uint64(prefix+".gas-estimate-base-fee-multiple-bips", uint64(DefaultBatchPosterConfig.GasEstimateBaseFeeMultipleBips), "for gas estimation, use this multiple of the basefee (measured in basis points) as the max fee per gas") f.Duration(prefix+".reorg-resistance-margin", DefaultBatchPosterConfig.ReorgResistanceMargin, "do not post batch if its within this duration from layer 1 minimum bounds. Requires l1-block-bound option not be set to \"ignore\"") f.Bool(prefix+".check-batch-correctness", DefaultBatchPosterConfig.CheckBatchCorrectness, "setting this to true will run the batch against an inbox multiplexer and verifies that it produces the correct set of messages") + f.Duration(prefix+".max-empty-batch-delay", DefaultBatchPosterConfig.MaxEmptyBatchDelay, "maximum empty batch posting delay, batch poster will only be able to post an empty batch if this time period building a batch has passed") redislock.AddConfigOptions(prefix+".redis-lock", f) dataposter.DataPosterConfigAddOptions(prefix+".data-poster", f, dataposter.DefaultDataPosterConfig) genericconf.WalletConfigAddOptions(prefix+".parent-chain-wallet", f, DefaultBatchPosterConfig.ParentChainWallet.Pathname) @@ -255,6 +257,7 @@ var DefaultBatchPosterConfig = BatchPosterConfig{ GasEstimateBaseFeeMultipleBips: arbmath.OneInUBips * 3 / 2, ReorgResistanceMargin: 10 * time.Minute, CheckBatchCorrectness: true, + MaxEmptyBatchDelay: 3 * 24 * time.Hour, } var DefaultBatchPosterL1WalletConfig = genericconf.WalletConfig{ @@ -1303,7 +1306,9 @@ func (b *BatchPoster) maybePostSequencerBatch(ctx context.Context) (bool, error) b.building.muxBackend.delayedInbox = append(b.building.muxBackend.delayedInbox, msg) } } - if msg.Message.Header.Kind != arbostypes.L1MessageType_BatchPostingReport { + // #nosec G115 + timeSinceMsg := time.Since(time.Unix(int64(msg.Message.Header.Timestamp), 0)) + if (msg.Message.Header.Kind != arbostypes.L1MessageType_BatchPostingReport) || (timeSinceMsg >= config.MaxEmptyBatchDelay) { b.building.haveUsefulMessage = true if b.building.firstUsefulMsg == nil { b.building.firstUsefulMsg = msg diff --git a/das/dasRpcClient.go b/das/dasRpcClient.go index 241f2196b1..d6e2c389c9 100644 --- a/das/dasRpcClient.go +++ b/das/dasRpcClient.go @@ -101,6 +101,7 @@ func (c *DASRPCClient) Store(ctx context.Context, message []byte, timeout uint64 var startChunkedStoreResult StartChunkedStoreResult if err := c.clnt.CallContext(ctx, &startChunkedStoreResult, "das_startChunkedStore", hexutil.Uint64(timestamp), hexutil.Uint64(nChunks), hexutil.Uint64(c.chunkSize), hexutil.Uint64(totalSize), hexutil.Uint64(timeout), hexutil.Bytes(startReqSig)); err != nil { if strings.Contains(err.Error(), "the method das_startChunkedStore does not exist") { + log.Info("Legacy store is used by the DAS client", "url", c.url) return c.legacyStore(ctx, message, timeout) } return nil, err diff --git a/precompiles/ArbAddressTable_test.go b/precompiles/ArbAddressTable_test.go index b01a460636..62ce177480 100644 --- a/precompiles/ArbAddressTable_test.go +++ b/precompiles/ArbAddressTable_test.go @@ -47,6 +47,12 @@ func TestAddressTable1(t *testing.T) { addr := common.BytesToAddress(crypto.Keccak256([]byte{})[:20]) + exists, err := atab.AddressExists(context, evm, addr) + Require(t, err) + if exists { + t.Fatal("Address shouldn't exist") + } + // register addr slot, err := atab.Register(context, evm, addr) Require(t, err) @@ -61,6 +67,12 @@ func TestAddressTable1(t *testing.T) { t.Fatal() } + exists, err = atab.AddressExists(context, evm, addr) + Require(t, err) + if !exists { + t.Fatal("Address should exist") + } + // verify Lookup of addr returns 0 index, err := atab.Lookup(context, evm, addr) Require(t, err) diff --git a/precompiles/ArbAggregator_test.go b/precompiles/ArbAggregator_test.go index ce1cebde5d..879fc737e4 100644 --- a/precompiles/ArbAggregator_test.go +++ b/precompiles/ArbAggregator_test.go @@ -12,34 +12,6 @@ import ( "github.com/offchainlabs/nitro/arbos/l1pricing" ) -func TestArbAggregatorBatchPosters(t *testing.T) { - evm := newMockEVMForTesting() - context := testContext(common.Address{}, evm) - - addr := common.BytesToAddress(crypto.Keccak256([]byte{})[:20]) - - // initially should have one batch poster - bps, err := ArbAggregator{}.GetBatchPosters(context, evm) - Require(t, err) - if len(bps) != 1 { - Fail(t) - } - - // add addr as a batch poster - Require(t, ArbDebug{}.BecomeChainOwner(context, evm)) - Require(t, ArbAggregator{}.AddBatchPoster(context, evm, addr)) - - // there should now be two batch posters, and addr should be one of them - bps, err = ArbAggregator{}.GetBatchPosters(context, evm) - Require(t, err) - if len(bps) != 2 { - Fail(t) - } - if bps[0] != addr && bps[1] != addr { - Fail(t) - } -} - func TestFeeCollector(t *testing.T) { evm := newMockEVMForTesting() agg := ArbAggregator{} diff --git a/precompiles/ArbGasInfo_test.go b/precompiles/ArbGasInfo_test.go new file mode 100644 index 0000000000..260d7b3cef --- /dev/null +++ b/precompiles/ArbGasInfo_test.go @@ -0,0 +1,140 @@ +// Copyright 2021-2024, Offchain Labs, Inc. +// For license information, see https://github.com/nitro/blob/master/LICENSE + +package precompiles + +import ( + "math/big" + "testing" + + "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/arbos/burn" + "github.com/offchainlabs/nitro/arbos/storage" + "github.com/offchainlabs/nitro/arbos/util" + "github.com/offchainlabs/nitro/util/testhelpers" +) + +func setupArbGasInfo( + t *testing.T, +) ( + *vm.EVM, + *arbosState.ArbosState, + *Context, + *ArbGasInfo, +) { + evm := newMockEVMForTesting() + caller := common.BytesToAddress(crypto.Keccak256([]byte{})[:20]) + tracer := util.NewTracingInfo(evm, testhelpers.RandomAddress(), types.ArbosAddress, util.TracingDuringEVM) + state, err := arbosState.OpenArbosState(evm.StateDB, burn.NewSystemBurner(tracer, false)) + Require(t, err) + + arbGasInfo := &ArbGasInfo{} + callCtx := testContext(caller, evm) + + return evm, state, callCtx, arbGasInfo +} + +func TestGetGasBacklog(t *testing.T) { + t.Parallel() + + evm, state, callCtx, arbGasInfo := setupArbGasInfo(t) + + backlog := uint64(1000) + err := state.L2PricingState().SetGasBacklog(backlog) + Require(t, err) + retrievedBacklog, err := arbGasInfo.GetGasBacklog(callCtx, evm) + Require(t, err) + if retrievedBacklog != backlog { + t.Fatal("expected backlog to be", backlog, "but got", retrievedBacklog) + } +} + +func TestGetL1PricingUpdateTime(t *testing.T) { + t.Parallel() + + evm, state, callCtx, arbGasInfo := setupArbGasInfo(t) + + lastUpdateTime := uint64(1001) + err := state.L1PricingState().SetLastUpdateTime(lastUpdateTime) + Require(t, err) + retrievedLastUpdateTime, err := arbGasInfo.GetLastL1PricingUpdateTime(callCtx, evm) + Require(t, err) + if retrievedLastUpdateTime != lastUpdateTime { + t.Fatal("expected last update time to be", lastUpdateTime, "but got", retrievedLastUpdateTime) + } +} + +func TestGetL1PricingFundsDueForRewards(t *testing.T) { + t.Parallel() + + evm, state, callCtx, arbGasInfo := setupArbGasInfo(t) + + fundsDueForRewards := big.NewInt(1002) + err := state.L1PricingState().SetFundsDueForRewards(fundsDueForRewards) + Require(t, err) + retrievedFundsDueForRewards, err := arbGasInfo.GetL1PricingFundsDueForRewards(callCtx, evm) + Require(t, err) + if retrievedFundsDueForRewards.Cmp(fundsDueForRewards) != 0 { + t.Fatal("expected funds due for rewards to be", fundsDueForRewards, "but got", retrievedFundsDueForRewards) + } +} + +func TestGetL1PricingUnitsSinceUpdate(t *testing.T) { + t.Parallel() + + evm, state, callCtx, arbGasInfo := setupArbGasInfo(t) + + pricingUnitsSinceUpdate := uint64(1003) + err := state.L1PricingState().SetUnitsSinceUpdate(pricingUnitsSinceUpdate) + Require(t, err) + retrievedPricingUnitsSinceUpdate, err := arbGasInfo.GetL1PricingUnitsSinceUpdate(callCtx, evm) + Require(t, err) + if retrievedPricingUnitsSinceUpdate != pricingUnitsSinceUpdate { + t.Fatal("expected pricing units since update to be", pricingUnitsSinceUpdate, "but got", retrievedPricingUnitsSinceUpdate) + } +} + +func TestGetLastL1PricingSurplus(t *testing.T) { + t.Parallel() + + evm, state, callCtx, arbGasInfo := setupArbGasInfo(t) + + lastSurplus := big.NewInt(1004) + err := state.L1PricingState().SetLastSurplus(lastSurplus, params.ArbosVersion_Stylus) + Require(t, err) + retrievedLastSurplus, err := arbGasInfo.GetLastL1PricingSurplus(callCtx, evm) + Require(t, err) + if retrievedLastSurplus.Cmp(lastSurplus) != 0 { + t.Fatal("expected last surplus to be", lastSurplus, "but got", retrievedLastSurplus) + } +} + +func TestGetPricesInArbGas(t *testing.T) { + t.Parallel() + + evm := newMockEVMForTesting() + caller := common.BytesToAddress(crypto.Keccak256([]byte{})[:20]) + arbGasInfo := &ArbGasInfo{} + callCtx := testContext(caller, evm) + + evm.Context.BaseFee = big.NewInt(1005) + expectedGasPerL2Tx := big.NewInt(111442786069) + expectedGasForL1Calldata := big.NewInt(796019900) + expectedStorageArbGas := big.NewInt(int64(storage.StorageWriteCost)) + gasPerL2Tx, gasForL1Calldata, storageArbGas, err := arbGasInfo.GetPricesInArbGas(callCtx, evm) + Require(t, err) + if gasPerL2Tx.Cmp(expectedGasPerL2Tx) != 0 { + t.Fatal("expected gas per L2 tx to be", expectedGasPerL2Tx, "but got", gasPerL2Tx) + } + if gasForL1Calldata.Cmp(expectedGasForL1Calldata) != 0 { + t.Fatal("expected gas for L1 calldata to be", expectedGasForL1Calldata, "but got", gasForL1Calldata) + } + if storageArbGas.Cmp(expectedStorageArbGas) != 0 { + t.Fatal("expected storage arb gas to be", expectedStorageArbGas, "but got", storageArbGas) + } +} diff --git a/precompiles/ArbOwner_test.go b/precompiles/ArbOwner_test.go index 1f8c7ae4cd..1fc6e679cb 100644 --- a/precompiles/ArbOwner_test.go +++ b/precompiles/ArbOwner_test.go @@ -151,6 +151,23 @@ func TestArbOwner(t *testing.T) { if avail.Cmp(deposited) != 0 { Fail(t, avail, deposited) } + + err = prec.SetNetworkFeeAccount(callCtx, evm, addr1) + Require(t, err) + retrievedNetworkFeeAccount, err := prec.GetNetworkFeeAccount(callCtx, evm) + Require(t, err) + if retrievedNetworkFeeAccount.Cmp(addr1) != 0 { + Fail(t, "Expected", addr1, "got", retrievedNetworkFeeAccount) + } + + l2BaseFee := big.NewInt(123) + err = prec.SetL2BaseFee(callCtx, evm, l2BaseFee) + Require(t, err) + retrievedL2BaseFee, err := state.L2PricingState().BaseFeeWei() + Require(t, err) + if l2BaseFee.Cmp(retrievedL2BaseFee) != 0 { + Fail(t, "Expected", l2BaseFee, "got", retrievedL2BaseFee) + } } func TestArbOwnerSetChainConfig(t *testing.T) { diff --git a/precompiles/ArbRetryableTx.go b/precompiles/ArbRetryableTx.go index 93e8023603..d925499180 100644 --- a/precompiles/ArbRetryableTx.go +++ b/precompiles/ArbRetryableTx.go @@ -154,7 +154,6 @@ func (con ArbRetryableTx) GetTimeout(c ctx, evm mech, ticketId bytes32) (huge, e // Keepalive adds one lifetime period to the ticket's expiry func (con ArbRetryableTx) Keepalive(c ctx, evm mech, ticketId bytes32) (huge, error) { - // charge for the expiry update retryableState := c.State.RetryableState() nbytes, err := retryableState.RetryableSizeBytes(ticketId, evm.Context.Time) diff --git a/precompiles/ArbRetryableTx_test.go b/precompiles/ArbRetryableTx_test.go index 9ccb437abc..47450299ce 100644 --- a/precompiles/ArbRetryableTx_test.go +++ b/precompiles/ArbRetryableTx_test.go @@ -7,12 +7,37 @@ import ( "math/big" "testing" + "github.com/offchainlabs/nitro/arbos" "github.com/offchainlabs/nitro/arbos/storage" "github.com/ethereum/go-ethereum/common" + "github.com/ethereum/go-ethereum/core" + "github.com/ethereum/go-ethereum/core/vm" templates "github.com/offchainlabs/nitro/solgen/go/precompilesgen" ) +func newMockEVMForTestingWithCurrentRefundTo(currentRefundTo *common.Address) *vm.EVM { + evm := newMockEVMForTesting() + txProcessor := arbos.NewTxProcessor(evm, &core.Message{}) + txProcessor.CurrentRefundTo = currentRefundTo + evm.ProcessingHook = txProcessor + return evm +} + +func TestGetCurrentRedeemer(t *testing.T) { + currentRefundTo := common.HexToAddress("0x030405") + + evm := newMockEVMForTestingWithCurrentRefundTo(¤tRefundTo) + retryableTx := ArbRetryableTx{} + context := testContext(common.Address{}, evm) + + currentRedeemer, err := retryableTx.GetCurrentRedeemer(context, evm) + Require(t, err) + if currentRefundTo.Cmp(currentRedeemer) != 0 { + t.Fatal("Expected to be ", currentRefundTo, " but got ", currentRedeemer) + } +} + func TestRetryableRedeem(t *testing.T) { evm := newMockEVMForTesting() precompileCtx := testContext(common.Address{}, evm) diff --git a/precompiles/ArbSys.go b/precompiles/ArbSys.go index d55067a09c..689d3b18de 100644 --- a/precompiles/ArbSys.go +++ b/precompiles/ArbSys.go @@ -92,7 +92,6 @@ func (con *ArbSys) WasMyCallersAddressAliased(c ctx, evm mech) (bool, error) { // MyCallersAddressWithoutAliasing gets the caller's caller without any potential aliasing func (con *ArbSys) MyCallersAddressWithoutAliasing(c ctx, evm mech) (addr, error) { - address := addr{} if evm.Depth() > 1 { diff --git a/pubsub/producer.go b/pubsub/producer.go index dacaeba7d0..722c145a09 100644 --- a/pubsub/producer.go +++ b/pubsub/producer.go @@ -201,8 +201,9 @@ func (p *Producer[Request, Response]) clearMessages(ctx context.Context) time.Du } if _, err := p.client.XDel(ctx, p.redisStream, pelData.Lower).Result(); err != nil { log.Error("error deleting PEL's lower message thats past its TTL", "msgID", pelData.Lower, "err", err) - return 0 + return 5 * p.cfg.CheckResultInterval } + return 0 } } return 5 * p.cfg.CheckResultInterval diff --git a/system_tests/debugapi_test.go b/system_tests/debugapi_test.go index 30a2bee03e..eb2bcd095d 100644 --- a/system_tests/debugapi_test.go +++ b/system_tests/debugapi_test.go @@ -43,7 +43,7 @@ func TestDebugAPI(t *testing.T) { arbSys, err := precompilesgen.NewArbSys(types.ArbSysAddress, builder.L2.Client) Require(t, err) auth := builder.L2Info.GetDefaultTransactOpts("Owner", ctx) - tx, err := arbSys.WithdrawEth(&auth, common.Address{}) + tx, err := arbSys.SendTxToL1(&auth, common.Address{}, []byte{}) Require(t, err) receipt, err := builder.L2.EnsureTxSucceeded(tx) Require(t, err) diff --git a/system_tests/fees_test.go b/system_tests/fees_test.go index ccca82e009..76de23e2cb 100644 --- a/system_tests/fees_test.go +++ b/system_tests/fees_test.go @@ -55,6 +55,12 @@ func TestSequencerFeePaid(t *testing.T) { l1Estimate, err := arbGasInfo.GetL1BaseFeeEstimate(callOpts) Require(t, err) + l1EstimateThroughGetL1GasPriceEstimate, err := arbGasInfo.GetL1GasPriceEstimate(callOpts) + Require(t, err) + if !arbmath.BigEquals(l1Estimate, l1EstimateThroughGetL1GasPriceEstimate) { + Fatal(t, "GetL1BaseFeeEstimate and GetL1GasPriceEstimate should return the same value") + } + baseFee := builder.L2.GetBaseFee(t) builder.L2Info.GasPrice = baseFee diff --git a/system_tests/precompile_doesnt_revert_test.go b/system_tests/precompile_doesnt_revert_test.go new file mode 100644 index 0000000000..e6751d347d --- /dev/null +++ b/system_tests/precompile_doesnt_revert_test.go @@ -0,0 +1,248 @@ +// Copyright 2021-2024, Offchain Labs, Inc. +// For license information, see https://github.com/OffchainLabs/nitro/blob/master/LICENSE + +package arbtest + +import ( + "context" + "encoding/json" + "math/big" + "testing" + + "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/crypto" + "github.com/ethereum/go-ethereum/params" + "github.com/offchainlabs/nitro/arbos/l1pricing" + "github.com/offchainlabs/nitro/solgen/go/precompilesgen" +) + +// DoesntRevert tests are useful to check if precompile calls revert due to differences in the +// return types of a contract between go and solidity. +// They are not a substitute for unit tests, as they don't test the actual functionality of the precompile. + +func TestArbAddressTableDoesntRevert(t *testing.T) { + t.Parallel() + + ctx, cancel := context.WithCancel(context.Background()) + defer cancel() + + builder := NewNodeBuilder(ctx).DefaultConfig(t, false) + cleanup := builder.Build(t) + defer cleanup() + + auth := builder.L2Info.GetDefaultTransactOpts("Owner", ctx) + callOpts := &bind.CallOpts{Context: ctx} + + arbAddressTable, err := precompilesgen.NewArbAddressTable(types.ArbAddressTableAddress, builder.L2.Client) + Require(t, err) + + addr := common.BytesToAddress(crypto.Keccak256([]byte{})[:20]) + + exists, err := arbAddressTable.AddressExists(callOpts, addr) + Require(t, err) + if exists { + Fatal(t, "expected address to not exist") + } + + tx, err := arbAddressTable.Register(&auth, addr) + Require(t, err) + _, err = builder.L2.EnsureTxSucceeded(tx) + Require(t, err) + + idx, err := arbAddressTable.Lookup(callOpts, addr) + Require(t, err) + + retrievedAddr, err := arbAddressTable.LookupIndex(callOpts, idx) + Require(t, err) + if retrievedAddr.Cmp(addr) != 0 { + Fatal(t, "expected retrieved address to be", addr, "got", retrievedAddr) + } + + size, err := arbAddressTable.Size(callOpts) + Require(t, err) + if size.Cmp(big.NewInt(1)) != 0 { + Fatal(t, "expected size to be 1, got", size) + } + + tx, err = arbAddressTable.Compress(&auth, addr) + Require(t, err) + _, err = builder.L2.EnsureTxSucceeded(tx) + Require(t, err) + + res := []uint8{128} + _, _, err = arbAddressTable.Decompress(callOpts, res, big.NewInt(0)) + Require(t, err) +} + +func TestArbAggregatorDoesntRevert(t *testing.T) { + t.Parallel() + + ctx, cancel := context.WithCancel(context.Background()) + defer cancel() + + builder := NewNodeBuilder(ctx).DefaultConfig(t, false) + cleanup := builder.Build(t) + defer cleanup() + + auth := builder.L2Info.GetDefaultTransactOpts("Owner", ctx) + callOpts := &bind.CallOpts{Context: ctx} + + arbAggregator, err := precompilesgen.NewArbAggregator(types.ArbAggregatorAddress, builder.L2.Client) + Require(t, err) + + tx, err := arbAggregator.SetFeeCollector(&auth, l1pricing.BatchPosterAddress, common.Address{}) + Require(t, err) + _, err = builder.L2.EnsureTxSucceeded(tx) + Require(t, err) + + _, err = arbAggregator.GetFeeCollector(callOpts, l1pricing.BatchPosterAddress) + Require(t, err) +} + +func TestArbosTestDoesntRevert(t *testing.T) { + t.Parallel() + + ctx, cancel := context.WithCancel(context.Background()) + defer cancel() + + builder := NewNodeBuilder(ctx).DefaultConfig(t, false) + cleanup := builder.Build(t) + defer cleanup() + + callOpts := &bind.CallOpts{Context: ctx} + + arbosTest, err := precompilesgen.NewArbosTest(types.ArbosTestAddress, builder.L2.Client) + Require(t, err) + + err = arbosTest.BurnArbGas(callOpts, big.NewInt(1)) + Require(t, err) +} + +func TestArbSysDoesntRevert(t *testing.T) { + t.Parallel() + + ctx, cancel := context.WithCancel(context.Background()) + defer cancel() + + builder := NewNodeBuilder(ctx).DefaultConfig(t, false) + cleanup := builder.Build(t) + defer cleanup() + + callOpts := &bind.CallOpts{Context: ctx} + + arbSys, err := precompilesgen.NewArbSys(types.ArbSysAddress, builder.L2.Client) + Require(t, err) + + addr1 := common.BytesToAddress(crypto.Keccak256([]byte{})[:20]) + addr2 := common.BytesToAddress(crypto.Keccak256([]byte{})[:20]) + _, err = arbSys.MapL1SenderContractAddressToL2Alias(callOpts, addr1, addr2) + Require(t, err) +} + +func TestArbOwnerDoesntRevert(t *testing.T) { + t.Parallel() + + ctx, cancel := context.WithCancel(context.Background()) + defer cancel() + + builder := NewNodeBuilder(ctx).DefaultConfig(t, false) + cleanup := builder.Build(t) + defer cleanup() + + auth := builder.L2Info.GetDefaultTransactOpts("Owner", ctx) + + arbOwner, err := precompilesgen.NewArbOwner(types.ArbOwnerAddress, builder.L2.Client) + Require(t, err) + + chainConfig := params.ArbitrumDevTestChainConfig() + chainConfig.ArbitrumChainParams.MaxCodeSize = 100 + serializedChainConfig, err := json.Marshal(chainConfig) + Require(t, err) + tx, err := arbOwner.SetChainConfig(&auth, string(serializedChainConfig)) + Require(t, err) + _, err = builder.L2.EnsureTxSucceeded(tx) + Require(t, err) + + tx, err = arbOwner.SetAmortizedCostCapBips(&auth, 77734) + Require(t, err) + _, err = builder.L2.EnsureTxSucceeded(tx) + Require(t, err) + + tx, err = arbOwner.ReleaseL1PricerSurplusFunds(&auth, big.NewInt(1)) + Require(t, err) + _, err = builder.L2.EnsureTxSucceeded(tx) + Require(t, err) + + tx, err = arbOwner.SetL2BaseFee(&auth, big.NewInt(1)) + Require(t, err) + _, err = builder.L2.EnsureTxSucceeded(tx) + Require(t, err) +} + +func TestArbGasInfoDoesntRevert(t *testing.T) { + t.Parallel() + + ctx, cancel := context.WithCancel(context.Background()) + defer cancel() + + builder := NewNodeBuilder(ctx).DefaultConfig(t, false) + cleanup := builder.Build(t) + defer cleanup() + + callOpts := &bind.CallOpts{Context: ctx} + addr := common.BytesToAddress(crypto.Keccak256([]byte{})[:20]) + + arbGasInfo, err := precompilesgen.NewArbGasInfo(types.ArbGasInfoAddress, builder.L2.Client) + Require(t, err) + + _, err = arbGasInfo.GetGasBacklog(callOpts) + Require(t, err) + + _, err = arbGasInfo.GetLastL1PricingUpdateTime(callOpts) + Require(t, err) + + _, err = arbGasInfo.GetL1PricingFundsDueForRewards(callOpts) + Require(t, err) + + _, err = arbGasInfo.GetL1PricingUnitsSinceUpdate(callOpts) + Require(t, err) + + _, err = arbGasInfo.GetLastL1PricingSurplus(callOpts) + Require(t, err) + + _, _, _, err = arbGasInfo.GetPricesInArbGas(callOpts) + Require(t, err) + + _, _, _, err = arbGasInfo.GetPricesInArbGasWithAggregator(callOpts, addr) + Require(t, err) + + _, err = arbGasInfo.GetAmortizedCostCapBips(callOpts) + Require(t, err) + + _, err = arbGasInfo.GetL1FeesAvailable(callOpts) + Require(t, err) + + _, _, _, _, _, _, err = arbGasInfo.GetPricesInWeiWithAggregator(callOpts, addr) + Require(t, err) +} + +func TestArbRetryableTxDoesntRevert(t *testing.T) { + t.Parallel() + + ctx, cancel := context.WithCancel(context.Background()) + defer cancel() + + builder := NewNodeBuilder(ctx).DefaultConfig(t, false) + cleanup := builder.Build(t) + defer cleanup() + + callOpts := &bind.CallOpts{Context: ctx} + + arbRetryableTx, err := precompilesgen.NewArbRetryableTx(common.HexToAddress("6e"), builder.L2.Client) + Require(t, err) + + _, err = arbRetryableTx.GetCurrentRedeemer(callOpts) + Require(t, err) +} diff --git a/system_tests/precompile_test.go b/system_tests/precompile_test.go index 9e829124ee..9d5737c249 100644 --- a/system_tests/precompile_test.go +++ b/system_tests/precompile_test.go @@ -7,12 +7,16 @@ import ( "context" "fmt" "math/big" + "sort" "testing" "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/crypto" "github.com/ethereum/go-ethereum/params" "github.com/offchainlabs/nitro/arbos" + "github.com/offchainlabs/nitro/arbos/l1pricing" "github.com/offchainlabs/nitro/solgen/go/mocksgen" "github.com/offchainlabs/nitro/solgen/go/precompilesgen" "github.com/offchainlabs/nitro/util/arbmath" @@ -22,7 +26,10 @@ func TestPurePrecompileMethodCalls(t *testing.T) { ctx, cancel := context.WithCancel(context.Background()) defer cancel() - builder := NewNodeBuilder(ctx).DefaultConfig(t, false) + arbosVersion := uint64(31) + builder := NewNodeBuilder(ctx). + DefaultConfig(t, false). + WithArbOSVersion(arbosVersion) cleanup := builder.Build(t) defer cleanup() @@ -33,6 +40,19 @@ func TestPurePrecompileMethodCalls(t *testing.T) { if chainId.Uint64() != params.ArbitrumDevTestChainConfig().ChainID.Uint64() { Fatal(t, "Wrong ChainID", chainId.Uint64()) } + + expectedArbosVersion := 55 + arbosVersion // Nitro versions start at 56 + arbSysArbosVersion, err := arbSys.ArbOSVersion(&bind.CallOpts{}) + Require(t, err) + if arbSysArbosVersion.Uint64() != expectedArbosVersion { + Fatal(t, "Expected ArbOS version", expectedArbosVersion, "got", arbSysArbosVersion) + } + + storageGasAvailable, err := arbSys.GetStorageGasAvailable(&bind.CallOpts{}) + Require(t, err) + if storageGasAvailable.Cmp(big.NewInt(0)) != 0 { + Fatal(t, "Expected 0 storage gas available, got", storageGasAvailable) + } } func TestViewLogReverts(t *testing.T) { @@ -52,7 +72,29 @@ func TestViewLogReverts(t *testing.T) { } } -func TestCustomSolidityErrors(t *testing.T) { +func TestArbDebugPanic(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("Owner", ctx) + + arbDebug, err := precompilesgen.NewArbDebug(types.ArbDebugAddress, builder.L2.Client) + Require(t, err) + + _, err = arbDebug.Panic(&auth) + if err == nil { + Fatal(t, "unexpected success") + } + if err.Error() != "method handler crashed" { + Fatal(t, "expected method handler to crash") + } +} + +func TestArbDebugLegacyError(t *testing.T) { ctx, cancel := context.WithCancel(context.Background()) defer cancel() @@ -61,32 +103,97 @@ func TestCustomSolidityErrors(t *testing.T) { defer cleanup() callOpts := &bind.CallOpts{Context: ctx} + arbDebug, err := precompilesgen.NewArbDebug(common.HexToAddress("0xff"), builder.L2.Client) - Require(t, err, "could not bind ArbDebug contract") - customError := arbDebug.CustomRevert(callOpts, 1024) - if customError == nil { - Fatal(t, "customRevert call should have errored") + Require(t, err) + + err = arbDebug.LegacyError(callOpts) + if err == nil { + Fatal(t, "unexpected success") } - observedMessage := customError.Error() - expectedError := "Custom(1024, This spider family wards off bugs: /\\oo/\\ //\\(oo)//\\ /\\oo/\\, true)" - // The first error is server side. The second error is client side ABI decoding. - expectedMessage := fmt.Sprintf("execution reverted: error %v: %v", expectedError, expectedError) - if observedMessage != expectedMessage { - Fatal(t, observedMessage) +} + +func TestCustomSolidityErrors(t *testing.T) { + ctx, cancel := context.WithCancel(context.Background()) + defer cancel() + + builder := NewNodeBuilder(ctx).DefaultConfig(t, false) + cleanup := builder.Build(t) + defer cleanup() + + callOpts := &bind.CallOpts{Context: ctx} + auth := builder.L2Info.GetDefaultTransactOpts("Owner", ctx) + + ensure := func( + customError error, + expectedError string, + scenario string, + ) { + if customError == nil { + Fatal(t, "should have errored", "scenario", scenario) + } + observedMessage := customError.Error() + // The first error is server side. The second error is client side ABI decoding. + expectedMessage := fmt.Sprintf("execution reverted: error %v: %v", expectedError, expectedError) + if observedMessage != expectedMessage { + Fatal(t, observedMessage, "scenario", scenario) + } } + arbDebug, err := precompilesgen.NewArbDebug(types.ArbDebugAddress, builder.L2.Client) + Require(t, err, "could not bind ArbDebug contract") + ensure( + arbDebug.CustomRevert(callOpts, 1024), + "Custom(1024, This spider family wards off bugs: /\\oo/\\ //\\(oo)//\\ /\\oo/\\, true)", + "arbDebug.CustomRevert", + ) + arbSys, err := precompilesgen.NewArbSys(arbos.ArbSysAddress, builder.L2.Client) Require(t, err, "could not bind ArbSys contract") - _, customError = arbSys.ArbBlockHash(callOpts, big.NewInt(1e9)) - if customError == nil { - Fatal(t, "out of range ArbBlockHash call should have errored") - } - observedMessage = customError.Error() - expectedError = "InvalidBlockNumber(1000000000, 1)" - expectedMessage = fmt.Sprintf("execution reverted: error %v: %v", expectedError, expectedError) - if observedMessage != expectedMessage { - Fatal(t, observedMessage) - } + _, customError := arbSys.ArbBlockHash(callOpts, big.NewInt(1e9)) + ensure( + customError, + "InvalidBlockNumber(1000000000, 1)", + "arbSys.ArbBlockHash", + ) + + arbRetryableTx, err := precompilesgen.NewArbRetryableTx(types.ArbRetryableTxAddress, builder.L2.Client) + Require(t, err) + _, customError = arbRetryableTx.SubmitRetryable( + &auth, + [32]byte{}, + big.NewInt(0), + big.NewInt(0), + big.NewInt(0), + big.NewInt(0), + 0, + big.NewInt(0), + common.Address{}, + common.Address{}, + common.Address{}, + []byte{}, + ) + ensure( + customError, + "NotCallable()", + "arbRetryableTx.SubmitRetryable", + ) + + arbosActs, err := precompilesgen.NewArbosActs(types.ArbosAddress, builder.L2.Client) + Require(t, err) + _, customError = arbosActs.StartBlock(&auth, big.NewInt(0), 0, 0, 0) + ensure( + customError, + "CallerNotArbOS()", + "arbosActs.StartBlock", + ) + + _, customError = arbosActs.BatchPostingReport(&auth, big.NewInt(0), common.Address{}, 0, 0, big.NewInt(0)) + ensure( + customError, + "CallerNotArbOS()", + "arbosActs.BatchPostingReport", + ) } func TestPrecompileErrorGasLeft(t *testing.T) { @@ -125,6 +232,274 @@ func TestPrecompileErrorGasLeft(t *testing.T) { assertNotAllGasConsumed(common.HexToAddress("0xff"), arbDebug.Methods["legacyError"].ID) } +func setupArbOwnerAndArbGasInfo( + t *testing.T, +) ( + *NodeBuilder, + func(), + bind.TransactOpts, + *precompilesgen.ArbOwner, + *precompilesgen.ArbGasInfo, +) { + ctx, cancel := context.WithCancel(context.Background()) + + builder := NewNodeBuilder(ctx).DefaultConfig(t, false) + builderCleanup := builder.Build(t) + + cleanup := func() { + builderCleanup() + cancel() + } + + auth := builder.L2Info.GetDefaultTransactOpts("Owner", ctx) + + arbOwner, err := precompilesgen.NewArbOwner(common.HexToAddress("0x70"), builder.L2.Client) + Require(t, err) + arbGasInfo, err := precompilesgen.NewArbGasInfo(common.HexToAddress("0x6c"), builder.L2.Client) + Require(t, err) + + return builder, cleanup, auth, arbOwner, arbGasInfo +} + +func TestL1BaseFeeEstimateInertia(t *testing.T) { + t.Parallel() + + builder, cleanup, auth, arbOwner, arbGasInfo := setupArbOwnerAndArbGasInfo(t) + defer cleanup() + ctx := builder.ctx + + inertia := uint64(11) + tx, err := arbOwner.SetL1BaseFeeEstimateInertia(&auth, inertia) + Require(t, err) + _, err = builder.L2.EnsureTxSucceeded(tx) + Require(t, err) + arbGasInfoInertia, err := arbGasInfo.GetL1BaseFeeEstimateInertia(&bind.CallOpts{Context: ctx}) + Require(t, err) + if arbGasInfoInertia != inertia { + Fatal(t, "expected inertia to be", inertia, "got", arbGasInfoInertia) + } +} + +// Similar to TestL1BaseFeeEstimateInertia, but now using a different setter from ArbOwner +func TestL1PricingInertia(t *testing.T) { + t.Parallel() + + builder, cleanup, auth, arbOwner, arbGasInfo := setupArbOwnerAndArbGasInfo(t) + defer cleanup() + ctx := builder.ctx + + inertia := uint64(12) + tx, err := arbOwner.SetL1PricingInertia(&auth, inertia) + Require(t, err) + _, err = builder.L2.EnsureTxSucceeded(tx) + Require(t, err) + arbGasInfoInertia, err := arbGasInfo.GetL1BaseFeeEstimateInertia(&bind.CallOpts{Context: ctx}) + Require(t, err) + if arbGasInfoInertia != inertia { + Fatal(t, "expected inertia to be", inertia, "got", arbGasInfoInertia) + } +} + +func TestL1PricingRewardRate(t *testing.T) { + t.Parallel() + + builder, cleanup, auth, arbOwner, arbGasInfo := setupArbOwnerAndArbGasInfo(t) + defer cleanup() + ctx := builder.ctx + + perUnitReward := uint64(13) + tx, err := arbOwner.SetL1PricingRewardRate(&auth, perUnitReward) + Require(t, err) + _, err = builder.L2.EnsureTxSucceeded(tx) + Require(t, err) + arbGasInfoPerUnitReward, err := arbGasInfo.GetL1RewardRate(&bind.CallOpts{Context: ctx}) + Require(t, err) + if arbGasInfoPerUnitReward != perUnitReward { + Fatal(t, "expected per unit reward to be", perUnitReward, "got", arbGasInfoPerUnitReward) + } +} + +func TestL1PricingRewardRecipient(t *testing.T) { + t.Parallel() + + builder, cleanup, auth, arbOwner, arbGasInfo := setupArbOwnerAndArbGasInfo(t) + defer cleanup() + ctx := builder.ctx + + rewardRecipient := common.BytesToAddress(crypto.Keccak256([]byte{})[:20]) + tx, err := arbOwner.SetL1PricingRewardRecipient(&auth, rewardRecipient) + Require(t, err) + _, err = builder.L2.EnsureTxSucceeded(tx) + Require(t, err) + arbGasInfoRewardRecipient, err := arbGasInfo.GetL1RewardRecipient(&bind.CallOpts{Context: ctx}) + Require(t, err) + if arbGasInfoRewardRecipient.Cmp(rewardRecipient) != 0 { + Fatal(t, "expected reward recipient to be", rewardRecipient, "got", arbGasInfoRewardRecipient) + } +} + +func TestL2GasPricingInertia(t *testing.T) { + t.Parallel() + + builder, cleanup, auth, arbOwner, arbGasInfo := setupArbOwnerAndArbGasInfo(t) + defer cleanup() + ctx := builder.ctx + + inertia := uint64(14) + tx, err := arbOwner.SetL2GasPricingInertia(&auth, inertia) + Require(t, err) + _, err = builder.L2.EnsureTxSucceeded(tx) + Require(t, err) + arbGasInfoInertia, err := arbGasInfo.GetPricingInertia(&bind.CallOpts{Context: ctx}) + Require(t, err) + if arbGasInfoInertia != inertia { + Fatal(t, "expected inertia to be", inertia, "got", arbGasInfoInertia) + } +} + +func TestL2GasBacklogTolerance(t *testing.T) { + t.Parallel() + + builder, cleanup, auth, arbOwner, arbGasInfo := setupArbOwnerAndArbGasInfo(t) + defer cleanup() + ctx := builder.ctx + + gasTolerance := uint64(15) + tx, err := arbOwner.SetL2GasBacklogTolerance(&auth, gasTolerance) + Require(t, err) + _, err = builder.L2.EnsureTxSucceeded(tx) + Require(t, err) + arbGasInfoGasTolerance, err := arbGasInfo.GetGasBacklogTolerance(&bind.CallOpts{Context: ctx}) + Require(t, err) + if arbGasInfoGasTolerance != gasTolerance { + Fatal(t, "expected gas tolerance to be", gasTolerance, "got", arbGasInfoGasTolerance) + } +} + +func TestPerBatchGasCharge(t *testing.T) { + t.Parallel() + + builder, cleanup, auth, arbOwner, arbGasInfo := setupArbOwnerAndArbGasInfo(t) + defer cleanup() + ctx := builder.ctx + + perBatchGasCharge := int64(16) + tx, err := arbOwner.SetPerBatchGasCharge(&auth, perBatchGasCharge) + Require(t, err) + _, err = builder.L2.EnsureTxSucceeded(tx) + Require(t, err) + arbGasInfoPerBatchGasCharge, err := arbGasInfo.GetPerBatchGasCharge(&bind.CallOpts{Context: ctx}) + Require(t, err) + if arbGasInfoPerBatchGasCharge != perBatchGasCharge { + Fatal(t, "expected per batch gas charge to be", perBatchGasCharge, "got", arbGasInfoPerBatchGasCharge) + } +} + +func TestL1PricingEquilibrationUnits(t *testing.T) { + t.Parallel() + + builder, cleanup, auth, arbOwner, arbGasInfo := setupArbOwnerAndArbGasInfo(t) + defer cleanup() + ctx := builder.ctx + + equilUnits := big.NewInt(17) + tx, err := arbOwner.SetL1PricingEquilibrationUnits(&auth, equilUnits) + Require(t, err) + _, err = builder.L2.EnsureTxSucceeded(tx) + Require(t, err) + arbGasInfoEquilUnits, err := arbGasInfo.GetL1PricingEquilibrationUnits(&bind.CallOpts{Context: ctx}) + Require(t, err) + if arbGasInfoEquilUnits.Cmp(equilUnits) != 0 { + Fatal(t, "expected equilibration units to be", equilUnits, "got", arbGasInfoEquilUnits) + } +} + +func TestGasAccountingParams(t *testing.T) { + t.Parallel() + + builder, cleanup, auth, arbOwner, arbGasInfo := setupArbOwnerAndArbGasInfo(t) + defer cleanup() + ctx := builder.ctx + + speedLimit := uint64(18) + txGasLimit := uint64(19) + tx, err := arbOwner.SetSpeedLimit(&auth, speedLimit) + Require(t, err) + _, err = builder.L2.EnsureTxSucceeded(tx) + Require(t, err) + tx, err = arbOwner.SetMaxTxGasLimit(&auth, txGasLimit) + Require(t, err) + _, err = builder.L2.EnsureTxSucceeded(tx) + Require(t, err) + arbGasInfoSpeedLimit, arbGasInfoPoolSize, arbGasInfoTxGasLimit, err := arbGasInfo.GetGasAccountingParams(&bind.CallOpts{Context: ctx}) + Require(t, err) + if arbGasInfoSpeedLimit.Cmp(big.NewInt(int64(speedLimit))) != 0 { + Fatal(t, "expected speed limit to be", speedLimit, "got", arbGasInfoSpeedLimit) + } + if arbGasInfoPoolSize.Cmp(big.NewInt(int64(txGasLimit))) != 0 { + Fatal(t, "expected pool size to be", txGasLimit, "got", arbGasInfoPoolSize) + } + if arbGasInfoTxGasLimit.Cmp(big.NewInt(int64(txGasLimit))) != 0 { + Fatal(t, "expected tx gas limit to be", txGasLimit, "got", arbGasInfoTxGasLimit) + } +} + +func TestCurrentTxL1GasFees(t *testing.T) { + t.Parallel() + + ctx, cancel := context.WithCancel(context.Background()) + defer cancel() + + builder := NewNodeBuilder(ctx).DefaultConfig(t, false) + cleanup := builder.Build(t) + defer cleanup() + + arbGasInfo, err := precompilesgen.NewArbGasInfo(types.ArbGasInfoAddress, builder.L2.Client) + Require(t, err) + + currTxL1GasFees, err := arbGasInfo.GetCurrentTxL1GasFees(&bind.CallOpts{Context: ctx}) + Require(t, err) + if currTxL1GasFees == nil { + Fatal(t, "currTxL1GasFees is nil") + } + if currTxL1GasFees.Cmp(big.NewInt(0)) != 1 { + Fatal(t, "expected currTxL1GasFees to be greater than 0, got", currTxL1GasFees) + } +} + +func TestGetBrotliCompressionLevel(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("Owner", ctx) + + arbOwnerPublic, err := precompilesgen.NewArbOwnerPublic(types.ArbOwnerPublicAddress, builder.L2.Client) + Require(t, err) + + arbOwner, err := precompilesgen.NewArbOwner(types.ArbOwnerAddress, builder.L2.Client) + Require(t, err) + + brotliCompressionLevel := uint64(11) + + // sets brotli compression level + tx, err := arbOwner.SetBrotliCompressionLevel(&auth, brotliCompressionLevel) + Require(t, err) + _, err = builder.L2.EnsureTxSucceeded(tx) + Require(t, err) + + // retrieves brotli compression level + callOpts := &bind.CallOpts{Context: ctx} + retrievedBrotliCompressionLevel, err := arbOwnerPublic.GetBrotliCompressionLevel(callOpts) + Require(t, err) + if retrievedBrotliCompressionLevel != brotliCompressionLevel { + Fatal(t, "expected brotli compression level to be", brotliCompressionLevel, "got", retrievedBrotliCompressionLevel) + } +} + func TestScheduleArbosUpgrade(t *testing.T) { ctx, cancel := context.WithCancel(context.Background()) defer cancel() @@ -175,3 +550,291 @@ func TestScheduleArbosUpgrade(t *testing.T) { t.Errorf("expected upgrade to be scheduled for version %v timestamp %v, got version %v timestamp %v", testVersion, testTimestamp, scheduled.ArbosVersion, scheduled.ScheduledForTimestamp) } } + +func TestArbStatistics(t *testing.T) { + t.Parallel() + + ctx, cancel := context.WithCancel(context.Background()) + defer cancel() + + builder := NewNodeBuilder(ctx).DefaultConfig(t, false) + cleanup := builder.Build(t) + defer cleanup() + + arbStatistics, err := precompilesgen.NewArbStatistics(types.ArbStatisticsAddress, builder.L2.Client) + Require(t, err) + + callOpts := &bind.CallOpts{Context: ctx} + blockNum, _, _, _, _, _, err := arbStatistics.GetStats(callOpts) + Require(t, err) + + expectedBlockNum, err := builder.L2.Client.BlockNumber(ctx) + Require(t, err) + + if blockNum.Uint64() != expectedBlockNum { + Fatal(t, "expected block number to be", expectedBlockNum, "got", blockNum) + } +} + +func TestArbFunctionTable(t *testing.T) { + t.Parallel() + + ctx, cancel := context.WithCancel(context.Background()) + defer cancel() + + builder := NewNodeBuilder(ctx).DefaultConfig(t, false) + cleanup := builder.Build(t) + defer cleanup() + + auth := builder.L2Info.GetDefaultTransactOpts("Owner", ctx) + callOpts := &bind.CallOpts{Context: ctx} + + arbFunctionTable, err := precompilesgen.NewArbFunctionTable(types.ArbFunctionTableAddress, builder.L2.Client) + Require(t, err) + + addr := common.BytesToAddress(crypto.Keccak256([]byte{})[:20]) + + // should be a noop + tx, err := arbFunctionTable.Upload(&auth, []byte{0, 0, 0, 0}) + Require(t, err) + _, err = builder.L2.EnsureTxSucceeded(tx) + Require(t, err) + + size, err := arbFunctionTable.Size(callOpts, addr) + Require(t, err) + if size.Cmp(big.NewInt(0)) != 0 { + t.Fatal("Size should be 0") + } + + _, _, _, err = arbFunctionTable.Get(callOpts, addr, big.NewInt(10)) + if err == nil { + t.Fatal("Should error") + } +} + +func TestArbAggregatorBaseFee(t *testing.T) { + t.Parallel() + + ctx, cancel := context.WithCancel(context.Background()) + defer cancel() + + builder := NewNodeBuilder(ctx).DefaultConfig(t, false) + cleanup := builder.Build(t) + defer cleanup() + + auth := builder.L2Info.GetDefaultTransactOpts("Owner", ctx) + callOpts := &bind.CallOpts{Context: ctx} + + arbAggregator, err := precompilesgen.NewArbAggregator(types.ArbAggregatorAddress, builder.L2.Client) + Require(t, err) + + tx, err := arbAggregator.SetTxBaseFee(&auth, common.Address{}, big.NewInt(1)) + Require(t, err) + _, err = builder.L2.EnsureTxSucceeded(tx) + Require(t, err) + + fee, err := arbAggregator.GetTxBaseFee(callOpts, common.Address{}) + Require(t, err) + if fee.Cmp(big.NewInt(0)) != 0 { + Fatal(t, "expected fee to be 0, got", fee) + } +} + +func TestFeeAccounts(t *testing.T) { + t.Parallel() + + ctx, cancel := context.WithCancel(context.Background()) + defer cancel() + + builder := NewNodeBuilder(ctx).DefaultConfig(t, false) + cleanup := builder.Build(t) + defer cleanup() + + auth := builder.L2Info.GetDefaultTransactOpts("Owner", ctx) + callOpts := &bind.CallOpts{Context: ctx} + + arbOwner, err := precompilesgen.NewArbOwner(types.ArbOwnerAddress, builder.L2.Client) + Require(t, err) + + builder.L2Info.GenerateAccount("User2") + addr := builder.L2Info.GetAddress("User2") + + tx, err := arbOwner.SetNetworkFeeAccount(&auth, addr) + Require(t, err) + _, err = builder.L2.EnsureTxSucceeded(tx) + Require(t, err) + + feeAccount, err := arbOwner.GetNetworkFeeAccount(callOpts) + Require(t, err) + if feeAccount.Cmp(addr) != 0 { + Fatal(t, "expected fee account to be", addr, "got", feeAccount) + } + + tx, err = arbOwner.SetInfraFeeAccount(&auth, addr) + Require(t, err) + _, err = builder.L2.EnsureTxSucceeded(tx) + Require(t, err) + + feeAccount, err = arbOwner.GetInfraFeeAccount(callOpts) + Require(t, err) + if feeAccount.Cmp(addr) != 0 { + Fatal(t, "expected fee account to be", addr, "got", feeAccount) + } +} + +func TestChainOwners(t *testing.T) { + t.Parallel() + + ctx, cancel := context.WithCancel(context.Background()) + defer cancel() + + builder := NewNodeBuilder(ctx).DefaultConfig(t, false) + cleanup := builder.Build(t) + defer cleanup() + + auth := builder.L2Info.GetDefaultTransactOpts("Owner", ctx) + callOpts := &bind.CallOpts{Context: ctx} + + arbOwnerPublic, err := precompilesgen.NewArbOwnerPublic(types.ArbOwnerPublicAddress, builder.L2.Client) + Require(t, err) + arbOwner, err := precompilesgen.NewArbOwner(types.ArbOwnerAddress, builder.L2.Client) + Require(t, err) + + builder.L2Info.GenerateAccount("Owner2") + chainOwnerAddr2 := builder.L2Info.GetAddress("Owner2") + tx, err := arbOwner.AddChainOwner(&auth, chainOwnerAddr2) + Require(t, err) + _, err = builder.L2.EnsureTxSucceeded(tx) + Require(t, err) + isChainOwner, err := arbOwnerPublic.IsChainOwner(callOpts, chainOwnerAddr2) + Require(t, err) + if !isChainOwner { + Fatal(t, "expected owner2 to be a chain owner") + } + + // check that the chain owners retrieved from arbOwnerPublic and arbOwner are the same + chainOwnersArbOwnerPublic, err := arbOwnerPublic.GetAllChainOwners(callOpts) + Require(t, err) + chainOwnersArbOwner, err := arbOwner.GetAllChainOwners(callOpts) + Require(t, err) + if len(chainOwnersArbOwnerPublic) != len(chainOwnersArbOwner) { + Fatal(t, "expected chain owners to be the same length") + } + // sort the chain owners to ensure they are in the same order + sort.Slice(chainOwnersArbOwnerPublic, func(i, j int) bool { + return chainOwnersArbOwnerPublic[i].Cmp(chainOwnersArbOwnerPublic[j]) < 0 + }) + for i := 0; i < len(chainOwnersArbOwnerPublic); i += 1 { + if chainOwnersArbOwnerPublic[i].Cmp(chainOwnersArbOwner[i]) != 0 { + Fatal(t, "expected chain owners to be the same") + } + } + chainOwnerAddr := builder.L2Info.GetAddress("Owner") + chainOwnerInChainOwners := false + for _, chainOwner := range chainOwnersArbOwner { + if chainOwner.Cmp(chainOwnerAddr) == 0 { + chainOwnerInChainOwners = true + } + } + if !chainOwnerInChainOwners { + Fatal(t, "expected owner to be in chain owners") + } + + // remove chain owner 2 + tx, err = arbOwner.RemoveChainOwner(&auth, chainOwnerAddr2) + Require(t, err) + _, err = builder.L2.EnsureTxSucceeded(tx) + Require(t, err) + isChainOwner, err = arbOwnerPublic.IsChainOwner(callOpts, chainOwnerAddr2) + Require(t, err) + if isChainOwner { + Fatal(t, "expected owner2 to not be a chain owner") + } + + _, err = arbOwnerPublic.RectifyChainOwner(&auth, chainOwnerAddr) + if (err == nil) || (err.Error() != "execution reverted") { + Fatal(t, "expected rectify chain owner to revert since it is already an owner") + } +} + +func TestArbAggregatorBatchPosters(t *testing.T) { + t.Parallel() + + ctx, cancel := context.WithCancel(context.Background()) + defer cancel() + + builder := NewNodeBuilder(ctx).DefaultConfig(t, false) + cleanup := builder.Build(t) + defer cleanup() + + auth := builder.L2Info.GetDefaultTransactOpts("Owner", ctx) + callOpts := &bind.CallOpts{Context: ctx} + + arbAggregator, err := precompilesgen.NewArbAggregator(types.ArbAggregatorAddress, builder.L2.Client) + Require(t, err) + + arbDebug, err := precompilesgen.NewArbDebug(types.ArbDebugAddress, builder.L2.Client) + Require(t, err) + + addr := common.BytesToAddress(crypto.Keccak256([]byte{})[:20]) + + // initially should have one batch poster + bps, err := arbAggregator.GetBatchPosters(callOpts) + Require(t, err) + if len(bps) != 1 { + Fatal(t, "expected one batch poster") + } + + // add addr as a batch poster + tx, err := arbDebug.BecomeChainOwner(&auth) + Require(t, err) + _, err = builder.L2.EnsureTxSucceeded(tx) + Require(t, err) + tx, err = arbAggregator.AddBatchPoster(&auth, addr) + Require(t, err) + _, err = builder.L2.EnsureTxSucceeded(tx) + Require(t, err) + + // there should now be two batch posters, and addr should be one of them + bps, err = arbAggregator.GetBatchPosters(callOpts) + Require(t, err) + if len(bps) != 2 { + Fatal(t, "expected two batch posters") + } + if bps[0] != addr && bps[1] != addr { + Fatal(t, "expected addr to be a batch poster") + } +} + +func TestArbAggregatorGetPreferredAggregator(t *testing.T) { + t.Parallel() + + ctx, cancel := context.WithCancel(context.Background()) + defer cancel() + + builder := NewNodeBuilder(ctx).DefaultConfig(t, false) + cleanup := builder.Build(t) + defer cleanup() + + callOpts := &bind.CallOpts{Context: ctx} + + arbAggregator, err := precompilesgen.NewArbAggregator(types.ArbAggregatorAddress, builder.L2.Client) + Require(t, err) + + addr := common.BytesToAddress(crypto.Keccak256([]byte{})[:20]) + + prefAgg, isDefault, err := arbAggregator.GetPreferredAggregator(callOpts, addr) + Require(t, err) + if !isDefault { + Fatal(t, "expected default preferred aggregator") + } + if prefAgg != l1pricing.BatchPosterAddress { + Fatal(t, "expected default preferred aggregator to be", l1pricing.BatchPosterAddress, "got", prefAgg) + } + + prefAgg, err = arbAggregator.GetDefaultAggregator(callOpts) + Require(t, err) + if prefAgg != l1pricing.BatchPosterAddress { + Fatal(t, "expected default preferred aggregator to be", l1pricing.BatchPosterAddress, "got", prefAgg) + } +} diff --git a/system_tests/program_test.go b/system_tests/program_test.go index 4c896d1791..ea4ccddd03 100644 --- a/system_tests/program_test.go +++ b/system_tests/program_test.go @@ -535,6 +535,16 @@ func testCalls(t *testing.T, jit bool) { defer cleanup() callsAddr := deployWasm(t, ctx, auth, l2client, rustFile("multicall")) + // checks that ArbInfo.GetCode works properly + codeFromFile, _ := readWasmFile(t, rustFile("multicall")) + arbInfo, err := pgen.NewArbInfo(types.ArbInfoAddress, l2client) + Require(t, err) + codeFromArbInfo, err := arbInfo.GetCode(nil, callsAddr) + Require(t, err) + if !bytes.Equal(codeFromFile, codeFromArbInfo) { + t.Fatal("ArbInfo.GetCode returned wrong code") + } + ensure := func(tx *types.Transaction, err error) *types.Receipt { t.Helper() Require(t, err) @@ -716,6 +726,13 @@ func testCalls(t *testing.T, jit bool) { Fatal(t, balance, value) } + // checks that ArbInfo.GetBalance works properly + balance, err = arbInfo.GetBalance(nil, eoa) + Require(t, err) + if !arbmath.BigEquals(balance, value) { + Fatal(t, balance, value) + } + blocks := []uint64{10} validateBlockRange(t, blocks, jit, builder) } @@ -1242,6 +1259,140 @@ func testSdkStorage(t *testing.T, jit bool) { check() } +func TestStylusPrecompileMethodsSimple(t *testing.T) { + ctx, cancel := context.WithCancel(context.Background()) + defer cancel() + + builder := NewNodeBuilder(ctx).DefaultConfig(t, true) + cleanup := builder.Build(t) + defer cleanup() + + arbOwner, err := pgen.NewArbOwner(types.ArbOwnerAddress, builder.L2.Client) + Require(t, err) + arbDebug, err := pgen.NewArbDebug(types.ArbDebugAddress, builder.L2.Client) + Require(t, err) + arbWasm, err := pgen.NewArbWasm(types.ArbWasmAddress, builder.L2.Client) + Require(t, err) + + ensure := func(tx *types.Transaction, err error) *types.Receipt { + t.Helper() + Require(t, err) + receipt, err := EnsureTxSucceeded(ctx, builder.L2.Client, tx) + Require(t, err) + return receipt + } + + ownerAuth := builder.L2Info.GetDefaultTransactOpts("Owner", ctx) + ensure(arbDebug.BecomeChainOwner(&ownerAuth)) + + wasm, _ := readWasmFile(t, rustFile("keccak")) + programAddress := deployContract(t, ctx, ownerAuth, builder.L2.Client, wasm) + + activateAuth := ownerAuth + activateAuth.Value = oneEth + ensure(arbWasm.ActivateProgram(&activateAuth, programAddress)) + + expectedExpiryDays := uint16(1) + ensure(arbOwner.SetWasmExpiryDays(&ownerAuth, expectedExpiryDays)) + ed, err := arbWasm.ExpiryDays(nil) + Require(t, err) + if ed != expectedExpiryDays { + t.Errorf("ExpiryDays from arbWasm precompile didnt match the value set by arbowner. have: %d, want: %d", ed, expectedExpiryDays) + } + ptl, err := arbWasm.ProgramTimeLeft(nil, programAddress) + Require(t, err) + expectedExpirySeconds := (uint64(expectedExpiryDays) * 24 * 3600) + // ProgramTimeLeft returns time in seconds to expiry and the current ExpiryDays is set to 1 day + // We expect the lag of 3600 seconds to exist because program.activatedAt uses hoursSinceArbitrum that + // rounds down (the current time since ArbitrumStartTime in hours)/3600 + if expectedExpirySeconds-ptl > 3600 { + t.Errorf("ProgramTimeLeft from arbWasm precompile returned value lesser than expected. %d <= want <= %d, have: %d", expectedExpirySeconds-3600, expectedExpirySeconds, ptl) + } + + ensure(arbOwner.SetWasmBlockCacheSize(&ownerAuth, 100)) + bcs, err := arbWasm.BlockCacheSize(nil) + Require(t, err) + if bcs != 100 { + t.Errorf("BlockCacheSize from arbWasm precompile didnt match the value set by arbowner. have: %d, want: %d", bcs, 100) + } + + ensure(arbOwner.SetWasmFreePages(&ownerAuth, 3)) + fp, err := arbWasm.FreePages(nil) + Require(t, err) + if fp != 3 { + t.Errorf("FreePages from arbWasm precompile didnt match the value set by arbowner. have: %d, want: %d", fp, 3) + } + + ensure(arbOwner.SetWasmInitCostScalar(&ownerAuth, uint64(4))) + ics, err := arbWasm.InitCostScalar(nil) + Require(t, err) + if ics != uint64(4) { + t.Errorf("InitCostScalar from arbWasm precompile didnt match the value set by arbowner. have: %d, want: %d", ics, 4) + } + + ensure(arbOwner.SetInkPrice(&ownerAuth, uint32(5))) + ip, err := arbWasm.InkPrice(nil) + Require(t, err) + if ip != uint32(5) { + t.Errorf("InkPrice from arbWasm precompile didnt match the value set by arbowner. have: %d, want: %d", ip, 5) + } + + ensure(arbOwner.SetWasmKeepaliveDays(&ownerAuth, 0)) + kad, err := arbWasm.KeepaliveDays(nil) + Require(t, err) + if kad != 0 { + t.Errorf("KeepaliveDays from arbWasm precompile didnt match the value set by arbowner. have: %d, want: 0", kad) + } + + ensure(arbOwner.SetWasmMaxStackDepth(&ownerAuth, uint32(6))) + msd, err := arbWasm.MaxStackDepth(nil) + Require(t, err) + if msd != uint32(6) { + t.Errorf("MaxStackDepth from arbWasm precompile didnt match the value set by arbowner. have: %d, want: %d", msd, 6) + } + + // Setting low values of gas and cached parameters ensures when MinInitGas is called on ArbWasm precompile, + // the returned values would be programs.MinInitGasUnits and programs.MinCachedGasUnits + ensure(arbOwner.SetWasmMinInitGas(&ownerAuth, 1, 1)) + mig, err := arbWasm.MinInitGas(nil) + Require(t, err) + if mig.Gas != programs.MinInitGasUnits { + t.Errorf("MinInitGas from arbWasm precompile didnt match the Gas value set by arbowner. have: %d, want: %d", mig.Gas, programs.MinInitGasUnits) + } + if mig.Cached != programs.MinCachedGasUnits { + t.Errorf("MinInitGas from arbWasm precompile didnt match the Cached value set by arbowner. have: %d, want: %d", mig.Cached, programs.MinCachedGasUnits) + } + + ensure(arbOwner.SetWasmPageGas(&ownerAuth, 7)) + pg, err := arbWasm.PageGas(nil) + Require(t, err) + if pg != 7 { + t.Errorf("PageGas from arbWasm precompile didnt match the value set by arbowner. have: %d, want: %d", pg, 7) + } + + ensure(arbOwner.SetWasmPageLimit(&ownerAuth, 8)) + pl, err := arbWasm.PageLimit(nil) + Require(t, err) + if pl != 8 { + t.Errorf("PageLimit from arbWasm precompile didnt match the value set by arbowner. have: %d, want: %d", pl, 8) + } + + // pageramp currently is initialPageRamp = 620674314 value in programs package + _, err = arbWasm.PageRamp(nil) + Require(t, err) + + codehash := crypto.Keccak256Hash(wasm) + cas, err := arbWasm.CodehashAsmSize(nil, codehash) + Require(t, err) + if cas == 0 { + t.Error("CodehashAsmSize from arbWasm precompile returned 0 value") + } + // Since ArbOwner has set wasm KeepaliveDays to 0, it enables us to do this, though this shouldn't have any effect + codehashKeepaliveAuth := ownerAuth + codehashKeepaliveAuth.Value = oneEth + ensure(arbWasm.CodehashKeepalive(&codehashKeepaliveAuth, codehash)) +} + func TestProgramActivationLogs(t *testing.T) { t.Parallel() builder, auth, cleanup := setupProgramTest(t, true) diff --git a/system_tests/retryable_test.go b/system_tests/retryable_test.go index aa9fbfd72e..89446e3c4b 100644 --- a/system_tests/retryable_test.go +++ b/system_tests/retryable_test.go @@ -423,6 +423,118 @@ func TestSubmitRetryableFailThenRetry(t *testing.T) { } } +func TestGetLifetime(t *testing.T) { + t.Parallel() + + ctx, cancel := context.WithCancel(context.Background()) + defer cancel() + + builder := NewNodeBuilder(ctx).DefaultConfig(t, false) + cleanup := builder.Build(t) + defer cleanup() + + callOpts := &bind.CallOpts{Context: ctx} + + arbRetryableTx, err := precompilesgen.NewArbRetryableTx(common.HexToAddress("6e"), builder.L2.Client) + Require(t, err) + + lifetime, err := arbRetryableTx.GetLifetime(callOpts) + Require(t, err) + if lifetime.Cmp(big.NewInt(retryables.RetryableLifetimeSeconds)) != 0 { + t.Fatal("Expected to be ", retryables.RetryableLifetimeSeconds, " but got ", lifetime) + } +} + +func TestKeepaliveAndCancelRetryable(t *testing.T) { + t.Parallel() + builder, delayedInbox, lookupL2Tx, ctx, teardown := retryableSetup(t) + defer teardown() + + ownerTxOpts := builder.L2Info.GetDefaultTransactOpts("Owner", ctx) + usertxopts := builder.L1Info.GetDefaultTransactOpts("Faucet", ctx) + usertxopts.Value = arbmath.BigMul(big.NewInt(1e12), big.NewInt(1e12)) + + simpleAddr, _ := builder.L2.DeploySimple(t, ownerTxOpts) + simpleABI, err := mocksgen.SimpleMetaData.GetAbi() + Require(t, err) + + beneficiaryAddress := builder.L2Info.GetAddress("Beneficiary") + l1tx, err := delayedInbox.CreateRetryableTicket( + &usertxopts, + simpleAddr, + common.Big0, + big.NewInt(1e16), + beneficiaryAddress, + beneficiaryAddress, + // send enough L2 gas for intrinsic but not compute + big.NewInt(int64(params.TxGas+params.TxDataNonZeroGasEIP2028*4)), + big.NewInt(l2pricing.InitialBaseFeeWei*2), + simpleABI.Methods["incrementRedeem"].ID, + ) + Require(t, err) + + l1Receipt, err := builder.L1.EnsureTxSucceeded(l1tx) + Require(t, err) + if l1Receipt.Status != types.ReceiptStatusSuccessful { + Fatal(t, "l1Receipt indicated failure") + } + + waitForL1DelayBlocks(t, builder) + + receipt, err := builder.L2.EnsureTxSucceeded(lookupL2Tx(l1Receipt)) + Require(t, err) + if len(receipt.Logs) != 2 { + Fatal(t, len(receipt.Logs)) + } + ticketId := receipt.Logs[0].Topics[1] + firstRetryTxId := receipt.Logs[1].Topics[2] + + // make sure it failed + receipt, err = WaitForTx(ctx, builder.L2.Client, firstRetryTxId, time.Second*5) + Require(t, err) + if receipt.Status != types.ReceiptStatusFailed { + Fatal(t, receipt.GasUsed) + } + + arbRetryableTx, err := precompilesgen.NewArbRetryableTx(common.HexToAddress("6e"), builder.L2.Client) + Require(t, err) + + // checks that the ticket exists and gets current timeout + timeoutBeforeKeepalive, err := arbRetryableTx.GetTimeout(&bind.CallOpts{}, ticketId) + Require(t, err) + + // checks beneficiary + retrievedBeneficiaryAddress, err := arbRetryableTx.GetBeneficiary(&bind.CallOpts{}, ticketId) + Require(t, err) + if retrievedBeneficiaryAddress != beneficiaryAddress { + Fatal(t, "expected beneficiary to be", beneficiaryAddress, "but got", retrievedBeneficiaryAddress) + } + + // checks that keepalive increases the timeout as expected + _, err = arbRetryableTx.Keepalive(&ownerTxOpts, ticketId) + Require(t, err) + timeoutAfterKeepalive, err := arbRetryableTx.GetTimeout(&bind.CallOpts{}, ticketId) + Require(t, err) + expectedTimeoutAfterKeepAlive := timeoutBeforeKeepalive + expectedTimeoutAfterKeepAlive.Add(expectedTimeoutAfterKeepAlive, big.NewInt(retryables.RetryableLifetimeSeconds)) + if timeoutAfterKeepalive.Cmp(expectedTimeoutAfterKeepAlive) != 0 { + Fatal(t, "expected timeout after keepalive to be", expectedTimeoutAfterKeepAlive, "but got", timeoutAfterKeepalive) + } + + // cancel the ticket + beneficiaryTxOpts := builder.L2Info.GetDefaultTransactOpts("Beneficiary", ctx) + tx, err := arbRetryableTx.Cancel(&beneficiaryTxOpts, ticketId) + Require(t, err) + _, err = builder.L2.EnsureTxSucceeded(tx) + Require(t, err) + + // checks that the ticket no longer exists + _, err = arbRetryableTx.GetTimeout(&bind.CallOpts{}, ticketId) + if (err == nil) || (err.Error() != "execution reverted: error NoTicketWithID(): NoTicketWithID()") { + Fatal(t, "didn't get expected NoTicketWithID error") + } +} + func TestSubmissionGasCosts(t *testing.T) { t.Parallel() builder, delayedInbox, lookupL2Tx, ctx, teardown := retryableSetup(t)