Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions arbos/tx_processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -814,3 +814,7 @@ func (p *TxProcessor) IsCalldataPricingIncreaseEnabled() bool {
}
return enabled
}

func (p *TxProcessor) EVM() *vm.EVM {
return p.evm
}
2 changes: 1 addition & 1 deletion contracts-local/src/precompiles
6 changes: 6 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/tracing"
)

// All calls to this precompile are authorized by the DebugPrecompile wrapper,
Expand Down Expand Up @@ -59,6 +60,11 @@ func (con ArbDebug) BecomeChainOwner(c ctx, evm mech) error {
return c.State.ChainOwners().Add(c.caller)
}

// Overwrite an existing contract's code
func (con ArbDebug) OverwriteContractCode(c ctx, evm mech, addr addr, code []byte) ([]byte, error) {
return c.txProcessor.EVM().StateDB.SetCode(addr, code, tracing.CodeChangeUnspecified), nil
}

// Halts the chain by panicking in the STF
func (con ArbDebug) Panic(c ctx, evm mech) error {
panic("called ArbDebug's debug-only Panic method")
Expand Down
13 changes: 13 additions & 0 deletions precompiles/ArbGasInfo.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
package precompiles

import (
"fmt"
"math/big"

"github.com/ethereum/go-ethereum/common"
Expand Down Expand Up @@ -284,3 +285,15 @@ func (con ArbGasInfo) GetL1PricingUnitsSinceUpdate(c ctx, evm mech) (uint64, err
func (con ArbGasInfo) GetLastL1PricingSurplus(c ctx, evm mech) (*big.Int, error) {
return c.State.L1PricingState().LastSurplus()
}

// GetMaxBlockGasLimit gets the maximum block gas limit
func (con ArbGasInfo) GetMaxBlockGasLimit(c ctx, evm mech) (uint64, error) {
// todo: update with real code once https://github.com/OffchainLabs/nitro/pull/3860 is merged
return 0, fmt.Errorf("GetMaxBlockGasLimit is a stub implementation, since definitions were upstreamed, but implementations not done")
}

// GetGasPricingConstraints gets the current gas pricing constraints used by the Multi-Constraint Pricer.
func (con ArbGasInfo) GetGasPricingConstraints(c ctx, evm mech) ([][3]uint64, error) {
// todo: update with real code once https://github.com/OffchainLabs/nitro/pull/3860 is merged
return nil, fmt.Errorf("GetGasPricingConstraints is a stub implementation, since definitions were upstreamed, but implementations not done")
}
6 changes: 6 additions & 0 deletions precompiles/ArbOwner.go
Original file line number Diff line number Diff line change
Expand Up @@ -453,3 +453,9 @@ func (con ArbOwner) SetChainConfig(c ctx, evm mech, serializedChainConfig []byte
func (con ArbOwner) SetCalldataPriceIncrease(c ctx, _ mech, enable bool) error {
return c.State.Features().SetCalldataPriceIncrease(enable)
}

// SetGasPricingConstraints sets the gas pricing constraints used by the Multi-Constraint Pricer.
func (con ArbOwner) SetGasPricingConstraints(c ctx, evm mech, constraints [][3]uint64) error {
// todo: update with real code once https://github.com/OffchainLabs/nitro/pull/3860 is merged
return fmt.Errorf("SetGasPricingConstraints is a stub implementation, since definitions were upstreamed, but implementations not done")
}
2 changes: 1 addition & 1 deletion precompiles/precompile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ func TestPrecompilesPerArbosVersion(t *testing.T) {
// Each new precompile contract and each method on new or existing precompile
// contracts should be counted.
expectedNewEntriesPerArbosVersion := map[uint64]int{
0: 99,
0: 102,
params.ArbosVersion_5: 3,
params.ArbosVersion_10: 2,
params.ArbosVersion_11: 4,
Expand Down
53 changes: 53 additions & 0 deletions system_tests/precompile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
package arbtest

import (
"bytes"
"context"
"fmt"
"math/big"
Expand Down Expand Up @@ -1312,3 +1313,55 @@ func TestArbAggregatorGetPreferredAggregator(t *testing.T) {
Fatal(t, "expected default preferred aggregator to be", l1pricing.BatchPosterAddress, "got", prefAgg)
}
}

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

builder := NewNodeBuilder(ctx).DefaultConfig(t, false)
cleanup := builder.Build(t)
defer cleanup()

// Become chain owner
auth := builder.L2Info.GetDefaultTransactOpts("Owner", ctx)
arbDebug, err := precompilesgen.NewArbDebug(types.ArbDebugAddress, builder.L2.Client)
Require(t, err)
tx, err := arbDebug.BecomeChainOwner(&auth)
Require(t, err)
_, err = builder.L2.EnsureTxSucceeded(tx)
Require(t, err)

// create EOA to test against
addr := common.BytesToAddress(crypto.Keccak256([]byte{})[:20])

// test that code is empty
code, err := builder.L2.Client.CodeAt(ctx, addr, nil)
Require(t, err)
if len(code) != 0 {
t.Fatal("expected code to be empty")
}

// overwrite with some code
testCodeA := []byte{0, 1, 2, 3, 4, 5, 6, 7, 8, 9}
tx, err = arbDebug.OverwriteContractCode(&auth, addr, testCodeA)
Require(t, err)
_, err = builder.L2.EnsureTxSucceeded(tx)
Require(t, err)
code, err = builder.L2.Client.CodeAt(ctx, addr, nil)
Require(t, err)
if !bytes.Equal(code, testCodeA) {
t.Fatal("expected code A to be", testCodeA, "got", code)
}

// overwrite with some other code
testCodeB := []byte{9, 8, 7, 6, 5, 4, 3, 2, 1, 0}
tx, err = arbDebug.OverwriteContractCode(&auth, addr, testCodeB)
Require(t, err)
_, err = builder.L2.EnsureTxSucceeded(tx)
Require(t, err)
code, err = builder.L2.Client.CodeAt(ctx, addr, nil)
Require(t, err)
if !bytes.Equal(code, testCodeB) {
t.Fatal("expected code B to be", testCodeB, "got", code)
}
}
Loading