Skip to content

Commit

Permalink
update geth dependency to version w/ v1.13.11 upstream commits (#10041)
Browse files Browse the repository at this point in the history
* update geth dependency to version with upstream updates to v1.13.11

* fix op-program tests

* update op-geth dep to tagged commit
  • Loading branch information
roberto-bayardo committed Apr 8, 2024
1 parent 8f516fa commit 75816d1
Show file tree
Hide file tree
Showing 20 changed files with 90 additions and 89 deletions.
2 changes: 1 addition & 1 deletion cannon/mipsevm/evm.go
Expand Up @@ -78,7 +78,7 @@ func NewEVMEnv(contracts *Contracts, addrs *Addresses) (*vm.EVM, *state.StateDB)
copy(mipsCtorArgs[12:], addrs.Oracle[:])
mipsDeploy := append(hexutil.MustDecode(bindings.MIPSMetaData.Bin), mipsCtorArgs[:]...)
startingGas := uint64(30_000_000)
_, deployedMipsAddr, leftOverGas, err := env.Create(vm.AccountRef(addrs.Sender), mipsDeploy, startingGas, big.NewInt(0))
_, deployedMipsAddr, leftOverGas, err := env.Create(vm.AccountRef(addrs.Sender), mipsDeploy, startingGas, common.U2560)
if err != nil {
panic(fmt.Errorf("failed to deploy MIPS contract: %w. took %d gas", err, startingGas-leftOverGas))
}
Expand Down
6 changes: 3 additions & 3 deletions cannon/mipsevm/evm_test.go
Expand Up @@ -72,12 +72,12 @@ func (m *MIPSEVM) Step(t *testing.T, stepWitness *StepWitness) []byte {
t.Logf("reading preimage key %x at offset %d", stepWitness.PreimageKey, stepWitness.PreimageOffset)
poInput, err := encodePreimageOracleInput(t, stepWitness, LocalContext{}, m.localOracle)
require.NoError(t, err, "encode preimage oracle input")
_, leftOverGas, err := m.env.Call(vm.AccountRef(sender), m.addrs.Oracle, poInput, startingGas, big.NewInt(0))
_, leftOverGas, err := m.env.Call(vm.AccountRef(sender), m.addrs.Oracle, poInput, startingGas, common.U2560)
require.NoErrorf(t, err, "evm should not fail, took %d gas", startingGas-leftOverGas)
}

input := encodeStepInput(t, stepWitness, LocalContext{})
ret, leftOverGas, err := m.env.Call(vm.AccountRef(sender), m.addrs.MIPS, input, startingGas, big.NewInt(0))
ret, leftOverGas, err := m.env.Call(vm.AccountRef(sender), m.addrs.MIPS, input, startingGas, common.U2560)
require.NoError(t, err, "evm should not fail")
require.Len(t, ret, 32, "expecting 32-byte state hash")
// remember state hash, to check it against state
Expand Down Expand Up @@ -293,7 +293,7 @@ func TestEVMFault(t *testing.T) {
input := encodeStepInput(t, stepWitness, LocalContext{})
startingGas := uint64(30_000_000)

_, _, err := env.Call(vm.AccountRef(sender), addrs.MIPS, input, startingGas, big.NewInt(0))
_, _, err := env.Call(vm.AccountRef(sender), addrs.MIPS, input, startingGas, common.U2560)
require.EqualValues(t, err, vm.ErrExecutionReverted)
logs := evmState.Logs()
require.Equal(t, 0, len(logs))
Expand Down
6 changes: 3 additions & 3 deletions go.mod
Expand Up @@ -12,7 +12,7 @@ require (
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.2.0
github.com/ethereum-optimism/go-ethereum-hdwallet v0.1.3
github.com/ethereum-optimism/superchain-registry/superchain v0.0.0-20240318114348-52d3dbd1605d
github.com/ethereum/go-ethereum v1.13.9
github.com/ethereum/go-ethereum v1.13.11
github.com/fsnotify/fsnotify v1.7.0
github.com/go-chi/chi/v5 v5.0.12
github.com/go-chi/docgen v1.2.0
Expand Down Expand Up @@ -103,7 +103,7 @@ require (
github.com/gballet/go-libpcsclite v0.0.0-20191108122812-4678299bea08 // indirect
github.com/gballet/go-verkle v0.1.1-0.20231031103413-a67434b50f46 // indirect
github.com/getsentry/sentry-go v0.18.0 // indirect
github.com/go-ole/go-ole v1.2.6 // indirect
github.com/go-ole/go-ole v1.3.0 // indirect
github.com/go-sourcemap/sourcemap v2.1.3+incompatible // indirect
github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572 // indirect
github.com/godbus/dbus/v5 v5.1.0 // indirect
Expand Down Expand Up @@ -247,7 +247,7 @@ require (
rsc.io/tmplfunc v0.0.3 // indirect
)

replace github.com/ethereum/go-ethereum v1.13.9 => github.com/ethereum-optimism/op-geth v1.101309.0-rc.2
replace github.com/ethereum/go-ethereum v1.13.11 => github.com/ethereum-optimism/op-geth v1.101311.0-rc.1

//replace github.com/ethereum/go-ethereum v1.13.9 => ../op-geth

Expand Down
8 changes: 5 additions & 3 deletions go.sum
Expand Up @@ -189,8 +189,8 @@ github.com/elastic/gosigar v0.14.2 h1:Dg80n8cr90OZ7x+bAax/QjoW/XqTI11RmA79ZwIm9/
github.com/elastic/gosigar v0.14.2/go.mod h1:iXRIGg2tLnu7LBdpqzyQfGDEidKCfWcCMS0WKyPWoMs=
github.com/ethereum-optimism/go-ethereum-hdwallet v0.1.3 h1:RWHKLhCrQThMfch+QJ1Z8veEq5ZO3DfIhZ7xgRP9WTc=
github.com/ethereum-optimism/go-ethereum-hdwallet v0.1.3/go.mod h1:QziizLAiF0KqyLdNJYD7O5cpDlaFMNZzlxYNcWsJUxs=
github.com/ethereum-optimism/op-geth v1.101309.0-rc.2 h1:8XIKJAH78fLl0AAY4Bq00nIeAeoodZjCcm5CNTcr0eU=
github.com/ethereum-optimism/op-geth v1.101309.0-rc.2/go.mod h1:eFb6HyjixYhM8b0r0imIYKKfhPKx+xIvTqbkIipoBig=
github.com/ethereum-optimism/op-geth v1.101311.0-rc.1 h1:3JE5FyGXNQCnXUuiK3I6ZD3zbB2DBIcEMsXCpjrXUwM=
github.com/ethereum-optimism/op-geth v1.101311.0-rc.1/go.mod h1:K23yb9efVf9DdUOv/vl/Ux57Tng00rLaFqWYlFF45CA=
github.com/ethereum-optimism/superchain-registry/superchain v0.0.0-20240318114348-52d3dbd1605d h1:K7HdD/ZAcSFhcqqnUAbvU+8vsg0DzL8pvetHw5vRLCc=
github.com/ethereum-optimism/superchain-registry/superchain v0.0.0-20240318114348-52d3dbd1605d/go.mod h1:7xh2awFQqsiZxFrHKTgEd+InVfDRrkKVUIuK8SAFHp0=
github.com/ethereum/c-kzg-4844 v0.4.0 h1:3MS1s4JtA868KpJxroZoepdV0ZKBp3u/O5HcZ7R3nlY=
Expand Down Expand Up @@ -244,8 +244,9 @@ github.com/go-logfmt/logfmt v0.4.0/go.mod h1:3RMwSq7FuexP4Kalkev3ejPJsZTpXXBr9+V
github.com/go-logfmt/logfmt v0.5.0/go.mod h1:wCYkCAKZfumFQihp8CzCvQ3paCTfi41vtzG1KdI/P7A=
github.com/go-logr/logr v1.3.0 h1:2y3SDp0ZXuc6/cjLSZ+Q3ir+QB9T/iG5yYRXqsagWSY=
github.com/go-logr/logr v1.3.0/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY=
github.com/go-ole/go-ole v1.2.6 h1:/Fpf6oFPoeFik9ty7siob0G6Ke8QvQEuVcuChpwXzpY=
github.com/go-ole/go-ole v1.2.6/go.mod h1:pprOEPIfldk/42T2oK7lQ4v4JSDwmV0As9GaiUsvbm0=
github.com/go-ole/go-ole v1.3.0 h1:Dt6ye7+vXGIKZ7Xtk4s6/xVdGDQynvom7xCFEdWr6uE=
github.com/go-ole/go-ole v1.3.0/go.mod h1:5LS6F96DhAwUc7C+1HLexzMXY1xGRSryjyPPKW6zv78=
github.com/go-openapi/jsonpointer v0.19.5/go.mod h1:Pl9vOtqEWErmShwVjC8pYs9cog34VGT37dQOVbmoatg=
github.com/go-openapi/swag v0.19.5/go.mod h1:POnQmlKehdgb5mhVOsnJFsivZCEZ/vjK9gh66Z9tfKk=
github.com/go-sourcemap/sourcemap v2.1.3+incompatible h1:W1iEw64niKVGogNgBN3ePyLFfuisuzeidWPMPWmECqU=
Expand Down Expand Up @@ -1061,6 +1062,7 @@ golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBc
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220908164124-27713097b956/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.1.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
Expand Down
3 changes: 2 additions & 1 deletion op-chain-ops/cmd/op-simulate/main.go
Expand Up @@ -11,6 +11,7 @@ import (
"path"
"time"

"github.com/holiman/uint256"
"github.com/pkg/profile"
"github.com/urfave/cli/v2"

Expand Down Expand Up @@ -257,7 +258,7 @@ func simulate(ctx context.Context, logger log.Logger, conf *params.ChainConfig,
}
for addr, acc := range dump {
state.CreateAccount(addr)
state.SetBalance(addr, new(big.Int).Set((*big.Int)(&acc.Balance)))
state.SetBalance(addr, uint256.MustFromBig((*big.Int)(&acc.Balance)))
state.SetNonce(addr, acc.Nonce)
state.SetCode(addr, acc.Code)
state.SetStorage(addr, acc.Storage)
Expand Down
12 changes: 6 additions & 6 deletions op-chain-ops/genesis/layer_one.go
Expand Up @@ -4,13 +4,13 @@ import (
"fmt"
"math/big"

"github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/params"
"github.com/holiman/uint256"

"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/math"
"github.com/ethereum/go-ethereum/core"
gstate "github.com/ethereum/go-ethereum/core/state"
"github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/params"

"github.com/ethereum-optimism/optimism/op-bindings/bindings"
"github.com/ethereum-optimism/optimism/op-chain-ops/state"
Expand Down Expand Up @@ -76,9 +76,9 @@ func BuildL1DeveloperGenesis(config *DeployConfig, dump *gstate.Dump, l1Deployme
memDB.CreateAccount(address)
memDB.SetNonce(address, account.Nonce)

balance, ok := math.ParseBig256(account.Balance)
if !ok {
return nil, fmt.Errorf("failed to parse balance for %s", address)
balance := &uint256.Int{}
if err := balance.UnmarshalText([]byte(account.Balance)); err != nil {
return nil, fmt.Errorf("failed to parse balance for %s: %w", address, err)
}
memDB.AddBalance(address, balance)
memDB.SetCode(address, account.Code)
Expand Down
6 changes: 4 additions & 2 deletions op-chain-ops/genesis/setters.go
Expand Up @@ -5,6 +5,8 @@ import (
"fmt"
"math/big"

"github.com/holiman/uint256"

"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/vm"
"github.com/ethereum/go-ethereum/log"
Expand All @@ -26,7 +28,7 @@ func FundDevAccounts(db vm.StateDB) {
if !db.Exist(account) {
db.CreateAccount(account)
}
db.AddBalance(account, devBalance)
db.AddBalance(account, uint256.MustFromBig(devBalance))
}
}

Expand Down Expand Up @@ -61,7 +63,7 @@ func SetPrecompileBalances(db vm.StateDB) {
for i := 0; i < PrecompileCount; i++ {
addr := common.BytesToAddress([]byte{byte(i)})
db.CreateAccount(addr)
db.AddBalance(addr, common.Big1)
db.AddBalance(addr, uint256.NewInt(1))
}
}

Expand Down
16 changes: 9 additions & 7 deletions op-chain-ops/state/memory_db.go
Expand Up @@ -6,6 +6,8 @@ import (
"math/big"
"sync"

"github.com/holiman/uint256"

"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core"
"github.com/ethereum/go-ethereum/core/types"
Expand Down Expand Up @@ -78,7 +80,7 @@ func (db *MemoryStateDB) createAccount(addr common.Address) {
}
}

func (db *MemoryStateDB) SubBalance(addr common.Address, amount *big.Int) {
func (db *MemoryStateDB) SubBalance(addr common.Address, amount *uint256.Int) {
db.rw.Lock()
defer db.rw.Unlock()

Expand All @@ -89,31 +91,31 @@ func (db *MemoryStateDB) SubBalance(addr common.Address, amount *big.Int) {
if account.Balance.Sign() == 0 {
return
}
account.Balance = new(big.Int).Sub(account.Balance, amount)
account.Balance.Sub(account.Balance, amount.ToBig())
db.genesis.Alloc[addr] = account
}

func (db *MemoryStateDB) AddBalance(addr common.Address, amount *big.Int) {
func (db *MemoryStateDB) AddBalance(addr common.Address, amount *uint256.Int) {
db.rw.Lock()
defer db.rw.Unlock()

account, ok := db.genesis.Alloc[addr]
if !ok {
panic(fmt.Sprintf("%s not in state", addr))
}
account.Balance = new(big.Int).Add(account.Balance, amount)
account.Balance.Add(account.Balance, amount.ToBig())
db.genesis.Alloc[addr] = account
}

func (db *MemoryStateDB) GetBalance(addr common.Address) *big.Int {
func (db *MemoryStateDB) GetBalance(addr common.Address) *uint256.Int {
db.rw.RLock()
defer db.rw.RUnlock()

account, ok := db.genesis.Alloc[addr]
if !ok {
return common.Big0
return common.U2560
}
return account.Balance
return uint256.MustFromBig(account.Balance)
}

func (db *MemoryStateDB) GetNonce(addr common.Address) uint64 {
Expand Down
6 changes: 4 additions & 2 deletions op-chain-ops/state/memory_db_test.go
Expand Up @@ -7,6 +7,8 @@ import (
"testing"
"time"

"github.com/holiman/uint256"

"github.com/ethereum-optimism/optimism/op-chain-ops/state"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/crypto"
Expand All @@ -22,14 +24,14 @@ func TestAddBalance(t *testing.T) {
for i := 0; i < 100; i++ {
key, _ := crypto.GenerateKey()
addr := crypto.PubkeyToAddress(key.PublicKey)
value := new(big.Int).Rand(rng, big.NewInt(1000))
value := uint256.NewInt(uint64(rng.Intn(1000)))

db.CreateAccount(addr)
db.AddBalance(addr, value)

account := db.GetAccount(addr)
require.NotNil(t, account)
require.True(t, BigEqual(account.Balance, value))
require.Equal(t, uint256.MustFromBig(account.Balance), value)
}
}

Expand Down
3 changes: 2 additions & 1 deletion op-e2e/e2eutils/wait/waits.go
Expand Up @@ -6,6 +6,7 @@ import (
"fmt"
"math/big"
"os"
"strings"
"time"

"github.com/ethereum/go-ethereum"
Expand Down Expand Up @@ -46,7 +47,7 @@ func ForReceipt(ctx context.Context, client *ethclient.Client, hash common.Hash,
defer ticker.Stop()
for {
receipt, err := client.TransactionReceipt(ctx, hash)
if errors.Is(err, ethereum.NotFound) {
if errors.Is(err, ethereum.NotFound) || (err != nil && strings.Contains(err.Error(), "transaction indexing is in progress")) {
select {
case <-ctx.Done():
return nil, ctx.Err()
Expand Down
3 changes: 2 additions & 1 deletion op-node/rollup/derive/fuzz_parsers_test.go
Expand Up @@ -6,6 +6,7 @@ import (
"testing"

"github.com/google/go-cmp/cmp"
"github.com/holiman/uint256"
"github.com/stretchr/testify/require"

"github.com/ethereum/go-ethereum/accounts/abi"
Expand Down Expand Up @@ -251,7 +252,7 @@ func FuzzUnmarshallLogEvent(f *testing.F) {
if err != nil {
t.Fatal(err)
}
state.SetBalance(from, BytesToBigInt([]byte{0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff}))
state.SetBalance(from, uint256.MustFromBig(BytesToBigInt([]byte{0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff})))
state.SetCode(addr, common.FromHex(bindings.OptimismPortalDeployedBin))
_, err = state.Commit(0, false)
if err != nil {
Expand Down
8 changes: 7 additions & 1 deletion op-node/withdrawals/proof.go
Expand Up @@ -5,6 +5,8 @@ import (
"errors"
"fmt"

"github.com/holiman/uint256"

"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/crypto"
Expand Down Expand Up @@ -76,12 +78,16 @@ func VerifyStorageProof(root common.Hash, proof gethclient.StorageResult) error
}

func VerifyProof(stateRoot common.Hash, proof *gethclient.AccountResult) error {
balance, overflow := uint256.FromBig(proof.Balance)
if overflow {
return fmt.Errorf("proof balance overflows uint256: %d", proof.Balance)
}
err := VerifyAccountProof(
stateRoot,
proof.Address,
types.StateAccount{
Nonce: proof.Nonce,
Balance: proof.Balance,
Balance: balance,
Root: proof.StorageHash,
CodeHash: proof.CodeHash[:],
},
Expand Down
17 changes: 9 additions & 8 deletions op-program/client/l2/db_test.go
Expand Up @@ -17,6 +17,7 @@ import (
"github.com/ethereum/go-ethereum/params"
"github.com/ethereum/go-ethereum/trie"
"github.com/ethereum/go-ethereum/trie/triedb/hashdb"
"github.com/holiman/uint256"
"github.com/stretchr/testify/require"
)

Expand Down Expand Up @@ -129,13 +130,13 @@ func TestUpdateState(t *testing.T) {

statedb, err := state.New(genesisBlock.Root(), state.NewDatabase(rawdb.NewDatabase(db)), nil)
require.NoError(t, err)
statedb.SetBalance(userAccount, big.NewInt(50))
require.Equal(t, big.NewInt(50), statedb.GetBalance(userAccount))
statedb.SetBalance(userAccount, uint256.NewInt(50))
require.Equal(t, uint256.NewInt(50), statedb.GetBalance(userAccount))
statedb.SetNonce(userAccount, uint64(5))
require.Equal(t, uint64(5), statedb.GetNonce(userAccount))

statedb.SetBalance(unknownAccount, big.NewInt(60))
require.Equal(t, big.NewInt(60), statedb.GetBalance(unknownAccount))
statedb.SetBalance(unknownAccount, uint256.NewInt(60))
require.Equal(t, uint256.NewInt(60), statedb.GetBalance(unknownAccount))
statedb.SetCode(codeAccount, []byte{1})
require.Equal(t, []byte{1}, statedb.GetCode(codeAccount))

Expand All @@ -147,9 +148,9 @@ func TestUpdateState(t *testing.T) {

statedb, err = state.New(newRoot, state.NewDatabase(rawdb.NewDatabase(db)), nil)
require.NoError(t, err)
require.Equal(t, big.NewInt(50), statedb.GetBalance(userAccount))
require.Equal(t, uint256.NewInt(50), statedb.GetBalance(userAccount))
require.Equal(t, uint64(5), statedb.GetNonce(userAccount))
require.Equal(t, big.NewInt(60), statedb.GetBalance(unknownAccount))
require.Equal(t, uint256.NewInt(60), statedb.GetBalance(unknownAccount))
require.Equal(t, []byte{1}, statedb.GetCode(codeAccount))
}

Expand Down Expand Up @@ -183,7 +184,7 @@ func assertStateDataAvailable(t *testing.T, db ethdb.KeyValueStore, l2Genesis *c
require.NoError(t, err)

for address, account := range l2Genesis.Alloc {
require.Equal(t, account.Balance, statedb.GetBalance(address))
require.Equal(t, uint256.MustFromBig(account.Balance), statedb.GetBalance(address))
require.Equal(t, account.Nonce, statedb.GetNonce(address))
require.Equal(t, common.BytesToHash(crypto.Keccak256(account.Code)), statedb.GetCodeHash(address))
require.Equal(t, account.Code, statedb.GetCode(address))
Expand All @@ -192,7 +193,7 @@ func assertStateDataAvailable(t *testing.T, db ethdb.KeyValueStore, l2Genesis *c
}
}
require.Equal(t, common.Hash{}, statedb.GetState(codeAccount, common.HexToHash("0x99")), "retrieve unset storage key")
require.Equal(t, common.Big0, statedb.GetBalance(unknownAccount), "unset account balance")
require.Equal(t, common.U2560, statedb.GetBalance(unknownAccount), "unset account balance")
require.Equal(t, uint64(0), statedb.GetNonce(unknownAccount), "unset account balance")
require.Nil(t, statedb.GetCode(unknownAccount), "unset account code")
require.Equal(t, common.Hash{}, statedb.GetCodeHash(unknownAccount), "unset account code hash")
Expand Down

0 comments on commit 75816d1

Please sign in to comment.