Commit 2e00002a authored by Kelvin Fichter's avatar Kelvin Fichter Committed by Kelvin Fichter

refactor: update OVM_ETH usage

parent 3605b963
...@@ -12,8 +12,7 @@ import { IS_LIVE_NETWORK } from './shared/utils' ...@@ -12,8 +12,7 @@ import { IS_LIVE_NETWORK } from './shared/utils'
import { OptimismEnv } from './shared/env' import { OptimismEnv } from './shared/env'
import { Direction } from './shared/watcher-utils' import { Direction } from './shared/watcher-utils'
// SKIP: ETH value PR describe('Fee Payment Integration Tests', async () => {
describe.skip('Fee Payment Integration Tests', async () => {
let env: OptimismEnv let env: OptimismEnv
before(async () => { before(async () => {
env = await OptimismEnv.new() env = await OptimismEnv.new()
......
...@@ -13,8 +13,7 @@ import { Interface } from 'ethers/lib/utils' ...@@ -13,8 +13,7 @@ import { Interface } from 'ethers/lib/utils'
chai.use(solidity) chai.use(solidity)
// SKIP: ETH value PR describe('Native ETH value integration tests', () => {
describe.skip('Native ETH value integration tests', () => {
let env: OptimismEnv let env: OptimismEnv
let wallet: Wallet let wallet: Wallet
let other: Wallet let other: Wallet
...@@ -332,7 +331,7 @@ describe.skip('Native ETH value integration tests', () => { ...@@ -332,7 +331,7 @@ describe.skip('Native ETH value integration tests', () => {
// Grab public variable from the EM // Grab public variable from the EM
const OVM_ExecutionManager = new Contract( const OVM_ExecutionManager = new Contract(
await env.addressManager.getAddress('OVM_ExecutionManager'), await env.addressManager.getAddress('OVM_ExecutionManager'),
getContractInterface('OVM_ExecutionManager', false), getContractInterface('OVM_ExecutionManager'),
env.l1Wallet.provider env.l1Wallet.provider
) )
const CALL_WITH_VALUE_INTRINSIC_GAS_BIGNUM = const CALL_WITH_VALUE_INTRINSIC_GAS_BIGNUM =
......
...@@ -19,8 +19,7 @@ const DEFAULT_TEST_GAS_L2 = 1_300_000 ...@@ -19,8 +19,7 @@ const DEFAULT_TEST_GAS_L2 = 1_300_000
// TX size enforced by CTC: // TX size enforced by CTC:
const MAX_ROLLUP_TX_SIZE = 50_000 const MAX_ROLLUP_TX_SIZE = 50_000
// SKIP: ETH value PR describe('Native ETH Integration Tests', async () => {
describe.skip('Native ETH Integration Tests', async () => {
let env: OptimismEnv let env: OptimismEnv
let l1Bob: Wallet let l1Bob: Wallet
let l2Bob: Wallet let l2Bob: Wallet
...@@ -345,21 +344,14 @@ describe.skip('Native ETH Integration Tests', async () => { ...@@ -345,21 +344,14 @@ describe.skip('Native ETH Integration Tests', async () => {
expect( expect(
await env.l2Wallet.provider.getBalance(env.l2Wallet.address) await env.l2Wallet.provider.getBalance(env.l2Wallet.address)
).to.equal(initialBalance) ).to.equal(initialBalance)
expect(receipt.events.length).to.equal(4) expect(receipt.events.length).to.equal(2)
// The first transfer event is fee payment
const [, firstTransferEvent, secondTransferEvent, depositEvent] =
receipt.events
expect(firstTransferEvent.event).to.equal('Transfer') const [transferEvent, depositEvent] = receipt.events
expect(firstTransferEvent.args.from).to.equal(env.l2Wallet.address)
expect(firstTransferEvent.args.to).to.equal(env.ovmEth.address)
expect(firstTransferEvent.args.value).to.equal(value)
expect(secondTransferEvent.event).to.equal('Transfer') expect(transferEvent.event).to.equal('Transfer')
expect(secondTransferEvent.args.from).to.equal(env.ovmEth.address) expect(transferEvent.args.from).to.equal(env.ovmEth.address)
expect(secondTransferEvent.args.to).to.equal(env.l2Wallet.address) expect(transferEvent.args.to).to.equal(env.l2Wallet.address)
expect(secondTransferEvent.args.value).to.equal(value) expect(transferEvent.args.value).to.equal(value)
expect(depositEvent.event).to.equal('Deposit') expect(depositEvent.event).to.equal('Deposit')
expect(depositEvent.args.dst).to.equal(env.l2Wallet.address) expect(depositEvent.args.dst).to.equal(env.l2Wallet.address)
...@@ -385,10 +377,9 @@ describe.skip('Native ETH Integration Tests', async () => { ...@@ -385,10 +377,9 @@ describe.skip('Native ETH Integration Tests', async () => {
expect( expect(
await env.l2Wallet.provider.getBalance(env.l2Wallet.address) await env.l2Wallet.provider.getBalance(env.l2Wallet.address)
).to.equal(initialBalance) ).to.equal(initialBalance)
expect(receipt.events.length).to.equal(2) expect(receipt.events.length).to.equal(1)
// The first transfer event is fee payment const depositEvent = receipt.events[0]
const depositEvent = receipt.events[1]
expect(depositEvent.event).to.equal('Withdrawal') expect(depositEvent.event).to.equal('Withdrawal')
expect(depositEvent.args.src).to.equal(env.l2Wallet.address) expect(depositEvent.args.src).to.equal(env.l2Wallet.address)
expect(depositEvent.args.wad).to.equal(value) expect(depositEvent.args.wad).to.equal(value)
......
...@@ -94,8 +94,7 @@ describe('Basic RPC tests', () => { ...@@ -94,8 +94,7 @@ describe('Basic RPC tests', () => {
).to.be.rejectedWith('Cannot submit unprotected transaction') ).to.be.rejectedWith('Cannot submit unprotected transaction')
}) })
// SKIP: needs ETH value PR it('should accept a transaction with a value', async () => {
it.skip('should accept a transaction with a value', async () => {
const tx = { const tx = {
...DEFAULT_TRANSACTION, ...DEFAULT_TRANSACTION,
chainId: await env.l2Wallet.getChainId(), chainId: await env.l2Wallet.getChainId(),
...@@ -113,8 +112,7 @@ describe('Basic RPC tests', () => { ...@@ -113,8 +112,7 @@ describe('Basic RPC tests', () => {
) )
}) })
// SKIP: needs ETH value PR it('should reject a transaction with higher value than user balance', async () => {
it.skip('should reject a transaction with higher value than user balance', async () => {
const balance = await env.l2Wallet.getBalance() const balance = await env.l2Wallet.getBalance()
const tx = { const tx = {
...DEFAULT_TRANSACTION, ...DEFAULT_TRANSACTION,
...@@ -170,8 +168,7 @@ describe('Basic RPC tests', () => { ...@@ -170,8 +168,7 @@ describe('Basic RPC tests', () => {
).to.be.rejectedWith('out of gas') ).to.be.rejectedWith('out of gas')
}) })
// SKIP: needs ETH value PR it('should allow eth_calls with nonzero value', async () => {
it.skip('should allow eth_calls with nonzero value', async () => {
// Deploy a contract to check msg.value of the call // Deploy a contract to check msg.value of the call
const Factory__ValueContext: ContractFactory = const Factory__ValueContext: ContractFactory =
await ethers.getContractFactory('ValueContext', wallet) await ethers.getContractFactory('ValueContext', wallet)
...@@ -315,8 +312,7 @@ describe('Basic RPC tests', () => { ...@@ -315,8 +312,7 @@ describe('Basic RPC tests', () => {
}) })
describe('eth_getBalance', () => { describe('eth_getBalance', () => {
// SKIP: needs ETH value PR it('should get the OVM_ETH balance', async () => {
it.skip('should get the OVM_ETH balance', async () => {
const rpcBalance = await provider.getBalance(env.l2Wallet.address) const rpcBalance = await provider.getBalance(env.l2Wallet.address)
const contractBalance = await env.ovmEth.balanceOf(env.l2Wallet.address) const contractBalance = await env.ovmEth.balanceOf(env.l2Wallet.address)
expect(rpcBalance).to.be.deep.eq(contractBalance) expect(rpcBalance).to.be.deep.eq(contractBalance)
......
...@@ -71,8 +71,7 @@ export class OptimismEnv { ...@@ -71,8 +71,7 @@ export class OptimismEnv {
// fund the user if needed // fund the user if needed
const balance = await l2Wallet.getBalance() const balance = await l2Wallet.getBalance()
if (balance.isZero()) { if (balance.isZero()) {
// TEMPORARILY SKIP UNTIL MESSAGE PASSING WORKS await fundUser(watcher, l1Bridge, utils.parseEther('20'))
//await fundUser(watcher, l1Bridge, utils.parseEther('20'))
} }
const l1Messenger = getContractFactory('iOVM_L1CrossDomainMessenger') const l1Messenger = getContractFactory('iOVM_L1CrossDomainMessenger')
.connect(l1Wallet) .connect(l1Wallet)
......
...@@ -47,8 +47,7 @@ describe('stress tests', () => { ...@@ -47,8 +47,7 @@ describe('stress tests', () => {
await L2SimpleStorage.deployTransaction.wait() await L2SimpleStorage.deployTransaction.wait()
}) })
// SKIP: needs message passing PR describe('L1 => L2 stress tests', () => {
describe.skip('L1 => L2 stress tests', () => {
const numTransactions = 10 const numTransactions = 10
it(`${numTransactions} L1 => L2 transactions (serial)`, async () => { it(`${numTransactions} L1 => L2 transactions (serial)`, async () => {
...@@ -84,8 +83,7 @@ describe('stress tests', () => { ...@@ -84,8 +83,7 @@ describe('stress tests', () => {
}).timeout(STRESS_TEST_TIMEOUT) }).timeout(STRESS_TEST_TIMEOUT)
}) })
// SKIP: needs message passing PR describe('L2 => L1 stress tests', () => {
describe.skip('L2 => L1 stress tests', () => {
const numTransactions = 10 const numTransactions = 10
it(`${numTransactions} L2 => L1 transactions (serial)`, async () => { it(`${numTransactions} L2 => L1 transactions (serial)`, async () => {
......
This diff is collapsed.
...@@ -37,10 +37,10 @@ import ( ...@@ -37,10 +37,10 @@ import (
"github.com/ethereum/go-ethereum/accounts" "github.com/ethereum/go-ethereum/accounts"
"github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/core/vm"
"github.com/ethereum/go-ethereum/crypto" "github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/event" "github.com/ethereum/go-ethereum/event"
"github.com/ethereum/go-ethereum/log" "github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/rollup/rcfg"
) )
var ( var (
...@@ -83,7 +83,7 @@ func NewKeyStore(keydir string, scryptN, scryptP int) *KeyStore { ...@@ -83,7 +83,7 @@ func NewKeyStore(keydir string, scryptN, scryptP int) *KeyStore {
keydir, _ = filepath.Abs(keydir) keydir, _ = filepath.Abs(keydir)
ks := &KeyStore{storage: &keyStorePassphrase{keydir, scryptN, scryptP, false}} ks := &KeyStore{storage: &keyStorePassphrase{keydir, scryptN, scryptP, false}}
ks.init(keydir) ks.init(keydir)
if vm.UsingOVM { if rcfg.UsingOVM {
// Add a deterministic key to the key store so that // Add a deterministic key to the key store so that
// all clique blocks are signed with the same key. // all clique blocks are signed with the same key.
// This change will result in deterministic blocks across // This change will result in deterministic blocks across
......
...@@ -33,12 +33,12 @@ import ( ...@@ -33,12 +33,12 @@ import (
"github.com/ethereum/go-ethereum/consensus/misc" "github.com/ethereum/go-ethereum/consensus/misc"
"github.com/ethereum/go-ethereum/core/state" "github.com/ethereum/go-ethereum/core/state"
"github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/core/vm"
"github.com/ethereum/go-ethereum/crypto" "github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/ethdb" "github.com/ethereum/go-ethereum/ethdb"
"github.com/ethereum/go-ethereum/log" "github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/params" "github.com/ethereum/go-ethereum/params"
"github.com/ethereum/go-ethereum/rlp" "github.com/ethereum/go-ethereum/rlp"
"github.com/ethereum/go-ethereum/rollup/rcfg"
"github.com/ethereum/go-ethereum/rpc" "github.com/ethereum/go-ethereum/rpc"
lru "github.com/hashicorp/golang-lru" lru "github.com/hashicorp/golang-lru"
"golang.org/x/crypto/sha3" "golang.org/x/crypto/sha3"
...@@ -249,7 +249,7 @@ func (c *Clique) verifyHeader(chain consensus.ChainReader, header *types.Header, ...@@ -249,7 +249,7 @@ func (c *Clique) verifyHeader(chain consensus.ChainReader, header *types.Header,
} }
number := header.Number.Uint64() number := header.Number.Uint64()
if !vm.UsingOVM { if !rcfg.UsingOVM {
// Don't waste time checking blocks from the future // Don't waste time checking blocks from the future
if header.Time > uint64(time.Now().Unix()) { if header.Time > uint64(time.Now().Unix()) {
return consensus.ErrFutureBlock return consensus.ErrFutureBlock
...@@ -328,7 +328,7 @@ func (c *Clique) verifyCascadingFields(chain consensus.ChainReader, header *type ...@@ -328,7 +328,7 @@ func (c *Clique) verifyCascadingFields(chain consensus.ChainReader, header *type
// Do not account for timestamps in consensus when running the OVM // Do not account for timestamps in consensus when running the OVM
// changes. The timestamp must be montonic, meaning that it can be the same // changes. The timestamp must be montonic, meaning that it can be the same
// or increase. L1 dictates the timestamp. // or increase. L1 dictates the timestamp.
if !vm.UsingOVM { if !rcfg.UsingOVM {
if parent.Time+c.config.Period > header.Time { if parent.Time+c.config.Period > header.Time {
return ErrInvalidTimestamp return ErrInvalidTimestamp
} }
...@@ -555,7 +555,7 @@ func (c *Clique) Prepare(chain consensus.ChainReader, header *types.Header) erro ...@@ -555,7 +555,7 @@ func (c *Clique) Prepare(chain consensus.ChainReader, header *types.Header) erro
} }
// Do not manipulate the timestamps when running with the OVM // Do not manipulate the timestamps when running with the OVM
if !vm.UsingOVM { if !rcfg.UsingOVM {
header.Time = parent.Time + c.config.Period header.Time = parent.Time + c.config.Period
if header.Time < uint64(time.Now().Unix()) { if header.Time < uint64(time.Now().Unix()) {
header.Time = uint64(time.Now().Unix()) header.Time = uint64(time.Now().Unix())
...@@ -640,7 +640,10 @@ func (c *Clique) Seal(chain consensus.ChainReader, block *types.Block, results c ...@@ -640,7 +640,10 @@ func (c *Clique) Seal(chain consensus.ChainReader, block *types.Block, results c
log.Trace("Out-of-turn signing requested", "wiggle", common.PrettyDuration(wiggle)) log.Trace("Out-of-turn signing requested", "wiggle", common.PrettyDuration(wiggle))
} }
if vm.UsingOVM { // Set the delay to 0 when using the OVM so that blocks are always
// produced instantly. When running in a non-OVM network, the delay prevents
// the creation of invalid blocks.
if rcfg.UsingOVM {
delay = 0 delay = 0
} }
// Sign all the things! // Sign all the things!
......
...@@ -23,6 +23,7 @@ import ( ...@@ -23,6 +23,7 @@ import (
"github.com/ethereum/go-ethereum/consensus" "github.com/ethereum/go-ethereum/consensus"
"github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/core/vm" "github.com/ethereum/go-ethereum/core/vm"
"github.com/ethereum/go-ethereum/rollup/rcfg"
) )
// DefaultL1MessageSender is the default L1MessageSender value attached to a transaction that is // DefaultL1MessageSender is the default L1MessageSender value attached to a transaction that is
...@@ -48,7 +49,7 @@ func NewEVMContext(msg Message, header *types.Header, chain ChainContext, author ...@@ -48,7 +49,7 @@ func NewEVMContext(msg Message, header *types.Header, chain ChainContext, author
} else { } else {
beneficiary = *author beneficiary = *author
} }
if vm.UsingOVM { if rcfg.UsingOVM {
// When using the OVM, we must: // When using the OVM, we must:
// (1) Attach the L1MessageSender context value and // (1) Attach the L1MessageSender context value and
// (2) Set the BlockNumber to be the msg.L1BlockNumber // (2) Set the BlockNumber to be the msg.L1BlockNumber
......
...@@ -34,13 +34,13 @@ import ( ...@@ -34,13 +34,13 @@ import (
"github.com/ethereum/go-ethereum/core/rawdb" "github.com/ethereum/go-ethereum/core/rawdb"
"github.com/ethereum/go-ethereum/core/state" "github.com/ethereum/go-ethereum/core/state"
"github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/core/vm"
"github.com/ethereum/go-ethereum/crypto" "github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/ethdb" "github.com/ethereum/go-ethereum/ethdb"
"github.com/ethereum/go-ethereum/log" "github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/params" "github.com/ethereum/go-ethereum/params"
"github.com/ethereum/go-ethereum/rlp" "github.com/ethereum/go-ethereum/rlp"
"github.com/ethereum/go-ethereum/rollup/dump" "github.com/ethereum/go-ethereum/rollup/dump"
"github.com/ethereum/go-ethereum/rollup/rcfg"
) )
//go:generate gencodec -type Genesis -field-override genesisSpecMarshaling -out gen_genesis.go //go:generate gencodec -type Genesis -field-override genesisSpecMarshaling -out gen_genesis.go
...@@ -352,8 +352,9 @@ func (g *Genesis) ToBlock(db ethdb.Database) *types.Block { ...@@ -352,8 +352,9 @@ func (g *Genesis) ToBlock(db ethdb.Database) *types.Block {
} }
statedb, _ := state.New(common.Hash{}, state.NewDatabase(db)) statedb, _ := state.New(common.Hash{}, state.NewDatabase(db))
if vm.UsingOVM { // Apply the OVM genesis state, including setting storage dynamically
// OVM_ENABLED // in particular system contracts.
if rcfg.UsingOVM {
ApplyOvmStateToState(statedb, g.Config.StateDump, g.L1CrossDomainMessengerAddress, g.L1StandardBridgeAddress, g.AddressManagerOwnerAddress, g.GasPriceOracleOwnerAddress, g.L1FeeWalletAddress, g.ChainID, g.GasLimit) ApplyOvmStateToState(statedb, g.Config.StateDump, g.L1CrossDomainMessengerAddress, g.L1StandardBridgeAddress, g.AddressManagerOwnerAddress, g.GasPriceOracleOwnerAddress, g.L1FeeWalletAddress, g.ChainID, g.GasLimit)
} }
...@@ -495,7 +496,7 @@ func DeveloperGenesisBlock(period uint64, faucet, l1XDomainMessengerAddress comm ...@@ -495,7 +496,7 @@ func DeveloperGenesisBlock(period uint64, faucet, l1XDomainMessengerAddress comm
} }
stateDump := dump.OvmDump{} stateDump := dump.OvmDump{}
if vm.UsingOVM { if rcfg.UsingOVM {
// Fetch the state dump from the state dump path // Fetch the state dump from the state dump path
// The system cannot start without a state dump as it depends on // The system cannot start without a state dump as it depends on
// the ABIs that are included in the state dump. Check that all // the ABIs that are included in the state dump. Check that all
......
...@@ -30,7 +30,10 @@ import ( ...@@ -30,7 +30,10 @@ import (
"github.com/ethereum/go-ethereum/log" "github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/metrics" "github.com/ethereum/go-ethereum/metrics"
"github.com/ethereum/go-ethereum/rlp" "github.com/ethereum/go-ethereum/rlp"
"github.com/ethereum/go-ethereum/rollup/dump"
"github.com/ethereum/go-ethereum/rollup/rcfg"
"github.com/ethereum/go-ethereum/trie" "github.com/ethereum/go-ethereum/trie"
"golang.org/x/crypto/sha3"
) )
type revision struct { type revision struct {
...@@ -57,6 +60,15 @@ func (n *proofList) Delete(key []byte) error { ...@@ -57,6 +60,15 @@ func (n *proofList) Delete(key []byte) error {
panic("not supported") panic("not supported")
} }
func GetOVMBalanceKey(addr common.Address) common.Hash {
position := common.Big0
hasher := sha3.NewLegacyKeccak256()
hasher.Write(common.LeftPadBytes(addr.Bytes(), 32))
hasher.Write(common.LeftPadBytes(position.Bytes(), 32))
digest := hasher.Sum(nil)
return common.BytesToHash(digest)
}
// StateDBs within the ethereum protocol are used to store anything // StateDBs within the ethereum protocol are used to store anything
// within the merkle trie. StateDBs take care of caching and storing // within the merkle trie. StateDBs take care of caching and storing
// nested states. It's the general query interface to retrieve: // nested states. It's the general query interface to retrieve:
...@@ -224,11 +236,19 @@ func (s *StateDB) Empty(addr common.Address) bool { ...@@ -224,11 +236,19 @@ func (s *StateDB) Empty(addr common.Address) bool {
// Retrieve the balance from the given address or 0 if object not found // Retrieve the balance from the given address or 0 if object not found
func (s *StateDB) GetBalance(addr common.Address) *big.Int { func (s *StateDB) GetBalance(addr common.Address) *big.Int {
stateObject := s.getStateObject(addr) if rcfg.UsingOVM {
if stateObject != nil { // Get balance from the OVM_ETH contract.
return stateObject.Balance() // NOTE: We may remove this feature in a future release.
key := GetOVMBalanceKey(addr)
bal := s.GetState(dump.OvmEthAddress, key)
return bal.Big()
} else {
stateObject := s.getStateObject(addr)
if stateObject != nil {
return stateObject.Balance()
}
return common.Big0
} }
return common.Big0
} }
func (s *StateDB) GetNonce(addr common.Address) uint64 { func (s *StateDB) GetNonce(addr common.Address) uint64 {
...@@ -347,24 +367,54 @@ func (s *StateDB) HasSuicided(addr common.Address) bool { ...@@ -347,24 +367,54 @@ func (s *StateDB) HasSuicided(addr common.Address) bool {
// AddBalance adds amount to the account associated with addr. // AddBalance adds amount to the account associated with addr.
func (s *StateDB) AddBalance(addr common.Address, amount *big.Int) { func (s *StateDB) AddBalance(addr common.Address, amount *big.Int) {
stateObject := s.GetOrNewStateObject(addr) if rcfg.UsingOVM {
if stateObject != nil { // Mutate the storage slot inside of OVM_ETH to change balances.
stateObject.AddBalance(amount) // Note that we don't need to check for overflows or underflows here because the code that
// uses this codepath already checks for them. You can follow the original codepath below
// (stateObject.AddBalance) to confirm that there are no checks being performed here.
key := GetOVMBalanceKey(addr)
value := s.GetState(dump.OvmEthAddress, key)
bal := value.Big()
bal = bal.Add(bal, amount)
s.SetState(dump.OvmEthAddress, key, common.BigToHash(bal))
} else {
stateObject := s.GetOrNewStateObject(addr)
if stateObject != nil {
stateObject.AddBalance(amount)
}
} }
} }
// SubBalance subtracts amount from the account associated with addr. // SubBalance subtracts amount from the account associated with addr.
func (s *StateDB) SubBalance(addr common.Address, amount *big.Int) { func (s *StateDB) SubBalance(addr common.Address, amount *big.Int) {
stateObject := s.GetOrNewStateObject(addr) if rcfg.UsingOVM {
if stateObject != nil { // Mutate the storage slot inside of OVM_ETH to change balances.
stateObject.SubBalance(amount) // Note that we don't need to check for overflows or underflows here because the code that
// uses this codepath already checks for them. You can follow the original codepath below
// (stateObject.SubBalance) to confirm that there are no checks being performed here.
key := GetOVMBalanceKey(addr)
value := s.GetState(dump.OvmEthAddress, key)
bal := value.Big()
bal = bal.Sub(bal, amount)
s.SetState(dump.OvmEthAddress, key, common.BigToHash(bal))
} else {
stateObject := s.GetOrNewStateObject(addr)
if stateObject != nil {
stateObject.SubBalance(amount)
}
} }
} }
func (s *StateDB) SetBalance(addr common.Address, amount *big.Int) { func (s *StateDB) SetBalance(addr common.Address, amount *big.Int) {
stateObject := s.GetOrNewStateObject(addr) if rcfg.UsingOVM {
if stateObject != nil { // Mutate the storage slot inside of OVM_ETH to change balances.
stateObject.SetBalance(amount) key := GetOVMBalanceKey(addr)
s.SetState(dump.OvmEthAddress, key, common.BigToHash(amount))
} else {
stateObject := s.GetOrNewStateObject(addr)
if stateObject != nil {
stateObject.SetBalance(amount)
}
} }
} }
......
...@@ -25,6 +25,7 @@ import ( ...@@ -25,6 +25,7 @@ import (
"github.com/ethereum/go-ethereum/core/vm" "github.com/ethereum/go-ethereum/core/vm"
"github.com/ethereum/go-ethereum/crypto" "github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/params" "github.com/ethereum/go-ethereum/params"
"github.com/ethereum/go-ethereum/rollup/rcfg"
) )
// StateProcessor is a basic Processor, which takes care of transitioning // StateProcessor is a basic Processor, which takes care of transitioning
...@@ -87,7 +88,7 @@ func (p *StateProcessor) Process(block *types.Block, statedb *state.StateDB, cfg ...@@ -87,7 +88,7 @@ func (p *StateProcessor) Process(block *types.Block, statedb *state.StateDB, cfg
// indicating the block was invalid. // indicating the block was invalid.
func ApplyTransaction(config *params.ChainConfig, bc ChainContext, author *common.Address, gp *GasPool, statedb *state.StateDB, header *types.Header, tx *types.Transaction, usedGas *uint64, cfg vm.Config) (*types.Receipt, error) { func ApplyTransaction(config *params.ChainConfig, bc ChainContext, author *common.Address, gp *GasPool, statedb *state.StateDB, header *types.Header, tx *types.Transaction, usedGas *uint64, cfg vm.Config) (*types.Receipt, error) {
msg, err := tx.AsMessage(types.MakeSigner(config, header.Number)) msg, err := tx.AsMessage(types.MakeSigner(config, header.Number))
if vm.UsingOVM { if rcfg.UsingOVM {
if err != nil { if err != nil {
// This should only be allowed to pass if the transaction is in the ctc // This should only be allowed to pass if the transaction is in the ctc
// already. The presence of `Index` should specify this. // already. The presence of `Index` should specify this.
......
...@@ -27,6 +27,7 @@ import ( ...@@ -27,6 +27,7 @@ import (
"github.com/ethereum/go-ethereum/core/vm" "github.com/ethereum/go-ethereum/core/vm"
"github.com/ethereum/go-ethereum/log" "github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/params" "github.com/ethereum/go-ethereum/params"
"github.com/ethereum/go-ethereum/rollup/rcfg"
) )
var ( var (
...@@ -180,10 +181,8 @@ func (st *StateTransition) preCheck() error { ...@@ -180,10 +181,8 @@ func (st *StateTransition) preCheck() error {
if st.msg.CheckNonce() { if st.msg.CheckNonce() {
nonce := st.state.GetNonce(st.msg.From()) nonce := st.state.GetNonce(st.msg.From())
if nonce < st.msg.Nonce() { if nonce < st.msg.Nonce() {
// Skip the nonce check for L1 to L2 transactions. They do not if rcfg.UsingOVM {
// increment a nonce in the state and they also ecrecover to // The nonce never increments for L1ToL2 txs
// `address(0)`
if vm.UsingOVM {
if st.msg.QueueOrigin() == types.QueueOriginL1ToL2 { if st.msg.QueueOrigin() == types.QueueOriginL1ToL2 {
return st.buyGas() return st.buyGas()
} }
......
...@@ -29,11 +29,11 @@ import ( ...@@ -29,11 +29,11 @@ import (
"github.com/ethereum/go-ethereum/common/prque" "github.com/ethereum/go-ethereum/common/prque"
"github.com/ethereum/go-ethereum/core/state" "github.com/ethereum/go-ethereum/core/state"
"github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/core/vm"
"github.com/ethereum/go-ethereum/event" "github.com/ethereum/go-ethereum/event"
"github.com/ethereum/go-ethereum/log" "github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/metrics" "github.com/ethereum/go-ethereum/metrics"
"github.com/ethereum/go-ethereum/params" "github.com/ethereum/go-ethereum/params"
"github.com/ethereum/go-ethereum/rollup/rcfg"
) )
const ( const (
...@@ -554,7 +554,7 @@ func (pool *TxPool) validateTx(tx *types.Transaction, local bool) error { ...@@ -554,7 +554,7 @@ func (pool *TxPool) validateTx(tx *types.Transaction, local bool) error {
return ErrUnderpriced return ErrUnderpriced
} }
// Ensure the transaction adheres to nonce ordering // Ensure the transaction adheres to nonce ordering
if vm.UsingOVM { if rcfg.UsingOVM {
if pool.currentState.GetNonce(from) != tx.Nonce() { if pool.currentState.GetNonce(from) != tx.Nonce() {
return ErrNonceTooLow return ErrNonceTooLow
} }
......
...@@ -37,6 +37,7 @@ import ( ...@@ -37,6 +37,7 @@ import (
"github.com/ethereum/go-ethereum/event" "github.com/ethereum/go-ethereum/event"
"github.com/ethereum/go-ethereum/log" "github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/params" "github.com/ethereum/go-ethereum/params"
"github.com/ethereum/go-ethereum/rollup/rcfg"
"github.com/ethereum/go-ethereum/rpc" "github.com/ethereum/go-ethereum/rpc"
) )
...@@ -267,7 +268,13 @@ func (b *EthAPIBackend) GetTd(blockHash common.Hash) *big.Int { ...@@ -267,7 +268,13 @@ func (b *EthAPIBackend) GetTd(blockHash common.Hash) *big.Int {
} }
func (b *EthAPIBackend) GetEVM(ctx context.Context, msg core.Message, state *state.StateDB, header *types.Header) (*vm.EVM, func() error, error) { func (b *EthAPIBackend) GetEVM(ctx context.Context, msg core.Message, state *state.StateDB, header *types.Header) (*vm.EVM, func() error, error) {
state.SetBalance(msg.From(), math.MaxBig256) // This was removed upstream:
// https://github.com/ethereum/go-ethereum/commit/39f502329fac4640cfb71959c3496f19ea88bc85#diff-9886da3412b43831145f62cec6e895eb3613a175b945e5b026543b7463454603
// We're throwing this behind a UsingOVM flag for now as to not break
// any tests that may depend on this behavior.
if !rcfg.UsingOVM {
state.SetBalance(msg.From(), math.MaxBig256)
}
vmError := func() error { return nil } vmError := func() error { return nil }
context := core.NewEVMContext(msg, header, b.eth.BlockChain(), nil) context := core.NewEVMContext(msg, header, b.eth.BlockChain(), nil)
......
...@@ -26,8 +26,6 @@ import ( ...@@ -26,8 +26,6 @@ import (
"sync" "sync"
"sync/atomic" "sync/atomic"
"github.com/ethereum/go-ethereum/rollup"
"github.com/ethereum/go-ethereum/accounts" "github.com/ethereum/go-ethereum/accounts"
"github.com/ethereum/go-ethereum/accounts/abi/bind" "github.com/ethereum/go-ethereum/accounts/abi/bind"
"github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common"
...@@ -53,6 +51,8 @@ import ( ...@@ -53,6 +51,8 @@ import (
"github.com/ethereum/go-ethereum/p2p/enr" "github.com/ethereum/go-ethereum/p2p/enr"
"github.com/ethereum/go-ethereum/params" "github.com/ethereum/go-ethereum/params"
"github.com/ethereum/go-ethereum/rlp" "github.com/ethereum/go-ethereum/rlp"
"github.com/ethereum/go-ethereum/rollup"
"github.com/ethereum/go-ethereum/rollup/rcfg"
"github.com/ethereum/go-ethereum/rpc" "github.com/ethereum/go-ethereum/rpc"
) )
...@@ -223,8 +223,8 @@ func New(ctx *node.ServiceContext, config *Config) (*Ethereum, error) { ...@@ -223,8 +223,8 @@ func New(ctx *node.ServiceContext, config *Config) (*Ethereum, error) {
eth.miner = miner.New(eth, &config.Miner, chainConfig, eth.EventMux(), eth.engine, eth.isLocalBlock) eth.miner = miner.New(eth, &config.Miner, chainConfig, eth.EventMux(), eth.engine, eth.isLocalBlock)
eth.miner.SetExtra(makeExtraData(config.Miner.ExtraData)) eth.miner.SetExtra(makeExtraData(config.Miner.ExtraData))
log.Info("Backend Config", "max-calldata-size", config.Rollup.MaxCallDataSize, "gas-limit", config.Rollup.GasLimit, "is-verifier", config.Rollup.IsVerifier, "using-ovm", vm.UsingOVM) log.Info("Backend Config", "max-calldata-size", config.Rollup.MaxCallDataSize, "gas-limit", config.Rollup.GasLimit, "is-verifier", config.Rollup.IsVerifier, "using-ovm", rcfg.UsingOVM)
eth.APIBackend = &EthAPIBackend{ctx.ExtRPCEnabled(), eth, nil, nil, config.Rollup.IsVerifier, config.Rollup.GasLimit, vm.UsingOVM, config.Rollup.MaxCallDataSize} eth.APIBackend = &EthAPIBackend{ctx.ExtRPCEnabled(), eth, nil, nil, config.Rollup.IsVerifier, config.Rollup.GasLimit, rcfg.UsingOVM, config.Rollup.MaxCallDataSize}
gpoParams := config.GPO gpoParams := config.GPO
if gpoParams.Default == nil { if gpoParams.Default == nil {
gpoParams.Default = config.Miner.GasPrice gpoParams.Default = config.Miner.GasPrice
...@@ -238,7 +238,7 @@ func New(ctx *node.ServiceContext, config *Config) (*Ethereum, error) { ...@@ -238,7 +238,7 @@ func New(ctx *node.ServiceContext, config *Config) (*Ethereum, error) {
} }
func makeExtraData(extra []byte) []byte { func makeExtraData(extra []byte) []byte {
if vm.UsingOVM { if rcfg.UsingOVM {
// Make the extradata deterministic // Make the extradata deterministic
extra, _ = rlp.EncodeToBytes([]interface{}{ extra, _ = rlp.EncodeToBytes([]interface{}{
uint(params.VersionMajor<<16 | params.VersionMinor<<8 | params.VersionPatch), uint(params.VersionMajor<<16 | params.VersionMinor<<8 | params.VersionPatch),
......
...@@ -44,15 +44,11 @@ import ( ...@@ -44,15 +44,11 @@ import (
"github.com/ethereum/go-ethereum/p2p" "github.com/ethereum/go-ethereum/p2p"
"github.com/ethereum/go-ethereum/params" "github.com/ethereum/go-ethereum/params"
"github.com/ethereum/go-ethereum/rlp" "github.com/ethereum/go-ethereum/rlp"
"github.com/ethereum/go-ethereum/rollup/fees" "github.com/ethereum/go-ethereum/rollup/rcfg"
"github.com/ethereum/go-ethereum/rpc" "github.com/ethereum/go-ethereum/rpc"
"github.com/tyler-smith/go-bip39" "github.com/tyler-smith/go-bip39"
) )
const (
defaultGasPrice = params.Wei * fees.TxGasPrice
)
var errOVMUnsupported = errors.New("OVM: Unsupported RPC Method") var errOVMUnsupported = errors.New("OVM: Unsupported RPC Method")
// TEMPORARY: Set the gas price to 0 until message passing and ETH value work again. // TEMPORARY: Set the gas price to 0 until message passing and ETH value work again.
...@@ -848,7 +844,7 @@ func DoCall(ctx context.Context, b Backend, args CallArgs, blockNrOrHash rpc.Blo ...@@ -848,7 +844,7 @@ func DoCall(ctx context.Context, b Backend, args CallArgs, blockNrOrHash rpc.Blo
log.Warn("Caller gas above allowance, capping", "requested", gas, "cap", globalGasCap) log.Warn("Caller gas above allowance, capping", "requested", gas, "cap", globalGasCap)
gas = globalGasCap.Uint64() gas = globalGasCap.Uint64()
} }
gasPrice := new(big.Int).SetUint64(defaultGasPrice) gasPrice := new(big.Int)
if args.GasPrice != nil { if args.GasPrice != nil {
gasPrice = args.GasPrice.ToInt() gasPrice = args.GasPrice.ToInt()
} }
...@@ -868,7 +864,7 @@ func DoCall(ctx context.Context, b Backend, args CallArgs, blockNrOrHash rpc.Blo ...@@ -868,7 +864,7 @@ func DoCall(ctx context.Context, b Backend, args CallArgs, blockNrOrHash rpc.Blo
// or else the result of `eth_call` will not be correct. // or else the result of `eth_call` will not be correct.
blockNumber := header.Number blockNumber := header.Number
timestamp := header.Time timestamp := header.Time
if vm.UsingOVM { if rcfg.UsingOVM {
block, err := b.BlockByNumber(ctx, rpc.BlockNumber(header.Number.Uint64())) block, err := b.BlockByNumber(ctx, rpc.BlockNumber(header.Number.Uint64()))
if err != nil { if err != nil {
return nil, 0, false, err return nil, 0, false, err
...@@ -1596,7 +1592,7 @@ func SubmitTransaction(ctx context.Context, b Backend, tx *types.Transaction) (c ...@@ -1596,7 +1592,7 @@ func SubmitTransaction(ctx context.Context, b Backend, tx *types.Transaction) (c
// SendTransaction creates a transaction for the given argument, sign it and submit it to the // SendTransaction creates a transaction for the given argument, sign it and submit it to the
// transaction pool. // transaction pool.
func (s *PublicTransactionPoolAPI) SendTransaction(ctx context.Context, args SendTxArgs) (common.Hash, error) { func (s *PublicTransactionPoolAPI) SendTransaction(ctx context.Context, args SendTxArgs) (common.Hash, error) {
if vm.UsingOVM { if rcfg.UsingOVM {
return common.Hash{}, errOVMUnsupported return common.Hash{}, errOVMUnsupported
} }
// Look up the wallet containing the requested signer // Look up the wallet containing the requested signer
...@@ -1631,7 +1627,7 @@ func (s *PublicTransactionPoolAPI) SendTransaction(ctx context.Context, args Sen ...@@ -1631,7 +1627,7 @@ func (s *PublicTransactionPoolAPI) SendTransaction(ctx context.Context, args Sen
// FillTransaction fills the defaults (nonce, gas, gasPrice) on a given unsigned transaction, // FillTransaction fills the defaults (nonce, gas, gasPrice) on a given unsigned transaction,
// and returns it to the caller for further processing (signing + broadcast) // and returns it to the caller for further processing (signing + broadcast)
func (s *PublicTransactionPoolAPI) FillTransaction(ctx context.Context, args SendTxArgs) (*SignTransactionResult, error) { func (s *PublicTransactionPoolAPI) FillTransaction(ctx context.Context, args SendTxArgs) (*SignTransactionResult, error) {
if vm.UsingOVM { if rcfg.UsingOVM {
return nil, errOVMUnsupported return nil, errOVMUnsupported
} }
// Set some sanity defaults and terminate on failure // Set some sanity defaults and terminate on failure
...@@ -1678,7 +1674,7 @@ func (s *PublicTransactionPoolAPI) SendRawTransaction(ctx context.Context, encod ...@@ -1678,7 +1674,7 @@ func (s *PublicTransactionPoolAPI) SendRawTransaction(ctx context.Context, encod
// //
// https://github.com/ethereum/wiki/wiki/JSON-RPC#eth_sign // https://github.com/ethereum/wiki/wiki/JSON-RPC#eth_sign
func (s *PublicTransactionPoolAPI) Sign(addr common.Address, data hexutil.Bytes) (hexutil.Bytes, error) { func (s *PublicTransactionPoolAPI) Sign(addr common.Address, data hexutil.Bytes) (hexutil.Bytes, error) {
if vm.UsingOVM { if rcfg.UsingOVM {
return nil, errOVMUnsupported return nil, errOVMUnsupported
} }
// Look up the wallet containing the requested signer // Look up the wallet containing the requested signer
...@@ -1706,7 +1702,7 @@ type SignTransactionResult struct { ...@@ -1706,7 +1702,7 @@ type SignTransactionResult struct {
// The node needs to have the private key of the account corresponding with // The node needs to have the private key of the account corresponding with
// the given from address and it needs to be unlocked. // the given from address and it needs to be unlocked.
func (s *PublicTransactionPoolAPI) SignTransaction(ctx context.Context, args SendTxArgs) (*SignTransactionResult, error) { func (s *PublicTransactionPoolAPI) SignTransaction(ctx context.Context, args SendTxArgs) (*SignTransactionResult, error) {
if vm.UsingOVM { if rcfg.UsingOVM {
return nil, errOVMUnsupported return nil, errOVMUnsupported
} }
if args.Gas == nil { if args.Gas == nil {
......
package dump
import (
"github.com/ethereum/go-ethereum/common"
)
var OvmEthAddress = common.HexToAddress("0x4200000000000000000000000000000000000006")
package rcfg
import (
"os"
)
// UsingOVM is used to enable or disable functionality necessary for the OVM.
var UsingOVM bool
func init() {
UsingOVM = os.Getenv("USING_OVM") == "true"
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment