Commit 9ca3362d authored by Mark Tyneway's avatar Mark Tyneway Committed by GitHub

contracts-bedrock: remove cannon deps on bindings (#10280)

* contracts-bedrock: remove cannon deps on bindings

Removes `cannon` deps on `op-bindings` package following
a pattern similar to https://github.com/ethereum-optimism/optimism/pull/10225.
Includes test coverage of the new functions and is the minimal diff to
get things working.

Ideally there was a canonical forge artifact type that is used but for
now we don't worry about it. This unblocks further work on removing the
bindings from the monorepo, greatly improving devex.

* cannon: cleanup, new approach

* ci: attempt fix

* ci: attempt fix

* ci: fixup
parent d4706dad
...@@ -123,6 +123,8 @@ jobs: ...@@ -123,6 +123,8 @@ jobs:
- checkout - checkout
- check-changed: - check-changed:
patterns: cannon,packages/contracts-bedrock/src/cannon,op-preimage,go.mod patterns: cannon,packages/contracts-bedrock/src/cannon,op-preimage,go.mod
- attach_workspace:
at: "."
- run: - run:
name: prep Cannon results dir name: prep Cannon results dir
command: mkdir -p /tmp/test-results command: mkdir -p /tmp/test-results
...@@ -783,12 +785,19 @@ jobs: ...@@ -783,12 +785,19 @@ jobs:
on_changes: on_changes:
description: changed pattern to fire fuzzer on description: changed pattern to fire fuzzer on
type: string type: string
uses_artifacts:
description: should load in foundry artifacts
type: boolean
default: false
docker: docker:
- image: <<pipeline.parameters.ci_builder_image>> - image: <<pipeline.parameters.ci_builder_image>>
steps: steps:
- checkout - checkout
- check-changed: - check-changed:
patterns: "<<parameters.package_name>>" patterns: "<<parameters.package_name>>"
- attach_workspace:
at: "."
if: ${{ uses_artifacts }}
- restore_cache: - restore_cache:
name: Restore Go modules cache name: Restore Go modules cache
key: gomod-{{ checksum "go.sum" }} key: gomod-{{ checksum "go.sum" }}
...@@ -1708,7 +1717,8 @@ workflows: ...@@ -1708,7 +1717,8 @@ workflows:
name: cannon-fuzz name: cannon-fuzz
package_name: cannon package_name: cannon
on_changes: cannon,packages/contracts-bedrock/src/cannon on_changes: cannon,packages/contracts-bedrock/src/cannon
requires: ["go-mod-download"] uses_artifacts: true
requires: ["go-mod-download", "pnpm-monorepo"]
- go-test: - go-test:
name: op-heartbeat-tests name: op-heartbeat-tests
module: op-heartbeat module: op-heartbeat
...@@ -1907,7 +1917,9 @@ workflows: ...@@ -1907,7 +1917,9 @@ workflows:
docker_tags: <<pipeline.git.revision>>,<<pipeline.git.branch>> docker_tags: <<pipeline.git.revision>>,<<pipeline.git.branch>>
- check-generated-mocks-op-node - check-generated-mocks-op-node
- check-generated-mocks-op-service - check-generated-mocks-op-service
- cannon-go-lint-and-test - cannon-go-lint-and-test:
requires:
- pnpm-monorepo
- cannon-build-test-vectors - cannon-build-test-vectors
- shellcheck/check: - shellcheck/check:
name: shell-check name: shell-check
......
...@@ -2,8 +2,10 @@ package mipsevm ...@@ -2,8 +2,10 @@ package mipsevm
import ( import (
"encoding/binary" "encoding/binary"
"encoding/json"
"fmt" "fmt"
"math/big" "math/big"
"os"
"github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/hexutil" "github.com/ethereum/go-ethereum/common/hexutil"
...@@ -15,28 +17,48 @@ import ( ...@@ -15,28 +17,48 @@ import (
"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/params" "github.com/ethereum/go-ethereum/params"
"github.com/ethereum-optimism/optimism/op-bindings/bindings"
) )
// LoadContracts loads the Cannon contracts, from op-bindings package // LoadContracts loads the Cannon contracts, from the contracts package.
func LoadContracts() (*Contracts, error) { func LoadContracts() (*Contracts, error) {
var mips, oracle Contract mips, err := loadContract("../../packages/contracts-bedrock/forge-artifacts/MIPS.sol/MIPS.json")
mips.DeployedBytecode.Object = hexutil.MustDecode(bindings.MIPSDeployedBin) if err != nil {
oracle.DeployedBytecode.Object = hexutil.MustDecode(bindings.PreimageOracleDeployedBin) return nil, fmt.Errorf("failed to load MIPS contract: %w", err)
}
oracle, err := loadContract("../../packages/contracts-bedrock/forge-artifacts/PreimageOracle.sol/PreimageOracle.json")
if err != nil {
return nil, fmt.Errorf("failed to load Oracle contract: %w", err)
}
return &Contracts{ return &Contracts{
MIPS: &mips, MIPS: mips,
Oracle: &oracle, Oracle: oracle,
}, nil }, nil
} }
func loadContract(path string) (*Contract, error) {
file, err := os.ReadFile(path)
if err != nil {
return nil, fmt.Errorf("artifact at %s not found: %w", path, err)
}
contract := Contract{}
if err := json.Unmarshal(file, &contract); err != nil {
return nil, err
}
return &contract, nil
}
type Contract struct { type Contract struct {
DeployedBytecode struct { DeployedBytecode struct {
Object hexutil.Bytes `json:"object"` Object hexutil.Bytes `json:"object"`
SourceMap string `json:"sourceMap"` SourceMap string `json:"sourceMap"`
} `json:"deployedBytecode"` } `json:"deployedBytecode"`
Bytecode struct {
// ignore abi,bytecode,etc. Object hexutil.Bytes `json:"object"`
} `json:"bytecode"`
// ignore abi,etc.
} }
type Contracts struct { type Contracts struct {
...@@ -76,7 +98,7 @@ func NewEVMEnv(contracts *Contracts, addrs *Addresses) (*vm.EVM, *state.StateDB) ...@@ -76,7 +98,7 @@ func NewEVMEnv(contracts *Contracts, addrs *Addresses) (*vm.EVM, *state.StateDB)
var mipsCtorArgs [32]byte var mipsCtorArgs [32]byte
copy(mipsCtorArgs[12:], addrs.Oracle[:]) copy(mipsCtorArgs[12:], addrs.Oracle[:])
mipsDeploy := append(hexutil.MustDecode(bindings.MIPSMetaData.Bin), mipsCtorArgs[:]...) mipsDeploy := append(hexutil.MustDecode(contracts.MIPS.Bytecode.Object.String()), mipsCtorArgs[:]...)
startingGas := uint64(30_000_000) startingGas := uint64(30_000_000)
_, deployedMipsAddr, leftOverGas, err := env.Create(vm.AccountRef(addrs.Sender), mipsDeploy, startingGas, common.U2560) _, deployedMipsAddr, leftOverGas, err := env.Create(vm.AccountRef(addrs.Sender), mipsDeploy, startingGas, common.U2560)
if err != nil { if err != nil {
......
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