Commit 71e0fd84 authored by protolambda's avatar protolambda

cannon: move sourcemap tracing util to op-chain-ops

parent 26c461ae
......@@ -20,6 +20,7 @@ import (
"github.com/ethereum/go-ethereum/params"
"github.com/ethereum-optimism/optimism/op-bindings/bindings"
"github.com/ethereum-optimism/optimism/op-chain-ops/srcmap"
)
var (
......@@ -78,8 +79,8 @@ type Contract struct {
// ignore abi,bytecode,etc.
}
func (c *Contract) SourceMap(sourcePaths []string) (*SourceMap, error) {
return ParseSourceMap(sourcePaths, c.DeployedBytecode.Object, c.DeployedBytecode.SourceMap)
func (c *Contract) SourceMap(sourcePaths []string) (*srcmap.SourceMap, error) {
return srcmap.ParseSourceMap(sourcePaths, c.DeployedBytecode.Object, c.DeployedBytecode.SourceMap)
}
type Contracts struct {
......
......@@ -15,6 +15,8 @@ import (
"github.com/ethereum/go-ethereum/core/vm"
"github.com/ethereum/go-ethereum/crypto"
"github.com/stretchr/testify/require"
"github.com/ethereum-optimism/optimism/op-chain-ops/srcmap"
)
func testContractsSetup(t *testing.T) (*Contracts, *Addresses, vm.EVMLogger) {
......@@ -33,7 +35,7 @@ func testContractsSetup(t *testing.T) (*Contracts, *Addresses, vm.EVMLogger) {
FeeRecipient: common.Address{0xaa},
}
var tracer vm.EVMLogger
tracer = NewSourceMapTracer(map[common.Address]*SourceMap{addrs.MIPS: mipsSrcMap, addrs.Oracle: oracleSrcMap}, os.Stdout)
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
......
package mipsevm
package srcmap
import (
"fmt"
......@@ -108,6 +108,11 @@ func (s *SourceMap) FormattedInfo(pc uint64) string {
// ParseSourceMap parses a solidity sourcemap: mapping bytecode indices to source references.
// See https://docs.soliditylang.org/en/latest/internals/source_mappings.html
//
// Sources is the list of source files, which will be read from the filesystem
// to transform token numbers into line/column numbers.
// The sources are as referenced in the source-map by index.
// Not all sources are necessary, some indices may be unknown.
func ParseSourceMap(sources []string, bytecode []byte, sourceMap string) (*SourceMap, error) {
instructions := strings.Split(sourceMap, ";")
......
package mipsevm
package srcmap
import (
"strings"
"testing"
"github.com/ethereum/go-ethereum/common/hexutil"
"github.com/stretchr/testify/require"
"github.com/ethereum-optimism/optimism/op-bindings/bindings"
)
func TestSourcemap(t *testing.T) {
contract, err := LoadContract("MIPS")
require.NoError(t, err)
srcMap, err := contract.SourceMap([]string{"../../packages/contracts-bedrock/contracts/cannon/MIPS.sol"})
sourcePath := "../../packages/contracts-bedrock/contracts/cannon/MIPS.sol"
deployedByteCode := hexutil.MustDecode(bindings.MIPSDeployedBin)
srcMap, err := ParseSourceMap(
[]string{sourcePath},
deployedByteCode,
bindings.MIPSDeployedSourceMap)
require.NoError(t, err)
for i := 0; i < len(contract.DeployedBytecode.Object); i++ {
for i := 0; i < len(deployedByteCode); i++ {
info := srcMap.FormattedInfo(uint64(i))
if !strings.HasPrefix(info, "generated:") && !strings.HasPrefix(info, "../../packages/contracts-bedrock/contracts/cannon/MIPS.sol") {
if !strings.HasPrefix(info, "generated:") && !strings.HasPrefix(info, sourcePath) {
t.Fatalf("unexpected info: %q", info)
}
}
......
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