Commit ab6e83e6 authored by protolambda's avatar protolambda

cannon: polish evm tracer setup and fix linting

parent 1588712f
...@@ -15,7 +15,7 @@ import ( ...@@ -15,7 +15,7 @@ import (
"github.com/pkg/profile" "github.com/pkg/profile"
"github.com/ethereum-optimism/optimism/cannon/mipsevm" "github.com/ethereum-optimism/optimism/cannon/mipsevm"
"github.com/ethereum-optimism/optimism/op-preimage" preimage "github.com/ethereum-optimism/optimism/op-preimage"
) )
var ( var (
...@@ -184,7 +184,7 @@ func Guard(proc *os.ProcessState, fn StepFn) StepFn { ...@@ -184,7 +184,7 @@ func Guard(proc *os.ProcessState, fn StepFn) StepFn {
wit, err := fn(proof) wit, err := fn(proof)
if err != nil { if err != nil {
if proc.Exited() { if proc.Exited() {
return nil, fmt.Errorf("pre-image server exited with code %d, resulting in err %v", proc.ExitCode(), err) return nil, fmt.Errorf("pre-image server exited with code %d, resulting in err %w", proc.ExitCode(), err)
} else { } else {
return nil, err return nil, err
} }
......
...@@ -37,7 +37,7 @@ func LoadContracts() (*Contracts, error) { ...@@ -37,7 +37,7 @@ func LoadContracts() (*Contracts, error) {
oracle.DeployedBytecode.Object = hexutil.MustDecode(bindings.OracleDeployedBin) oracle.DeployedBytecode.Object = hexutil.MustDecode(bindings.OracleDeployedBin)
oracle.DeployedBytecode.SourceMap = bindings.OracleDeployedSourceMap oracle.DeployedBytecode.SourceMap = bindings.OracleDeployedSourceMap
return &Contracts{ return &Contracts{
MIPS: &mips, MIPS: &mips,
Oracle: &oracle, Oracle: &oracle,
}, nil }, nil
} }
......
...@@ -14,39 +14,46 @@ import ( ...@@ -14,39 +14,46 @@ import (
"github.com/ethereum/go-ethereum/common/hexutil" "github.com/ethereum/go-ethereum/common/hexutil"
"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/eth/tracers/logger"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
"github.com/ethereum-optimism/optimism/op-chain-ops/srcmap" "github.com/ethereum-optimism/optimism/op-chain-ops/srcmap"
) )
func testContractsSetup(t *testing.T) (*Contracts, *Addresses, vm.EVMLogger) { func testContractsSetup(t *testing.T) (*Contracts, *Addresses) {
contracts, err := LoadContracts() contracts, err := LoadContracts()
require.NoError(t, err) require.NoError(t, err)
mipsSrcMap, err := contracts.MIPS.SourceMap([]string{"../../packages/contracts-bedrock/contracts/cannon/MIPS.sol"})
require.NoError(t, err)
oracleSrcMap, err := contracts.Oracle.SourceMap([]string{"../../packages/contracts-bedrock/contracts/cannon/Oracle.sol"})
require.NoError(t, err)
addrs := &Addresses{ addrs := &Addresses{
MIPS: common.Address{0: 0xff, 19: 1}, MIPS: common.Address{0: 0xff, 19: 1},
Oracle: common.Address{0: 0xff, 19: 2}, Oracle: common.Address{0: 0xff, 19: 2},
Sender: common.Address{0x13, 0x37}, Sender: common.Address{0x13, 0x37},
FeeRecipient: common.Address{0xaa}, FeeRecipient: common.Address{0xaa},
} }
var tracer vm.EVMLogger
tracer = srcmap.NewSourceMapTracer(map[common.Address]*srcmap.SourceMap{addrs.MIPS: mipsSrcMap, addrs.Oracle: oracleSrcMap}, os.Stdout)
//tracer = logger.NewMarkdownLogger(&logger.Config{}, os.Stdout)
tracer = nil // disable tracer return contracts, addrs
return contracts, addrs, tracer }
func SourceMapTracer(t *testing.T, contracts *Contracts, addrs *Addresses) vm.EVMLogger {
mipsSrcMap, err := contracts.MIPS.SourceMap([]string{"../../packages/contracts-bedrock/contracts/cannon/MIPS.sol"})
require.NoError(t, err)
oracleSrcMap, err := contracts.Oracle.SourceMap([]string{"../../packages/contracts-bedrock/contracts/cannon/Oracle.sol"})
require.NoError(t, err)
return srcmap.NewSourceMapTracer(map[common.Address]*srcmap.SourceMap{addrs.MIPS: mipsSrcMap, addrs.Oracle: oracleSrcMap}, os.Stdout)
}
func MarkdownTracer() vm.EVMLogger {
return logger.NewMarkdownLogger(&logger.Config{}, os.Stdout)
} }
func TestEVM(t *testing.T) { func TestEVM(t *testing.T) {
testFiles, err := os.ReadDir("open_mips_tests/test/bin") testFiles, err := os.ReadDir("open_mips_tests/test/bin")
require.NoError(t, err) require.NoError(t, err)
contracts, addrs, tracer := testContractsSetup(t) contracts, addrs := testContractsSetup(t)
var tracer vm.EVMLogger // no-tracer by default, but see SourceMapTracer and MarkdownTracer
//tracer = SourceMapTracer(t, contracts, addrs)
sender := common.Address{0x13, 0x37} sender := common.Address{0x13, 0x37}
for _, f := range testFiles { for _, f := range testFiles {
...@@ -113,7 +120,9 @@ func TestEVM(t *testing.T) { ...@@ -113,7 +120,9 @@ func TestEVM(t *testing.T) {
} }
func TestHelloEVM(t *testing.T) { func TestHelloEVM(t *testing.T) {
contracts, addrs, tracer := testContractsSetup(t) contracts, addrs := testContractsSetup(t)
var tracer vm.EVMLogger // no-tracer by default, but see SourceMapTracer and MarkdownTracer
//tracer = SourceMapTracer(t, contracts, addrs)
sender := common.Address{0x13, 0x37} sender := common.Address{0x13, 0x37}
elfProgram, err := elf.Open("../example/bin/hello.elf") elfProgram, err := elf.Open("../example/bin/hello.elf")
...@@ -180,7 +189,9 @@ func TestHelloEVM(t *testing.T) { ...@@ -180,7 +189,9 @@ func TestHelloEVM(t *testing.T) {
} }
func TestClaimEVM(t *testing.T) { func TestClaimEVM(t *testing.T) {
contracts, addrs, tracer := testContractsSetup(t) contracts, addrs := testContractsSetup(t)
var tracer vm.EVMLogger // no-tracer by default, but see SourceMapTracer and MarkdownTracer
//tracer = SourceMapTracer(t, contracts, addrs)
elfProgram, err := elf.Open("../example/bin/claim.elf") elfProgram, err := elf.Open("../example/bin/claim.elf")
require.NoError(t, err, "open ELF file") require.NoError(t, err, "open ELF file")
......
...@@ -16,7 +16,7 @@ import ( ...@@ -16,7 +16,7 @@ import (
"github.com/ethereum/go-ethereum/crypto" "github.com/ethereum/go-ethereum/crypto"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
"github.com/ethereum-optimism/optimism/op-preimage" preimage "github.com/ethereum-optimism/optimism/op-preimage"
) )
// 0xbf_c0_00_00 ... baseAddrEnd is used in tests to write the results to // 0xbf_c0_00_00 ... baseAddrEnd is used in tests to write the results to
......
...@@ -5,7 +5,7 @@ import ( ...@@ -5,7 +5,7 @@ import (
"errors" "errors"
"fmt" "fmt"
"github.com/ethereum-optimism/optimism/op-preimage" preimage "github.com/ethereum-optimism/optimism/op-preimage"
) )
type StepWitness struct { type StepWitness struct {
......
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