Skip to content

Commit

Permalink
Update to go-ethereum 1.12.0 (#199)
Browse files Browse the repository at this point in the history
* Updated CallMessage to be compliant with core.Message made in new go-ethereum

---------

Co-authored-by: anishnaik <[email protected]>
  • Loading branch information
Xenomega and anishnaik authored Aug 11, 2023
1 parent 2917efc commit cd8605e
Show file tree
Hide file tree
Showing 20 changed files with 313 additions and 260 deletions.
18 changes: 13 additions & 5 deletions chain/test_chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,14 @@ func NewTestChain(genesisAlloc core.GenesisAlloc, testChainConfig *config.TestCh
return nil, err
}

// TODO: go-ethereum doesn't set shanghai start time for THEIR test `ChainConfig` struct.
// Note: We have our own `TestChainConfig` definition that is different (second argument in this function).
// We should allow the user to provide a go-ethereum `ChainConfig` to do custom fork selection, inside of our
// `TestChainConfig` definition. Or we should wrap it in our own struct to simplify the options and not pollute
// our overall medusa project config.
shanghaiTime := uint64(0)
chainConfig.ShanghaiTime = &shanghaiTime

// Create our genesis definition with our default chain config.
genesisDefinition := &core.Genesis{
Config: chainConfig,
Expand Down Expand Up @@ -527,7 +535,7 @@ func (t *TestChain) RevertToBlockNumber(blockNumber uint64) error {
// It takes an optional state argument, which is the state to execute the message over. If not provided, the
// current pending state (or committed state if none is pending) will be used instead.
// The state executed over may be a pending block state.
func (t *TestChain) CallContract(msg core.Message, state *state.StateDB, additionalTracers ...vm.EVMLogger) (*core.ExecutionResult, error) {
func (t *TestChain) CallContract(msg *core.Message, state *state.StateDB, additionalTracers ...vm.EVMLogger) (*core.ExecutionResult, error) {
// If our provided state is nil, use our current chain state.
if state == nil {
state = t.state
Expand All @@ -537,7 +545,7 @@ func (t *TestChain) CallContract(msg core.Message, state *state.StateDB, additio
snapshot := state.Snapshot()

// Set infinite balance to the fake caller account
from := state.GetOrNewStateObject(msg.From())
from := state.GetOrNewStateObject(msg.From)
from.SetBalance(math.MaxBig256)

// Create our transaction and block contexts for the vm
Expand All @@ -552,7 +560,7 @@ func (t *TestChain) CallContract(msg core.Message, state *state.StateDB, additio

// Create our EVM instance.
evm := vm.NewEVM(blockContext, txContext, state, t.chainConfig, vm.Config{
Debug: true,
//Debug: true,
Tracer: extendedTracerRouter,
NoBaseFee: true,
ConfigExtensions: t.vmConfigExtensions,
Expand Down Expand Up @@ -672,7 +680,7 @@ func (t *TestChain) PendingBlockCreateWithParameters(blockNumber uint64, blockTi
// PendingBlockAddTx takes a message (internal txs) and adds it to the current pending block, updating the header
// with relevant execution information. If a pending block was not created, an error is returned.
// Returns the constructed block, or an error if one occurred.
func (t *TestChain) PendingBlockAddTx(message core.Message) error {
func (t *TestChain) PendingBlockAddTx(message *core.Message) error {
// If we don't have a pending block, return an error
if t.pendingBlock == nil {
return errors.New("could not add tx to the chain's pending block because no pending block was created")
Expand All @@ -692,7 +700,7 @@ func (t *TestChain) PendingBlockAddTx(message core.Message) error {

// Create our EVM instance.
evm := vm.NewEVM(blockContext, core.NewEVMTxContext(message), t.state, t.chainConfig, vm.Config{
Debug: true,
//Debug: true,
Tracer: t.transactionTracerRouter,
NoBaseFee: true,
ConfigExtensions: t.vmConfigExtensions,
Expand Down
64 changes: 56 additions & 8 deletions chain/test_chain_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -241,14 +241,26 @@ func TestChainDynamicDeployments(t *testing.T) {
// Deploy the currently indexed contract next

// Create a message to represent our contract deployment.
msg := types.NewMessage(senders[0], nil, chain.State().GetNonce(senders[0]), big.NewInt(0), chain.BlockGasLimit, big.NewInt(1), big.NewInt(0), big.NewInt(0), contract.InitBytecode, nil, false)
msg := core.Message{
To: nil,
From: senders[0],
Nonce: chain.State().GetNonce(senders[0]),
Value: big.NewInt(0),
GasLimit: chain.BlockGasLimit,
GasPrice: big.NewInt(1),
GasFeeCap: big.NewInt(0),
GasTipCap: big.NewInt(0),
Data: contract.InitBytecode,
AccessList: nil,
SkipAccountChecks: false,
}

// Create a new pending block we'll commit to chain
block, err := chain.PendingBlockCreate()
assert.NoError(t, err)

// Add our transaction to the block
err = chain.PendingBlockAddTx(msg)
err = chain.PendingBlockAddTx(&msg)
assert.NoError(t, err)

// Commit the pending block to the chain, so it becomes the new head.
Expand Down Expand Up @@ -354,14 +366,26 @@ func TestChainDeploymentWithArgs(t *testing.T) {
assert.NoError(t, err)

// Create a message to represent our contract deployment.
msg := types.NewMessage(senders[0], nil, chain.State().GetNonce(senders[0]), big.NewInt(0), chain.BlockGasLimit, big.NewInt(1), big.NewInt(0), big.NewInt(0), msgData, nil, false)
msg := core.Message{
To: nil,
From: senders[0],
Nonce: chain.State().GetNonce(senders[0]),
Value: big.NewInt(0),
GasLimit: chain.BlockGasLimit,
GasPrice: big.NewInt(1),
GasFeeCap: big.NewInt(0),
GasTipCap: big.NewInt(0),
Data: msgData,
AccessList: nil,
SkipAccountChecks: false,
}

// Create a new pending block we'll commit to chain
block, err := chain.PendingBlockCreate()
assert.NoError(t, err)

// Add our transaction to the block
err = chain.PendingBlockAddTx(msg)
err = chain.PendingBlockAddTx(&msg)
assert.NoError(t, err)

// Commit the pending block to the chain, so it becomes the new head.
Expand Down Expand Up @@ -451,14 +475,26 @@ func TestChainCloning(t *testing.T) {
// Deploy the currently indexed contract next

// Create a message to represent our contract deployment.
msg := types.NewMessage(senders[0], nil, chain.State().GetNonce(senders[0]), big.NewInt(0), chain.BlockGasLimit, big.NewInt(1), big.NewInt(0), big.NewInt(0), contract.InitBytecode, nil, false)
msg := core.Message{
To: nil,
From: senders[0],
Nonce: chain.State().GetNonce(senders[0]),
Value: big.NewInt(0),
GasLimit: chain.BlockGasLimit,
GasPrice: big.NewInt(1),
GasFeeCap: big.NewInt(0),
GasTipCap: big.NewInt(0),
Data: contract.InitBytecode,
AccessList: nil,
SkipAccountChecks: false,
}

// Create a new pending block we'll commit to chain
block, err := chain.PendingBlockCreate()
assert.NoError(t, err)

// Add our transaction to the block
err = chain.PendingBlockAddTx(msg)
err = chain.PendingBlockAddTx(&msg)
assert.NoError(t, err)

// Commit the pending block to the chain, so it becomes the new head.
Expand Down Expand Up @@ -533,14 +569,26 @@ func TestChainCallSequenceReplayMatchSimple(t *testing.T) {
if len(contract.Abi.Constructor.Inputs) == 0 {
for i := 0; i < 10; i++ {
// Create a message to represent our contract deployment.
msg := types.NewMessage(senders[0], nil, chain.State().GetNonce(senders[0]), big.NewInt(0), chain.BlockGasLimit, big.NewInt(1), big.NewInt(0), big.NewInt(0), contract.InitBytecode, nil, false)
msg := core.Message{
To: nil,
From: senders[0],
Nonce: chain.State().GetNonce(senders[0]),
Value: big.NewInt(0),
GasLimit: chain.BlockGasLimit,
GasPrice: big.NewInt(1),
GasFeeCap: big.NewInt(0),
GasTipCap: big.NewInt(0),
Data: contract.InitBytecode,
AccessList: nil,
SkipAccountChecks: false,
}

// Create a new pending block we'll commit to chain
block, err := chain.PendingBlockCreate()
assert.NoError(t, err)

// Add our transaction to the block
err = chain.PendingBlockAddTx(msg)
err = chain.PendingBlockAddTx(&msg)
assert.NoError(t, err)

// Commit the pending block to the chain, so it becomes the new head.
Expand Down
4 changes: 2 additions & 2 deletions chain/types/block.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ type Block struct {
// of a transaction occurs and can be thought of as an internal EVM transaction. It contains typical transaction
// fields plainly (e.g., no transaction signature is included, the sender is derived and simply supplied as a field
// in a message).
Messages []core.Message
Messages []*core.Message

// MessageResults represents the results recorded while executing transactions.
MessageResults []*MessageResults
Expand All @@ -30,7 +30,7 @@ func NewBlock(header *types.Header) *Block {
block := &Block{
Hash: header.Hash(),
Header: header,
Messages: make([]core.Message, 0),
Messages: make([]*core.Message, 0),
MessageResults: make([]*MessageResults, 0),
}
return block
Expand Down
4 changes: 2 additions & 2 deletions chain/vendored/apply_transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ import (
// This executes on an underlying EVM and returns a transaction receipt, or an error if one occurs.
// Additional changes:
// - Exposed core.ExecutionResult as a return value.
func EVMApplyTransaction(msg Message, config *params.ChainConfig, author *common.Address, gp *GasPool, statedb *state.StateDB, blockNumber *big.Int, blockHash common.Hash, tx *types.Transaction, usedGas *uint64, evm *vm.EVM) (*types.Receipt, *ExecutionResult, error) {
func EVMApplyTransaction(msg *Message, config *params.ChainConfig, author *common.Address, gp *GasPool, statedb *state.StateDB, blockNumber *big.Int, blockHash common.Hash, tx *types.Transaction, usedGas *uint64, evm *vm.EVM) (*types.Receipt, *ExecutionResult, error) {
// Create a new context to be used in the EVM environment.
txContext := NewEVMTxContext(msg)
evm.Reset(txContext, statedb)
Expand Down Expand Up @@ -67,7 +67,7 @@ func EVMApplyTransaction(msg Message, config *params.ChainConfig, author *common
receipt.GasUsed = result.UsedGas

// If the transaction created a contract, store the creation address in the receipt.
if msg.To() == nil {
if msg.To == nil {
receipt.ContractAddress = crypto.CreateAddress(evm.TxContext.Origin, tx.Nonce())
}

Expand Down
2 changes: 1 addition & 1 deletion compilation/types/source_maps.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ func (s SourceMap) GetInstructionIndexToOffsetLookup(bytecode []byte) ([]int, er
operandCount := 0
if op.IsPush() {
if op == vm.PUSH0 {
operandCount = 1
operandCount = 0
} else {
operandCount = int(op) - int(vm.PUSH1) + 1
}
Expand Down
Loading

0 comments on commit cd8605e

Please sign in to comment.