Skip to content

Commit

Permalink
contracts-bedrock: remove cannon deps on bindings (#10280)
Browse files Browse the repository at this point in the history
* contracts-bedrock: remove cannon deps on bindings

Removes `cannon` deps on `op-bindings` package following
a pattern similar to #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
  • Loading branch information
tynes authored Apr 24, 2024
1 parent d4706da commit 9ca3362
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 13 deletions.
16 changes: 14 additions & 2 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,8 @@ jobs:
- checkout
- check-changed:
patterns: cannon,packages/contracts-bedrock/src/cannon,op-preimage,go.mod
- attach_workspace:
at: "."
- run:
name: prep Cannon results dir
command: mkdir -p /tmp/test-results
Expand Down Expand Up @@ -783,12 +785,19 @@ jobs:
on_changes:
description: changed pattern to fire fuzzer on
type: string
uses_artifacts:
description: should load in foundry artifacts
type: boolean
default: false
docker:
- image: <<pipeline.parameters.ci_builder_image>>
steps:
- checkout
- check-changed:
patterns: "<<parameters.package_name>>"
- attach_workspace:
at: "."
if: ${{ uses_artifacts }}
- restore_cache:
name: Restore Go modules cache
key: gomod-{{ checksum "go.sum" }}
Expand Down Expand Up @@ -1708,7 +1717,8 @@ workflows:
name: cannon-fuzz
package_name: cannon
on_changes: cannon,packages/contracts-bedrock/src/cannon
requires: ["go-mod-download"]
uses_artifacts: true
requires: ["go-mod-download", "pnpm-monorepo"]
- go-test:
name: op-heartbeat-tests
module: op-heartbeat
Expand Down Expand Up @@ -1907,7 +1917,9 @@ workflows:
docker_tags: <<pipeline.git.revision>>,<<pipeline.git.branch>>
- check-generated-mocks-op-node
- check-generated-mocks-op-service
- cannon-go-lint-and-test
- cannon-go-lint-and-test:
requires:
- pnpm-monorepo
- cannon-build-test-vectors
- shellcheck/check:
name: shell-check
Expand Down
44 changes: 33 additions & 11 deletions cannon/mipsevm/evm.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ package mipsevm

import (
"encoding/binary"
"encoding/json"
"fmt"
"math/big"
"os"

"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/hexutil"
Expand All @@ -15,28 +17,48 @@ import (
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/core/vm"
"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) {
var mips, oracle Contract
mips.DeployedBytecode.Object = hexutil.MustDecode(bindings.MIPSDeployedBin)
oracle.DeployedBytecode.Object = hexutil.MustDecode(bindings.PreimageOracleDeployedBin)
mips, err := loadContract("../../packages/contracts-bedrock/forge-artifacts/MIPS.sol/MIPS.json")
if err != nil {
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{
MIPS: &mips,
Oracle: &oracle,
MIPS: mips,
Oracle: oracle,
}, 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 {
DeployedBytecode struct {
Object hexutil.Bytes `json:"object"`
SourceMap string `json:"sourceMap"`
} `json:"deployedBytecode"`

// ignore abi,bytecode,etc.
Bytecode struct {
Object hexutil.Bytes `json:"object"`
} `json:"bytecode"`
// ignore abi,etc.
}

type Contracts struct {
Expand Down Expand Up @@ -76,7 +98,7 @@ func NewEVMEnv(contracts *Contracts, addrs *Addresses) (*vm.EVM, *state.StateDB)

var mipsCtorArgs [32]byte
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)
_, deployedMipsAddr, leftOverGas, err := env.Create(vm.AccountRef(addrs.Sender), mipsDeploy, startingGas, common.U2560)
if err != nil {
Expand Down

0 comments on commit 9ca3362

Please sign in to comment.