Skip to content
This repository was archived by the owner on Apr 11, 2021. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
e3ca5a8
Works, but need to figure out this bug
smartcontracts Oct 29, 2020
4f90f0e
Remove unnecessary log statements
smartcontracts Oct 29, 2020
f6482de
Finalizing integration
smartcontracts Oct 30, 2020
dd0caa0
Small code cleanups
smartcontracts Oct 31, 2020
dd3d4a3
Added a few more comments
smartcontracts Nov 2, 2020
cfbb0c0
Various bugfixes
smartcontracts Nov 3, 2020
c467c4a
Works, but need to figure out this bug
smartcontracts Oct 29, 2020
fede6c8
Remove unnecessary log statements
smartcontracts Oct 29, 2020
16dad48
Finalizing integration
smartcontracts Oct 30, 2020
bc8af0d
Small code cleanups
smartcontracts Oct 31, 2020
f25f336
Added a few more comments
smartcontracts Nov 2, 2020
a8ed700
Various bugfixes
smartcontracts Nov 3, 2020
8bd1147
Merge branch 'dev/contracts-v2-v2' of github.com:ethereum-optimism/go…
smartcontracts Nov 3, 2020
f1b39f5
Added custom fillbytes function
smartcontracts Nov 4, 2020
e9f95d3
Removed old test file for now
smartcontracts Nov 4, 2020
56680fb
Fix linting errors
smartcontracts Nov 4, 2020
3a03061
Fix linting errors
smartcontracts Nov 4, 2020
c2f6f1e
Reduce gas limit again
smartcontracts Nov 4, 2020
511c45c
Various fixes!
smartcontracts Nov 5, 2020
41b4998
Minor updates to get l1 ingestion address
smartcontracts Nov 6, 2020
b5124c2
Merge branch 'master' of github.com:ethereum-optimism/go-ethereum int…
karlfloersch Nov 6, 2020
d20c3a9
Fix remaining bugs
karlfloersch Nov 6, 2020
1969725
Fix lint errors
karlfloersch Nov 6, 2020
0ef864e
Fix broken tests. WARN I skipped some
karlfloersch Nov 6, 2020
a495e0d
loglines: remove before deployment
tynes Nov 6, 2020
3004a0a
core: less diff by removing newlines
tynes Nov 6, 2020
1ac2e87
core: less diff by removing newlines
tynes Nov 6, 2020
3b72f28
rollup: remove logline in signtx
tynes Nov 6, 2020
9790e0f
core/ovm: handle errors when type casting
tynes Nov 6, 2020
1bf63ca
ovm: log applying message
tynes Nov 6, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 12 additions & 11 deletions accounts/abi/bind/backends/simulated.go
Original file line number Diff line number Diff line change
Expand Up @@ -593,17 +593,18 @@ type callmsg struct {
ethereum.CallMsg
}

func (m callmsg) From() common.Address { return m.CallMsg.From }
func (m callmsg) Nonce() uint64 { return 0 }
func (m callmsg) CheckNonce() bool { return false }
func (m callmsg) To() *common.Address { return m.CallMsg.To }
func (m callmsg) GasPrice() *big.Int { return m.CallMsg.GasPrice }
func (m callmsg) Gas() uint64 { return m.CallMsg.Gas }
func (m callmsg) Value() *big.Int { return m.CallMsg.Value }
func (m callmsg) Data() []byte { return m.CallMsg.Data }
func (m callmsg) L1MessageSender() *common.Address { return m.CallMsg.L1MessageSender }
func (m callmsg) L1RollupTxId() *hexutil.Uint64 { return m.CallMsg.L1RollupTxId }
func (m callmsg) QueueOrigin() *big.Int { return m.CallMsg.QueueOrigin }
func (m callmsg) From() common.Address { return m.CallMsg.From }
func (m callmsg) Nonce() uint64 { return 0 }
func (m callmsg) CheckNonce() bool { return false }
func (m callmsg) To() *common.Address { return m.CallMsg.To }
func (m callmsg) GasPrice() *big.Int { return m.CallMsg.GasPrice }
func (m callmsg) Gas() uint64 { return m.CallMsg.Gas }
func (m callmsg) Value() *big.Int { return m.CallMsg.Value }
func (m callmsg) Data() []byte { return m.CallMsg.Data }
func (m callmsg) L1MessageSender() *common.Address { return m.CallMsg.L1MessageSender }
func (m callmsg) L1RollupTxId() *hexutil.Uint64 { return m.CallMsg.L1RollupTxId }
func (m callmsg) QueueOrigin() *big.Int { return m.CallMsg.QueueOrigin }
func (m callmsg) SignatureHashType() types.SignatureHashType { return m.CallMsg.SignatureHashType }

