From cbdd00a421f76c1c6c3f1a10523902d8ecb65376 Mon Sep 17 00:00:00 2001 From: Rachel Franks Date: Mon, 1 Nov 2021 22:37:51 -0500 Subject: [PATCH 1/7] implement GetPoolNonce --- arbitrum/apibackend.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/arbitrum/apibackend.go b/arbitrum/apibackend.go index 35d6c7dac914..6fb1cb4e1444 100644 --- a/arbitrum/apibackend.go +++ b/arbitrum/apibackend.go @@ -216,7 +216,11 @@ func (a *APIBackend) GetPoolTransaction(txHash common.Hash) *types.Transaction { } func (a *APIBackend) GetPoolNonce(ctx context.Context, addr common.Address) (uint64, error) { - panic("not implemented") // TODO: Implement + stateDB, err := a.b.blockChain.State() + if err != nil { + return 0, err + } + return stateDB.GetNonce(addr), nil } func (a *APIBackend) Stats() (pending int, queued int) { From 273eafd258f56684480de3aac1b99b51d2bb0930 Mon Sep 17 00:00:00 2001 From: Rachel Franks Date: Mon, 1 Nov 2021 23:39:08 -0500 Subject: [PATCH 2/7] fix BlockByNumber --- arbitrum/apibackend.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/arbitrum/apibackend.go b/arbitrum/apibackend.go index 6fb1cb4e1444..27a0ef1daf95 100644 --- a/arbitrum/apibackend.go +++ b/arbitrum/apibackend.go @@ -129,6 +129,9 @@ func (a *APIBackend) CurrentBlock() *types.Block { } func (a *APIBackend) BlockByNumber(ctx context.Context, number rpc.BlockNumber) (*types.Block, error) { + if number == rpc.LatestBlockNumber || number == rpc.PendingBlockNumber { + return a.b.blockChain.CurrentBlock(), nil + } return a.b.blockChain.GetBlockByNumber(uint64(number.Int64())), nil } From 2b15dbe60204b781d24e29e41d97191a2b3f7fea Mon Sep 17 00:00:00 2001 From: Rachel Franks Date: Tue, 2 Nov 2021 22:44:33 -0500 Subject: [PATCH 3/7] Implement GetLogs --- arbitrum/apibackend.go | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/arbitrum/apibackend.go b/arbitrum/apibackend.go index 3282eef5617d..0ceb1fa63825 100644 --- a/arbitrum/apibackend.go +++ b/arbitrum/apibackend.go @@ -248,11 +248,19 @@ func (a *APIBackend) SubscribeNewTxsEvent(ch chan<- core.NewTxsEvent) event.Subs // Filter API func (a *APIBackend) BloomStatus() (uint64, uint64) { - panic("not implemented") // TODO: Implement + return params.BloomBitsBlocks, 0 // TODO: Implement second return value } func (a *APIBackend) GetLogs(ctx context.Context, blockHash common.Hash) ([][]*types.Log, error) { - panic("not implemented") // TODO: Implement + receipts := a.blockChain().GetReceiptsByHash(blockHash) + if receipts == nil { + return nil, nil + } + logs := make([][]*types.Log, len(receipts)) + for i, receipt := range receipts { + logs[i] = receipt.Logs + } + return logs, nil } func (a *APIBackend) ServiceFilter(ctx context.Context, session *bloombits.MatcherSession) { From 537d17b41c1a4a0cc2dba9f389d890974c0b96b2 Mon Sep 17 00:00:00 2001 From: Ed Felten Date: Wed, 3 Nov 2021 09:54:24 -0400 Subject: [PATCH 4/7] Make EVM depth visible --- core/vm/evm.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/core/vm/evm.go b/core/vm/evm.go index 57ccdc0db92a..8a7d66d9dbc0 100644 --- a/core/vm/evm.go +++ b/core/vm/evm.go @@ -158,6 +158,11 @@ func (evm *EVM) Cancelled() bool { return atomic.LoadInt32(&evm.abort) == 1 } +// Depth returns the current depth +func (evm *EVM) Depth() int { + return evm.depth +} + // Interpreter returns the current interpreter func (evm *EVM) Interpreter() *EVMInterpreter { return evm.interpreter From 0a65cad780cda3a95a8204d82651c54542d87b88 Mon Sep 17 00:00:00 2001 From: Rachel Franks Date: Wed, 3 Nov 2021 11:17:49 -0500 Subject: [PATCH 5/7] move changes to new file --- core/vm/evm.go | 5 ----- core/vm/evm_arbitrum.go | 22 ++++++++++++++++++++++ 2 files changed, 22 insertions(+), 5 deletions(-) create mode 100644 core/vm/evm_arbitrum.go diff --git a/core/vm/evm.go b/core/vm/evm.go index 8a7d66d9dbc0..57ccdc0db92a 100644 --- a/core/vm/evm.go +++ b/core/vm/evm.go @@ -158,11 +158,6 @@ func (evm *EVM) Cancelled() bool { return atomic.LoadInt32(&evm.abort) == 1 } -// Depth returns the current depth -func (evm *EVM) Depth() int { - return evm.depth -} - // Interpreter returns the current interpreter func (evm *EVM) Interpreter() *EVMInterpreter { return evm.interpreter diff --git a/core/vm/evm_arbitrum.go b/core/vm/evm_arbitrum.go new file mode 100644 index 000000000000..d3a2cc5448f0 --- /dev/null +++ b/core/vm/evm_arbitrum.go @@ -0,0 +1,22 @@ +// Copyright 2014 The go-ethereum Authors +// This file is part of the go-ethereum library. +// +// The go-ethereum library is free software: you can redistribute it and/or modify +// it under the terms of the GNU Lesser General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// The go-ethereum library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public License +// along with the go-ethereum library. If not, see . + +package vm + +// Depth returns the current depth +func (evm *EVM) Depth() int { + return evm.depth +} From b0e7e9b7f1ecf0e8241ff64fea11dc73be91fdc0 Mon Sep 17 00:00:00 2001 From: Ed Felten Date: Wed, 3 Nov 2021 15:42:03 -0400 Subject: [PATCH 6/7] Add OriginWasRemapped field to TxContext --- core/evm.go | 9 +++++++++ core/vm/evm.go | 1 + 2 files changed, 10 insertions(+) diff --git a/core/evm.go b/core/evm.go index 6c67fc43762c..bbead8f9bec2 100644 --- a/core/evm.go +++ b/core/evm.go @@ -72,6 +72,15 @@ func NewEVMTxContext(msg Message) vm.TxContext { } } +// NewEVMTxContextWithRemapInfo creates a new transaction context for a single transaction. +func NewEVMTxContextWithRemapInfo(msg Message, originWasRemapped bool) vm.TxContext { + return vm.TxContext{ + Origin: msg.From(), + GasPrice: new(big.Int).Set(msg.GasPrice()), + OriginWasRemapped: originWasRemapped, + } +} + // GetHashFn returns a GetHashFunc which retrieves header hashes by number func GetHashFn(ref *types.Header, chain ChainContext) func(n uint64) common.Hash { // Cache will initially contain [refHash.parent], diff --git a/core/vm/evm.go b/core/vm/evm.go index 57ccdc0db92a..9cb073ee84fb 100644 --- a/core/vm/evm.go +++ b/core/vm/evm.go @@ -86,6 +86,7 @@ type TxContext struct { // Message information Origin common.Address // Provides information for ORIGIN GasPrice *big.Int // Provides information for GASPRICE + OriginWasRemapped bool // Arbitrum addition, provides information for ArbSys precopmile } // EVM is the Ethereum Virtual Machine base object and provides From f81705d618333dc08ee1a8e9636636da79b60b09 Mon Sep 17 00:00:00 2001 From: Ed Felten Date: Wed, 3 Nov 2021 16:05:55 -0400 Subject: [PATCH 7/7] Add OriginWasRemapped to TxContext --- accounts/abi/bind/backends/simulated.go | 1 + core/evm.go | 12 +++++------- core/state_transition.go | 1 + 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/accounts/abi/bind/backends/simulated.go b/accounts/abi/bind/backends/simulated.go index e410522ac8bf..1d9b0e2104fe 100644 --- a/accounts/abi/bind/backends/simulated.go +++ b/accounts/abi/bind/backends/simulated.go @@ -793,6 +793,7 @@ type callMsg struct { ethereum.CallMsg } +func (m callMsg) UnderlyingTransaction() *types.Transaction { return nil } func (m callMsg) From() common.Address { return m.CallMsg.From } func (m callMsg) Nonce() uint64 { return 0 } func (m callMsg) IsFake() bool { return true } diff --git a/core/evm.go b/core/evm.go index bbead8f9bec2..23e2e4eedd3f 100644 --- a/core/evm.go +++ b/core/evm.go @@ -66,14 +66,12 @@ func NewEVMBlockContext(header *types.Header, chain ChainContext, author *common // NewEVMTxContext creates a new transaction context for a single transaction. func NewEVMTxContext(msg Message) vm.TxContext { - return vm.TxContext{ - Origin: msg.From(), - GasPrice: new(big.Int).Set(msg.GasPrice()), + originWasRemapped := false + tx := msg.UnderlyingTransaction() + if tx != nil { + txType := tx.Type() + originWasRemapped = txType == types.ArbitrumUnsignedTxType || txType == types.ArbitrumContractTxType } -} - -// NewEVMTxContextWithRemapInfo creates a new transaction context for a single transaction. -func NewEVMTxContextWithRemapInfo(msg Message, originWasRemapped bool) vm.TxContext { return vm.TxContext{ Origin: msg.From(), GasPrice: new(big.Int).Set(msg.GasPrice()), diff --git a/core/state_transition.go b/core/state_transition.go index 72a41e18f6f4..f8e5fe2d69ef 100644 --- a/core/state_transition.go +++ b/core/state_transition.go @@ -73,6 +73,7 @@ type StateTransition struct { // Message represents a message sent to a contract. type Message interface { + UnderlyingTransaction() *types.Transaction From() common.Address To() *common.Address