Skip to content

Commit

Permalink
Merge pull request #2517 from OffchainLabs/update-gethpin-v1.14.0
Browse files Browse the repository at this point in the history
Update gethpin v1.14.0
  • Loading branch information
tsahee authored Nov 6, 2024
2 parents b4e27fc + f878323 commit 8e69f40
Show file tree
Hide file tree
Showing 23 changed files with 169 additions and 284 deletions.
2 changes: 1 addition & 1 deletion arbnode/batch_poster.go
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ var TestBatchPosterConfig = BatchPosterConfig{
DASRetentionPeriod: daprovider.DefaultDASRetentionPeriod,
GasRefunderAddress: "",
ExtraBatchGas: 10_000,
Post4844Blobs: true,
Post4844Blobs: false,
IgnoreBlobPrice: false,
DataPoster: dataposter.TestDataPosterConfig,
ParentChainWallet: DefaultBatchPosterL1WalletConfig,
Expand Down
1 change: 0 additions & 1 deletion arbos/arbosState/initialization_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ func tryMarshalUnmarshal(input *statetransfer.ArbosInitializationInfo, t *testin
cacheConfig := core.DefaultCacheConfigWithScheme(env.GetTestStateScheme())
stateroot, err := InitializeArbosInDatabase(raw, cacheConfig, initReader, chainConfig, arbostypes.TestInitMessage, 0, 0)
Require(t, err)

triedbConfig := cacheConfig.TriedbConfig()
stateDb, err := state.New(stateroot, state.NewDatabaseWithConfig(raw, triedbConfig), nil)
Require(t, err)
Expand Down
7 changes: 4 additions & 3 deletions arbos/arbosState/initialize.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package arbosState

import (
"errors"
"github.com/ethereum/go-ethereum/core/tracing"
"math/big"
"regexp"
"sort"
Expand Down Expand Up @@ -159,7 +160,7 @@ func InitializeArbosInDatabase(db ethdb.Database, cacheConfig *core.CacheConfig,
if err != nil {
return common.Hash{}, err
}
statedb.SetBalance(account.Addr, uint256.MustFromBig(account.EthBalance))
statedb.SetBalance(account.Addr, uint256.MustFromBig(account.EthBalance), tracing.BalanceChangeUnspecified)
statedb.SetNonce(account.Addr, account.Nonce)
if account.ContractInfo != nil {
statedb.SetCode(account.Addr, account.ContractInfo.Code)
Expand Down Expand Up @@ -190,7 +191,7 @@ func initializeRetryables(statedb *state.StateDB, rs *retryables.RetryableState,
return err
}
if r.Timeout <= currentTimestamp {
statedb.AddBalance(r.Beneficiary, uint256.MustFromBig(r.Callvalue))
statedb.AddBalance(r.Beneficiary, uint256.MustFromBig(r.Callvalue), tracing.BalanceChangeUnspecified)
continue
}
retryablesList = append(retryablesList, r)
Expand All @@ -209,7 +210,7 @@ func initializeRetryables(statedb *state.StateDB, rs *retryables.RetryableState,
addr := r.To
to = &addr
}
statedb.AddBalance(retryables.RetryableEscrowAddress(r.Id), uint256.MustFromBig(r.Callvalue))
statedb.AddBalance(retryables.RetryableEscrowAddress(r.Id), uint256.MustFromBig(r.Callvalue), tracing.BalanceChangeUnspecified)
_, err := rs.CreateRetryable(r.Id, r.Timeout, r.From, to, r.Callvalue, r.Beneficiary, r.Calldata)
if err != nil {
return err
Expand Down
11 changes: 5 additions & 6 deletions arbos/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,16 +48,15 @@ func (e Engine) Prepare(chain consensus.ChainHeaderReader, header *types.Header)
return nil
}

func (e Engine) Finalize(chain consensus.ChainHeaderReader, header *types.Header, state *state.StateDB, txs []*types.Transaction, uncles []*types.Header, withdrawals []*types.Withdrawal) {
FinalizeBlock(header, txs, state, chain.Config())
func (e Engine) Finalize(chain consensus.ChainHeaderReader, header *types.Header, state *state.StateDB, body *types.Body) {
FinalizeBlock(header, body.Transactions, state, chain.Config())
}

func (e Engine) FinalizeAndAssemble(chain consensus.ChainHeaderReader, header *types.Header, state *state.StateDB, txs []*types.Transaction,
uncles []*types.Header, receipts []*types.Receipt, withdrawals []*types.Withdrawal) (*types.Block, error) {
func (e Engine) FinalizeAndAssemble(chain consensus.ChainHeaderReader, header *types.Header, state *state.StateDB, body *types.Body, receipts []*types.Receipt) (*types.Block, error) {

e.Finalize(chain, header, state, txs, uncles, withdrawals)
e.Finalize(chain, header, state, body)

block := types.NewBlock(header, txs, nil, receipts, trie.NewStackTrie(nil))
block := types.NewBlock(header, body.Transactions, nil, receipts, trie.NewStackTrie(nil))
return block, nil
}

Expand Down
3 changes: 2 additions & 1 deletion arbos/l1pricing_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
package arbos

import (
"github.com/ethereum/go-ethereum/core/tracing"
"math/big"
"testing"

Expand Down Expand Up @@ -172,7 +173,7 @@ func _testL1PricingFundsDue(t *testing.T, testParams *l1PricingTest, expectedRes
// create some fake collection
balanceAdded := new(big.Int).SetUint64(testParams.fundsCollectedPerSecond * 3)
unitsAdded := testParams.unitsPerSecond * 3
evm.StateDB.AddBalance(l1pricing.L1PricerFundsPoolAddress, uint256.MustFromBig(balanceAdded))
evm.StateDB.AddBalance(l1pricing.L1PricerFundsPoolAddress, uint256.MustFromBig(balanceAdded), tracing.BalanceChangeUnspecified)
err = l1p.SetL1FeesAvailable(balanceAdded)
Require(t, err)
err = l1p.SetUnitsSinceUpdate(unitsAdded)
Expand Down
4 changes: 3 additions & 1 deletion arbos/programs/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,9 @@ func newApiClosures(
return memoryModel.GasCost(pages, open, ever)
}
captureHostio := func(name string, args, outs []byte, startInk, endInk uint64) {
tracingInfo.Tracer.CaptureStylusHostio(name, args, outs, startInk, endInk)
if tracingInfo.Tracer != nil && tracingInfo.Tracer.CaptureStylusHostio != nil {
tracingInfo.Tracer.CaptureStylusHostio(name, args, outs, startInk, endInk)
}
tracingInfo.CaptureEVMTraceForHostio(name, args, outs, startInk, endInk)
}

Expand Down
8 changes: 6 additions & 2 deletions arbos/tx_processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,13 +153,17 @@ func (p *TxProcessor) StartTxHook() (endTxNow bool, gasUsed uint64, err error, r
}
evm.IncrementDepth() // fake a call
from := p.msg.From
tracer.CaptureStart(evm, from, *p.msg.To, false, p.msg.Data, p.msg.GasLimit, p.msg.Value)
if tracer.OnEnter != nil {
tracer.OnEnter(evm.Depth(), byte(vm.CALL), from, *p.msg.To, p.msg.Data, p.msg.GasLimit, p.msg.Value)
}

tracingInfo = util.NewTracingInfo(evm, from, *p.msg.To, util.TracingDuringEVM)
p.state = arbosState.OpenSystemArbosStateOrPanic(evm.StateDB, tracingInfo, false)

return func() {
tracer.CaptureEnd(nil, p.state.Burner.Burned(), nil)
if tracer.OnExit != nil {
tracer.OnExit(evm.Depth(), nil, p.state.Burner.Burned(), nil, false)
}
evm.DecrementDepth() // fake the return to the first faked call

tracingInfo = util.NewTracingInfo(evm, from, *p.msg.To, util.TracingAfterEVM)
Expand Down
39 changes: 28 additions & 11 deletions arbos/util/tracing.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"math/big"

"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/tracing"
"github.com/ethereum/go-ethereum/core/vm"
"github.com/ethereum/go-ethereum/log"
"github.com/holiman/uint256"
Expand All @@ -22,7 +23,7 @@ const (
)

type TracingInfo struct {
Tracer vm.EVMLogger
Tracer *tracing.Hooks
Scenario TracingScenario
Contract *vm.Contract
Depth int
Expand Down Expand Up @@ -59,8 +60,10 @@ func (info *TracingInfo) RecordStorageGet(key common.Hash) {
Stack: TracingStackFromArgs(HashToUint256(key)),
Contract: info.Contract,
}
tracer.CaptureState(0, vm.SLOAD, 0, 0, scope, []byte{}, info.Depth, nil)
} else {
if tracer.OnOpcode != nil {
tracer.OnOpcode(0, byte(vm.SLOAD), 0, 0, scope, []byte{}, info.Depth, nil)
}
} else if tracer.CaptureArbitrumStorageGet != nil {
tracer.CaptureArbitrumStorageGet(key, info.Depth, info.Scenario == TracingBeforeEVM)
}
}
Expand All @@ -73,8 +76,10 @@ func (info *TracingInfo) RecordStorageSet(key, value common.Hash) {
Stack: TracingStackFromArgs(HashToUint256(key), HashToUint256(value)),
Contract: info.Contract,
}
tracer.CaptureState(0, vm.SSTORE, 0, 0, scope, []byte{}, info.Depth, nil)
} else {
if tracer.OnOpcode != nil {
tracer.OnOpcode(0, byte(vm.SSTORE), 0, 0, scope, []byte{}, info.Depth, nil)
}
} else if tracer.CaptureArbitrumStorageSet != nil {
tracer.CaptureArbitrumStorageSet(key, value, info.Depth, info.Scenario == TracingBeforeEVM)
}
}
Expand All @@ -98,8 +103,12 @@ func (info *TracingInfo) MockCall(input []byte, gas uint64, from, to common.Addr
),
Contract: contract,
}
tracer.CaptureState(0, vm.CALL, 0, 0, scope, []byte{}, depth, nil)
tracer.CaptureEnter(vm.INVALID, from, to, input, 0, amount)
if tracer.OnOpcode != nil {
tracer.OnOpcode(0, byte(vm.CALL), 0, 0, scope, []byte{}, depth, nil)
}
if tracer.OnEnter != nil {
tracer.OnEnter(depth, byte(vm.CALL), from, to, input, gas, amount)
}

retScope := &vm.ScopeContext{
Memory: vm.NewMemory(),
Expand All @@ -109,8 +118,12 @@ func (info *TracingInfo) MockCall(input []byte, gas uint64, from, to common.Addr
),
Contract: contract,
}
tracer.CaptureState(0, vm.RETURN, 0, 0, retScope, []byte{}, depth+1, nil)
tracer.CaptureExit(nil, 0, nil)
if tracer.OnOpcode != nil {
tracer.OnOpcode(0, byte(vm.RETURN), 0, 0, retScope, []byte{}, depth+1, nil)
}
if tracer.OnExit != nil {
tracer.OnExit(depth, nil, 0, nil, false)
}

popScope := &vm.ScopeContext{
Memory: vm.NewMemory(),
Expand All @@ -119,7 +132,9 @@ func (info *TracingInfo) MockCall(input []byte, gas uint64, from, to common.Addr
),
Contract: contract,
}
tracer.CaptureState(0, vm.POP, 0, 0, popScope, []byte{}, depth, nil)
if tracer.OnOpcode != nil {
tracer.OnOpcode(0, byte(vm.POP), 0, 0, popScope, []byte{}, depth, nil)
}
}

func (info *TracingInfo) CaptureEVMTraceForHostio(name string, args, outs []byte, startInk, endInk uint64) {
Expand Down Expand Up @@ -533,7 +548,9 @@ func (info *TracingInfo) captureState(op vm.OpCode, gas uint64, cost uint64, mem
Stack: TracingStackFromArgs(stack...),
Contract: info.Contract,
}
info.Tracer.CaptureState(0, op, gas, cost, scope, []byte{}, info.Depth, nil)
if info.Tracer.OnOpcode != nil {
info.Tracer.OnOpcode(0, byte(op), gas, cost, scope, []byte{}, info.Depth, nil)
}
}

func lenToBytes(data []byte) []byte {
Expand Down
60 changes: 32 additions & 28 deletions arbos/util/transfer.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"math/big"

"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/tracing"
"github.com/ethereum/go-ethereum/core/vm"
"github.com/ethereum/go-ethereum/log"
"github.com/holiman/uint256"
Expand All @@ -28,20 +29,6 @@ func TransferBalance(
if amount.Sign() < 0 {
panic(fmt.Sprintf("Tried to transfer negative amount %v from %v to %v", amount, from, to))
}
if from != nil {
balance := evm.StateDB.GetBalance(*from)
if arbmath.BigLessThan(balance.ToBig(), amount) {
return fmt.Errorf("%w: addr %v have %v want %v", vm.ErrInsufficientBalance, *from, balance, amount)
}
evm.StateDB.SubBalance(*from, uint256.MustFromBig(amount))
if evm.Context.ArbOSVersion >= 30 {
// ensure the from account is "touched" for EIP-161
evm.StateDB.AddBalance(*from, &uint256.Int{})
}
}
if to != nil {
evm.StateDB.AddBalance(*to, uint256.MustFromBig(amount))
}
if tracer := evm.Config.Tracer; tracer != nil {
if evm.Depth() != 0 && scenario != TracingDuringEVM {
// A non-zero depth implies this transfer is occurring inside EVM execution
Expand All @@ -50,24 +37,41 @@ func TransferBalance(
}

if scenario != TracingDuringEVM {
tracer.CaptureArbitrumTransfer(evm, from, to, amount, scenario == TracingBeforeEVM, purpose)
return nil
}
if tracer.CaptureArbitrumTransfer != nil {
tracer.CaptureArbitrumTransfer(from, to, amount, scenario == TracingBeforeEVM, purpose)
}
} else {
fromCopy := from
toCopy := to
if fromCopy == nil {
fromCopy = &common.Address{}
}
if toCopy == nil {
toCopy = &common.Address{}
}

if from == nil {
from = &common.Address{}
info := &TracingInfo{
Tracer: evm.Config.Tracer,
Scenario: scenario,
Contract: vm.NewContract(addressHolder{*toCopy}, addressHolder{*fromCopy}, uint256.NewInt(0), 0),
Depth: evm.Depth(),
}
info.MockCall([]byte{}, 0, *fromCopy, *toCopy, amount)
}
if to == nil {
to = &common.Address{}
}
if from != nil {
balance := evm.StateDB.GetBalance(*from)
if arbmath.BigLessThan(balance.ToBig(), amount) {
return fmt.Errorf("%w: addr %v have %v want %v", vm.ErrInsufficientBalance, *from, balance, amount)
}

info := &TracingInfo{
Tracer: evm.Config.Tracer,
Scenario: scenario,
Contract: vm.NewContract(addressHolder{*to}, addressHolder{*from}, uint256.NewInt(0), 0),
Depth: evm.Depth(),
evm.StateDB.SubBalance(*from, uint256.MustFromBig(amount), tracing.BalanceChangeTransfer)
if evm.Context.ArbOSVersion >= 30 {
// ensure the from account is "touched" for EIP-161
evm.StateDB.AddBalance(*from, &uint256.Int{}, tracing.BalanceChangeTransfer)
}
info.MockCall([]byte{}, 0, *from, *to, amount)
}
if to != nil {
evm.StateDB.AddBalance(*to, uint256.MustFromBig(amount), tracing.BalanceChangeTransfer)
}
return nil
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/genericconf/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ package genericconf
import (
"errors"
"io"
"log/slog"
"time"

"github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/node"
flag "github.com/spf13/pflag"
"golang.org/x/exp/slog"
)

type ConfConfig struct {
Expand Down
2 changes: 1 addition & 1 deletion cmd/genericconf/loglevel.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ package genericconf

import (
"errors"
"log/slog"
"strconv"
"strings"

"github.com/ethereum/go-ethereum/log"
"golang.org/x/exp/slog"
)

func ToSlogLevel(str string) (slog.Level, error) {
Expand Down
Loading

0 comments on commit 8e69f40

Please sign in to comment.