// filterBackend implements filters.Backend to support filtering for logs without
// taking bloom-bits acceleration structures into account.
Expand Down
15 changes: 4 additions & 11 deletions core/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -256,17 +256,10 @@ func (g *Genesis) configOrDefault(ghash common.Hash) *params.ChainConfig {

// ApplyOvmStateToState applies the initial OVM state to a state object.
func ApplyOvmStateToState(statedb *state.StateDB) {
// Set up the OVM genesis state
var initOvmStateDump state.Dump
// Load the OVM genesis
initOvmStateDumpMarshaled, _ := hex.DecodeString(vm.InitialOvmStateDump)
json.Unmarshal(initOvmStateDumpMarshaled, &initOvmStateDump)
for addr, account := range initOvmStateDump.Accounts {
statedb.AddBalance(addr, big.NewInt(0))
statedb.SetCode(addr, common.FromHex(account.Code))
statedb.SetNonce(addr, account.Nonce)
for key, value := range account.Storage {
statedb.SetState(addr, key, common.HexToHash(value))
for _, account := range vm.OvmStateDump.Accounts {
statedb.SetCode(account.Address, common.FromHex(account.Code))
for key, val := range account.Storage {
statedb.SetState(account.Address, key, common.HexToHash(val))
}
}
}
Expand Down
19 changes: 16 additions & 3 deletions core/state_processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"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/log"
"github.com/ethereum/go-ethereum/params"
)

Expand Down Expand Up @@ -82,17 +83,29 @@ func (p *StateProcessor) Process(block *types.Block, statedb *state.StateDB, cfg
// for the transaction, gas used and an error if the transaction failed,
// 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) {
msg, err := tx.AsMessage(types.MakeSigner(config, header.Number))
if err != nil {
return nil, err
var msg Message
var err error
if !vm.UsingOVM {
msg, err = tx.AsMessage(types.MakeSigner(config, header.Number))
if err != nil {
return nil, err
}
} else {
msg, err = asOvmMessage(tx, types.MakeSigner(config, header.Number))
if err != nil {
return nil, err
}
}

// Create a new context to be used in the EVM environment
context := NewEVMContext(msg, header, bc, author)
// Create a new environment which holds all relevant information
// about the transaction and calling mechanisms.
vmenv := vm.NewEVM(context, statedb, config, cfg)
// Apply the transaction to the current state (included in the env)
log.Debug(">>>>>> Serving an OVM transaction <<<<<<")
_, gas, failed, err := ApplyMessage(vmenv, msg, gp)
log.Debug("<<<<<< Served an OVM transaction >>>>>>")
if err != nil {
return nil, err
}
Expand Down
109 changes: 36 additions & 73 deletions core/state_transition.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,32 +18,20 @@ package core

import (
"errors"
"fmt"
"math"
"math/big"
"strings"

"github.com/ethereum/go-ethereum/accounts/abi"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/hexutil"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/core/vm"
"github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/params"
)

var (
errInsufficientBalanceForGas = errors.New("insufficient balance to pay for gas")
executionManagerAbi abi.ABI
)

func init() {
var err error
executionManagerAbi, err = abi.JSON(strings.NewReader(vm.RawExecutionManagerAbi))
if err != nil {
panic(fmt.Sprintf("Error reading ExecutionManagerAbi! Error: %s", err))
}
}

/*
The State Transitioning Model

Expand Down Expand Up @@ -89,6 +77,7 @@ type Message interface {
L1MessageSender() *common.Address
L1RollupTxId() *hexutil.Uint64
QueueOrigin() *big.Int
SignatureHashType() types.SignatureHashType
}

// IntrinsicGas computes the 'intrinsic gas' for a message with the given data.
Expand Down Expand Up @@ -149,6 +138,18 @@ func NewStateTransition(evm *vm.EVM, msg Message, gp *GasPool) *StateTransition
// indicates a core error meaning that the message would always fail for that particular
// state and would never be accepted within a block.
func ApplyMessage(evm *vm.EVM, msg Message, gp *GasPool) ([]byte, uint64, bool, error) {
if vm.UsingOVM {
// OVM_ENABLED
ovmmsg, err := toExecutionManagerRun(evm, msg)
if err != nil {
return nil, 0, false, err
}

evm.Context.Origin = msg.From()

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hopefully this will be made unnecessary by a change @K-Ho is making to the OVM_ExecutionManager. Basically needed so I can get msg.sender == ovmStateManager.owner() to return true.


return NewStateTransition(evm, ovmmsg, gp).TransitionDb()
}

return NewStateTransition(evm, msg, gp).TransitionDb()
}
Comment thread
tynes marked this conversation as resolved.
Outdated

Expand Down Expand Up @@ -201,9 +202,16 @@ func (st *StateTransition) preCheck() error {
// returning the result including the used gas. It returns an error if failed.
// An error indicates a consensus issue.
func (st *StateTransition) TransitionDb() (ret []byte, usedGas uint64, failed bool, err error) {
if err = st.preCheck(); err != nil {
return
if !vm.UsingOVM {
// OVM_DISABLED
if err = st.preCheck(); err != nil {
return
}
} else {
// OVM_ENABLED
st.buyGas()

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the only part of the preCheck that we actually care about.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is it safe to skip the nonce check?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It wasn't :-( I added the nonce check again.

}

msg := st.msg
sender := vm.AccountRef(msg.From())
homestead := st.evm.ChainConfig().IsHomestead(st.evm.BlockNumber)
Expand All @@ -220,80 +228,35 @@ func (st *StateTransition) TransitionDb() (ret []byte, usedGas uint64, failed bo
}

var (
evm = st.evm
// vm errors do not effect consensus and are therefore
// not assigned to err, except for insufficient balance
// error.
vmerr error
)

to := "<nil>"
if msg.To() != nil {
to = msg.To().Hex()
}

executionMgrTime := st.evm.Time
if executionMgrTime.Cmp(big.NewInt(0)) == 0 {
executionMgrTime = big.NewInt(1)
}

// TODO: queue origin is always 0 with current version of em
queueOrigin := big.NewInt(0)

l1MessageSender := msg.L1MessageSender()
if l1MessageSender == nil {
addr := common.HexToAddress("")
l1MessageSender = &addr
}

log.Debug("Applying transaction", "from", sender.Address().Hex(), "to", to, "nonce", msg.Nonce(), "l1MessageSender", l1MessageSender.Hex(), "data", hexutil.Encode(msg.Data()))

if contractCreation {
// Here we are going to call the EM directly

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All of this is now handled in toExecutionManagerRun, so not needed here anymore.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

awesome refactor

deployContractCalldata, _ := executionManagerAbi.Pack(
"executeTransaction",
executionMgrTime, // lastL1Timestamp
queueOrigin, // queueOrigin
common.HexToAddress(""), // ovmEntrypoint
st.data, // callBytes
sender, // fromAddress
l1MessageSender, // l1MsgSenderAddress
true, // allowRevert
)

ret, st.gas, vmerr = evm.Call(sender, vm.ExecutionManagerAddress, deployContractCalldata, st.gas, st.value)
ret, _, st.gas, vmerr = st.evm.Create(sender, st.data, st.gas, st.value)
} else {
callContractCalldata, _ := executionManagerAbi.Pack(
"executeTransaction",
executionMgrTime, // lastL1Timestamp
queueOrigin, // queueOrigin
st.to(), // ovmEntrypoint
st.data, // callBytes
sender, // fromAddress
l1MessageSender, // l1MsgSenderAddress
true, // allowRevert
)

ret, st.gas, vmerr = evm.Call(sender, vm.ExecutionManagerAddress, callContractCalldata, st.gas, st.value)
// Increment the nonce for the next transaction
if !vm.UsingOVM {
st.state.SetNonce(msg.From(), st.state.GetNonce(msg.From())+1)
}
ret, st.gas, vmerr = st.evm.Call(sender, st.to(), st.data, st.gas, st.value)
}
if vmerr != nil {
log.Debug("VM returned with error", "err", vmerr)

// If the tx fails we won't have incremented the nonce. In this case, increment it manually
log.Debug("Incrementing nonce due to transaction failure")
st.state.SetNonce(msg.From(), st.state.GetNonce(sender.Address())+1)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to figure out the best way to handle this nonce eviction thing. @karlfloersch should we just go ahead and update the eviction logic?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Once we've stabilized Synthetix running in Contracts v2, and have deployed Mintr to this Geth & have it work, that seems to me to be the next highest priority


// The only possible consensus-error would be if there wasn't
// sufficient balance to make the transfer happen. The first
// balance transfer may never fail.
if vmerr != nil {
if vmerr == vm.ErrInsufficientBalance {
return nil, 0, false, vmerr
}
}

st.refundGas()
st.state.AddBalance(st.evm.Coinbase, new(big.Int).Mul(new(big.Int).SetUint64(st.gasUsed()), st.gasPrice))

log.Debug("return data", "data", hexutil.Encode(ret))
if !vm.UsingOVM {
// OVM_DISABLED
st.state.AddBalance(st.evm.Coinbase, new(big.Int).Mul(new(big.Int).SetUint64(st.gasUsed()), st.gasPrice))

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No balances in the OVM.

}

return ret, st.gasUsed(), vmerr != nil, err
}

Expand Down
Loading