Skip to content

Commit

Permalink
Merge branch 'master' into bold
Browse files Browse the repository at this point in the history
  • Loading branch information
amsanghi committed Nov 29, 2023
2 parents 3f0d737 + 59e4e51 commit 4187bf5
Show file tree
Hide file tree
Showing 22 changed files with 266 additions and 40 deletions.
2 changes: 1 addition & 1 deletion arbnode/delayed.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ func (m *DelayedInboxMessage) AfterInboxAcc() common.Hash {
arbmath.UintToBytes(m.Message.Header.BlockNumber),
arbmath.UintToBytes(m.Message.Header.Timestamp),
m.Message.Header.RequestId.Bytes(),
math.U256Bytes(m.Message.Header.L1BaseFee),
arbmath.U256Bytes(m.Message.Header.L1BaseFee),
crypto.Keccak256(m.Message.L2msg),
)
return crypto.Keccak256Hash(m.BeforeInboxAcc[:], hash)
Expand Down
7 changes: 3 additions & 4 deletions arbnode/inbox_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import (
"github.com/offchainlabs/nitro/util/testhelpers"

"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/math"
"github.com/ethereum/go-ethereum/core"
"github.com/ethereum/go-ethereum/core/rawdb"
"github.com/ethereum/go-ethereum/core/types"
Expand Down Expand Up @@ -148,10 +147,10 @@ func TestTransactionStreamer(t *testing.T) {
var gas uint64 = 100000
var l2Message []byte
l2Message = append(l2Message, arbos.L2MessageKind_ContractTx)
l2Message = append(l2Message, math.U256Bytes(new(big.Int).SetUint64(gas))...)
l2Message = append(l2Message, math.U256Bytes(big.NewInt(l2pricing.InitialBaseFeeWei))...)
l2Message = append(l2Message, arbmath.Uint64ToU256Bytes(gas)...)
l2Message = append(l2Message, arbmath.Uint64ToU256Bytes(l2pricing.InitialBaseFeeWei)...)
l2Message = append(l2Message, dest.Hash().Bytes()...)
l2Message = append(l2Message, math.U256Bytes(value)...)
l2Message = append(l2Message, arbmath.U256Bytes(value)...)
var requestId common.Hash
binary.BigEndian.PutUint64(requestId.Bytes()[:8], uint64(i))
messages = append(messages, arbostypes.MessageWithMetadata{
Expand Down
5 changes: 2 additions & 3 deletions arbnode/transaction_streamer.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import (
"github.com/syndtr/goleveldb/leveldb"

"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/math"
"github.com/ethereum/go-ethereum/ethdb"
"github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/params"
Expand All @@ -35,6 +34,7 @@ import (
"github.com/offchainlabs/nitro/broadcaster"
"github.com/offchainlabs/nitro/execution"
"github.com/offchainlabs/nitro/staker"
"github.com/offchainlabs/nitro/util/arbmath"
"github.com/offchainlabs/nitro/util/sharedmetrics"
"github.com/offchainlabs/nitro/util/stopwaiter"
)
Expand Down Expand Up @@ -531,8 +531,7 @@ func (s *TransactionStreamer) AddFakeInitMessage() error {
if err != nil {
return fmt.Errorf("failed to serialize chain config: %w", err)
}
// TODO: once we have a safe U256Bytes that does a copy internally, use that instead of doing an explicit copy here
chainIdBytes := math.U256Bytes(new(big.Int).Set(s.chainConfig.ChainID))
chainIdBytes := arbmath.U256Bytes(s.chainConfig.ChainID)
msg := append(append(chainIdBytes, 0), chainConfigJson...)
return s.AddMessages(0, false, []arbostypes.MessageWithMetadata{{
Message: &arbostypes.L1IncomingMessage{
Expand Down
7 changes: 3 additions & 4 deletions arbos/parse_l2.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"time"

"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/math"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/log"
Expand Down Expand Up @@ -40,8 +39,8 @@ func ParseL2Transactions(msg *arbostypes.L1IncomingMessage, chainId *big.Int, ba
return nil, errors.New("cannot issue L2 funded by L1 tx without L1 request id")
}
kind := msg.L2msg[0]
depositRequestId := crypto.Keccak256Hash(msg.Header.RequestId[:], math.U256Bytes(common.Big0))
unsignedRequestId := crypto.Keccak256Hash(msg.Header.RequestId[:], math.U256Bytes(common.Big1))
depositRequestId := crypto.Keccak256Hash(msg.Header.RequestId[:], arbmath.U256Bytes(common.Big0))
unsignedRequestId := crypto.Keccak256Hash(msg.Header.RequestId[:], arbmath.U256Bytes(common.Big1))
tx, err := parseUnsignedTx(bytes.NewReader(msg.L2msg[1:]), msg.Header.Poster, &unsignedRequestId, chainId, kind)
if err != nil {
return nil, err
Expand Down Expand Up @@ -146,7 +145,7 @@ func parseL2Message(rd io.Reader, poster common.Address, timestamp uint64, reque

var nextRequestId *common.Hash
if requestId != nil {
subRequestId := crypto.Keccak256Hash(requestId[:], math.U256Bytes(index))
subRequestId := crypto.Keccak256Hash(requestId[:], arbmath.U256Bytes(index))
nextRequestId = &subRequestId
}
nestedSegments, err := parseL2Message(bytes.NewReader(nextMsg), poster, timestamp, nextRequestId, chainId, depth+1)
Expand Down
2 changes: 1 addition & 1 deletion arbos/storage/storage_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func TestStorageBackedBigInt(t *testing.T) {
t.Fatal(err)
}
// Verify that our encoding matches geth's signed complement impl
expectedRawVal := common.BigToHash(math.U256(new(big.Int).Set(in)))
expectedRawVal := common.BigToHash(arbmath.U256(in))
if rawVal != expectedRawVal {
t.Fatal("for input", in, "expected raw value", expectedRawVal, "but got", rawVal)
}
Expand Down
3 changes: 3 additions & 0 deletions cmd/nitro/nitro.go
Original file line number Diff line number Diff line change
Expand Up @@ -838,6 +838,9 @@ func applyChainParameters(ctx context.Context, k *koanf.Koanf, chainId uint64, c
chainDefaults["node.batch-poster.max-size"] = safeBatchSize
chainDefaults["node.sequencer.max-tx-data-size"] = safeBatchSize - bufferSpace
}
if chainInfo.DasIndexUrl != "" {
chainDefaults["node.batch-poster.max-size"] = 1000000
}
err = k.Load(confmap.Provider(chainDefaults, "."), nil)
if err != nil {
return false, err
Expand Down
2 changes: 1 addition & 1 deletion fastcache
Submodule fastcache updated 1 files
+2 −0 fastcache.go
3 changes: 2 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ replace github.com/OffchainLabs/bold => ./bold

require (
github.com/OffchainLabs/bold v0.0.0-00010101000000-000000000000
github.com/Shopify/toxiproxy v2.1.4+incompatible
github.com/alicebob/miniredis/v2 v2.21.0
github.com/allegro/bigcache v1.2.1-0.20190218064605-e24eb225f156
github.com/andybalholm/brotli v1.0.4
Expand Down Expand Up @@ -84,7 +85,7 @@ require (
github.com/cockroachdb/logtags v0.0.0-20230118201751-21c54148d20b // indirect
github.com/cockroachdb/redact v1.1.3 // indirect
github.com/consensys/bavard v0.1.13 // indirect
github.com/consensys/gnark-crypto v0.10.0 // indirect
github.com/consensys/gnark-crypto v0.12.1 // indirect
github.com/containerd/cgroups v1.1.0 // indirect
github.com/coreos/go-systemd/v22 v22.5.0 // indirect
github.com/cpuguy83/go-md2man/v2 v2.0.2 // indirect
Expand Down
5 changes: 3 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAE
github.com/Shopify/goreferrer v0.0.0-20181106222321-ec9c9a553398/go.mod h1:a1uqRtAwp2Xwc6WNPJEufxJ7fx3npB4UV/JOLmbu5I0=
github.com/Shopify/sarama v1.19.0/go.mod h1:FVkBWblsNy7DGZRfXLU0O9RCGt5g3g3yEuWXgklEdEo=
github.com/Shopify/sarama v1.30.0/go.mod h1:zujlQQx1kzHsh4jfV1USnptCQrHAEZ2Hk8fTKCulPVs=
github.com/Shopify/toxiproxy v2.1.4+incompatible h1:TKdv8HiTLgE5wdJuEML90aBgNWsokNbMijUGhmcoBJc=
github.com/Shopify/toxiproxy v2.1.4+incompatible/go.mod h1:OXgGpZ6Cli1/URJOF1DMxUHB2q5Ap20/P/eIdh4G0pI=
github.com/Shopify/toxiproxy/v2 v2.1.6-0.20210914104332-15ea381dcdae/go.mod h1:/cvHQkZ1fst0EmZnA5dFtiQdWCNCFYzb+uE2vqVgvx0=
github.com/Stebalien/go-bitfield v0.0.1/go.mod h1:GNjFpasyUVkHMsfEOk8EFLJ9syQ6SI+XWrX9Wf2XH0s=
Expand Down Expand Up @@ -236,8 +237,8 @@ github.com/codeclysm/extract/v3 v3.0.2/go.mod h1:NKsw+hqua9H+Rlwy/w/3Qgt9jDonYEg
github.com/codegangsta/inject v0.0.0-20150114235600-33e0aa1cb7c0/go.mod h1:4Zcjuz89kmFXt9morQgcfYZAYZ5n8WHjt81YYWIwtTM=
github.com/consensys/bavard v0.1.13 h1:oLhMLOFGTLdlda/kma4VOJazblc7IM5y5QPd2A/YjhQ=
github.com/consensys/bavard v0.1.13/go.mod h1:9ItSMtA/dXMAiL7BG6bqW2m3NdSEObYWoH223nGHukI=
github.com/consensys/gnark-crypto v0.10.0 h1:zRh22SR7o4K35SoNqouS9J/TKHTyU2QWaj5ldehyXtA=
github.com/consensys/gnark-crypto v0.10.0/go.mod h1:Iq/P3HHl0ElSjsg2E1gsMwhAyxnxoKK5nVyZKd+/KhU=
github.com/consensys/gnark-crypto v0.12.1 h1:lHH39WuuFgVHONRl3J0LRBtuYdQTumFSDtJF7HpyG8M=
github.com/consensys/gnark-crypto v0.12.1/go.mod h1:v2Gy7L/4ZRosZ7Ivs+9SfUDr0f5UlG+EM5t7MPHiLuY=
github.com/containerd/cgroups v0.0.0-20201119153540-4cbc285b3327/go.mod h1:ZJeTFisyysqgcCdecO57Dj79RfL0LNeGiFUqLYQRYLE=
github.com/containerd/cgroups v1.1.0 h1:v8rEWFl6EoqHB+swVNjVoCJE8o3jX7e8nqBGPLaDFBM=
github.com/containerd/cgroups v1.1.0/go.mod h1:6ppBcbh/NOOUU+dMKrykgaBnK9lCIBxHqJDGwsa1mIw=
Expand Down
7 changes: 3 additions & 4 deletions precompiles/ArbSys.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"math/big"

"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/math"
"github.com/ethereum/go-ethereum/core/vm"
"github.com/offchainlabs/nitro/arbos/util"
"github.com/offchainlabs/nitro/util/arbmath"
Expand Down Expand Up @@ -121,9 +120,9 @@ func (con *ArbSys) SendTxToL1(c ctx, evm mech, value huge, destination addr, cal
sendHash, err := arbosState.KeccakHash(
c.caller.Bytes(),
destination.Bytes(),
math.U256Bytes(evm.Context.BlockNumber),
math.U256Bytes(bigL1BlockNum),
math.U256Bytes(&t),
arbmath.U256Bytes(evm.Context.BlockNumber),
arbmath.U256Bytes(bigL1BlockNum),
arbmath.U256Bytes(&t),
common.BigToHash(value).Bytes(),
calldataForL1,
)
Expand Down
7 changes: 4 additions & 3 deletions staker/assertion.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@ import (
"math/big"

"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/math"
"github.com/ethereum/go-ethereum/crypto"

"github.com/offchainlabs/nitro/solgen/go/rollupgen"
"github.com/offchainlabs/nitro/util/arbmath"
"github.com/offchainlabs/nitro/validator"
)

Expand Down Expand Up @@ -39,8 +40,8 @@ func HashChallengeState(
hashesBytes = append(hashesBytes, h[:]...)
}
return crypto.Keccak256Hash(
math.U256Bytes(new(big.Int).SetUint64(segmentStart)),
math.U256Bytes(new(big.Int).SetUint64(segmentLength)),
arbmath.Uint64ToU256Bytes(segmentStart),
arbmath.Uint64ToU256Bytes(segmentLength),
hashesBytes,
)
}
Expand Down
30 changes: 29 additions & 1 deletion system_tests/block_validator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"time"

"github.com/ethereum/go-ethereum"
"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"
Expand All @@ -22,7 +23,9 @@ import (
"github.com/offchainlabs/nitro/arbos/l2pricing"
"github.com/offchainlabs/nitro/arbutil"
"github.com/offchainlabs/nitro/execution/gethexec"
"github.com/offchainlabs/nitro/solgen/go/mocksgen"
"github.com/offchainlabs/nitro/solgen/go/precompilesgen"
"github.com/offchainlabs/nitro/util/arbmath"
)

type workloadType uint
Expand Down Expand Up @@ -71,6 +74,7 @@ func testBlockValidatorSimple(t *testing.T, dasModeString string, workloadLoops

perTransfer := big.NewInt(1e12)

var simple *mocksgen.Simple
if workload != upgradeArbOs {
for i := 0; i < workloadLoops; i++ {
var tx *types.Transaction
Expand Down Expand Up @@ -122,10 +126,24 @@ func testBlockValidatorSimple(t *testing.T, dasModeString string, workloadLoops
}
} else {
auth := builder.L2Info.GetDefaultTransactOpts("Owner", ctx)
// deploy a test contract
var err error
_, _, simple, err = mocksgen.DeploySimple(&auth, builder.L2.Client)
Require(t, err, "could not deploy contract")

tx, err := simple.StoreDifficulty(&auth)
Require(t, err)
_, err = EnsureTxSucceeded(ctx, builder.L2.Client, tx)
Require(t, err)
difficulty, err := simple.GetBlockDifficulty(&bind.CallOpts{})
Require(t, err)
if !arbmath.BigEquals(difficulty, common.Big1) {
Fatal(t, "Expected difficulty to be 1 but got:", difficulty)
}
// make auth a chain owner
arbDebug, err := precompilesgen.NewArbDebug(common.HexToAddress("0xff"), builder.L2.Client)
Require(t, err)
tx, err := arbDebug.BecomeChainOwner(&auth)
tx, err = arbDebug.BecomeChainOwner(&auth)
Require(t, err)
_, err = builder.L2.EnsureTxSucceeded(tx)
Require(t, err)
Expand All @@ -136,6 +154,16 @@ func testBlockValidatorSimple(t *testing.T, dasModeString string, workloadLoops
_, err = builder.L2.EnsureTxSucceeded(tx)
Require(t, err)

tx, err = simple.StoreDifficulty(&auth)
Require(t, err)
_, err = EnsureTxSucceeded(ctx, builder.L2.Client, tx)
Require(t, err)
difficulty, err = simple.GetBlockDifficulty(&bind.CallOpts{})
Require(t, err)
if !arbmath.BigEquals(difficulty, common.Big1) {
Fatal(t, "Expected difficulty to be 1 but got:", difficulty)
}

tx = builder.L2Info.PrepareTxTo("Owner", nil, builder.L2Info.TransferGas, perTransfer, []byte{byte(vm.PUSH0)})
err = builder.L2.Client.SendTransaction(ctx, tx)
Require(t, err)
Expand Down
7 changes: 3 additions & 4 deletions system_tests/contract_tx_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (
"time"

"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/math"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/params"
Expand Down Expand Up @@ -64,10 +63,10 @@ func TestContractTxDeploy(t *testing.T) {
Data: deployCode,
}
l2Msg := []byte{arbos.L2MessageKind_ContractTx}
l2Msg = append(l2Msg, math.U256Bytes(arbmath.UintToBig(contractTx.Gas))...)
l2Msg = append(l2Msg, math.U256Bytes(contractTx.GasFeeCap)...)
l2Msg = append(l2Msg, arbmath.Uint64ToU256Bytes(contractTx.Gas)...)
l2Msg = append(l2Msg, arbmath.U256Bytes(contractTx.GasFeeCap)...)
l2Msg = append(l2Msg, common.Hash{}.Bytes()...) // to is zero, translated into nil
l2Msg = append(l2Msg, math.U256Bytes(contractTx.Value)...)
l2Msg = append(l2Msg, arbmath.U256Bytes(contractTx.Value)...)
l2Msg = append(l2Msg, contractTx.Data...)

err = builder.L2.ConsensusNode.TxStreamer.AddMessages(pos, true, []arbostypes.MessageWithMetadata{
Expand Down
14 changes: 7 additions & 7 deletions system_tests/deployment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,18 @@ package arbtest
import (
"bytes"
"context"
"math/big"
"strings"
"testing"

"github.com/ethereum/go-ethereum"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/math"
"github.com/ethereum/go-ethereum/core"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/core/vm"
"github.com/ethereum/go-ethereum/ethclient"
"github.com/ethereum/go-ethereum/params"

"github.com/offchainlabs/nitro/util/arbmath"
)

func testContractDeployment(t *testing.T, ctx context.Context, client *ethclient.Client, contractCode []byte, accountInfo *AccountInfo, expectedEstimateGasError error) {
Expand All @@ -26,7 +26,7 @@ func testContractDeployment(t *testing.T, ctx context.Context, client *ethclient
0x7F, // PUSH32
}
// len(contractCode)
deployCode = append(deployCode, math.U256Bytes(big.NewInt(int64(len(contractCode))))...)
deployCode = append(deployCode, arbmath.Uint64ToU256Bytes(uint64(len(contractCode)))...)
var codeOffset byte = 42
deployCode = append(deployCode, []byte{
0x80, // DUP
Expand Down Expand Up @@ -115,7 +115,7 @@ func TestContractDeployment(t *testing.T) {
defer cleanup()

account := builder.L2Info.GetInfoWithPrivKey("Faucet")
for _, size := range []int{0, 1, 1000, 20000, params.MaxCodeSize} {
for _, size := range []int{0, 1, 1000, 20000, params.DefaultMaxCodeSize} {
testContractDeployment(t, ctx, builder.L2.Client, makeContractOfLength(size), account, nil)
}

Expand All @@ -128,13 +128,13 @@ func TestExtendedContractDeployment(t *testing.T) {
defer cancel()

builder := NewNodeBuilder(ctx).DefaultConfig(t, false)
builder.chainConfig.ArbitrumChainParams.MaxCodeSize = params.MaxCodeSize * 3
builder.chainConfig.ArbitrumChainParams.MaxInitCodeSize = params.MaxInitCodeSize * 3
builder.chainConfig.ArbitrumChainParams.MaxCodeSize = params.DefaultMaxCodeSize * 3
builder.chainConfig.ArbitrumChainParams.MaxInitCodeSize = params.DefaultMaxInitCodeSize * 3
cleanup := builder.Build(t)
defer cleanup()

account := builder.L2Info.GetInfoWithPrivKey("Faucet")
for _, size := range []int{0, 1, 1000, 20000, 30000, 40000, 60000, params.MaxCodeSize * 3} {
for _, size := range []int{0, 1, 1000, 20000, 30000, 40000, 60000, params.DefaultMaxCodeSize * 3} {
testContractDeployment(t, ctx, builder.L2.Client, makeContractOfLength(size), account, nil)
}

Expand Down
51 changes: 51 additions & 0 deletions system_tests/estimation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,57 @@ func TestEstimate(t *testing.T) {
}
}

func TestDifficultyForLatestArbOS(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)

// deploy a test contract
_, _, simple, err := mocksgen.DeploySimple(&auth, builder.L2.Client)
Require(t, err, "could not deploy contract")

tx, err := simple.StoreDifficulty(&auth)
Require(t, err)
_, err = EnsureTxSucceeded(ctx, builder.L2.Client, tx)
Require(t, err)
difficulty, err := simple.GetBlockDifficulty(&bind.CallOpts{})
Require(t, err)
if !arbmath.BigEquals(difficulty, common.Big1) {
Fatal(t, "Expected difficulty to be 1 but got:", difficulty)
}
}

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

builder := NewNodeBuilder(ctx).DefaultConfig(t, false)
builder.chainConfig.ArbitrumChainParams.InitialArbOSVersion = 10
cleanup := builder.Build(t)
defer cleanup()

auth := builder.L2Info.GetDefaultTransactOpts("Owner", ctx)

// deploy a test contract
_, _, simple, err := mocksgen.DeploySimple(&auth, builder.L2.Client)
Require(t, err, "could not deploy contract")

tx, err := simple.StoreDifficulty(&auth)
Require(t, err)
_, err = EnsureTxSucceeded(ctx, builder.L2.Client, tx)
Require(t, err)
difficulty, err := simple.GetBlockDifficulty(&bind.CallOpts{})
Require(t, err)
if !arbmath.BigEquals(difficulty, common.Big1) {
Fatal(t, "Expected difficulty to be 1 but got:", difficulty)
}
}

func TestComponentEstimate(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
Expand Down
Loading

0 comments on commit 4187bf5

Please sign in to comment.