Skip to content

Commit

Permalink
devnet: Replace mt-cannon with 64-bit Cannon (#12924)
Browse files Browse the repository at this point in the history
  • Loading branch information
Inphi authored Nov 17, 2024
1 parent 78fed1e commit 914157f
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 14 deletions.
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,8 @@ cannon-prestate: op-program cannon ## Generates prestate using cannon and op-pro
mv op-program/bin/0.json op-program/bin/prestate-proof.json
.PHONY: cannon-prestate

cannon-prestate-mt: op-program cannon ## Generates prestate using cannon and op-program in the multithreaded cannon format
./cannon/bin/cannon load-elf --type multithreaded --path op-program/bin/op-program-client.elf --out op-program/bin/prestate-mt.bin.gz --meta op-program/bin/meta-mt.json
cannon-prestate-mt: op-program cannon ## Generates prestate using cannon and op-program in the multithreaded64 cannon format
./cannon/bin/cannon load-elf --type multithreaded64 --path op-program/bin/op-program-client64.elf --out op-program/bin/prestate-mt.bin.gz --meta op-program/bin/meta-mt.json
./cannon/bin/cannon run --proof-at '=0' --stop-at '=1' --input op-program/bin/prestate-mt.bin.gz --meta op-program/bin/meta-mt.json --proof-fmt 'op-program/bin/%d-mt.json' --output ""
mv op-program/bin/0-mt.json op-program/bin/prestate-proof-mt.json
.PHONY: cannon-prestate-mt
Expand Down
34 changes: 28 additions & 6 deletions op-e2e/faultproofs/precompile_test.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
package faultproofs

import (
"bytes"
"context"
"encoding/json"
"math"
"math/big"
"os/exec"
"path/filepath"
"testing"

Expand All @@ -12,7 +15,6 @@ import (
"github.com/ethereum-optimism/optimism/op-e2e/system/e2esys"
"github.com/ethereum-optimism/optimism/op-e2e/system/helpers"

"github.com/ethereum-optimism/optimism/cannon/mipsevm/versions"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/hexutil"
"github.com/ethereum/go-ethereum/core/types"
Expand Down Expand Up @@ -276,9 +278,29 @@ func runCannon(t *testing.T, ctx context.Context, sys *e2esys.System, inputs uti
err := executor.DoGenerateProof(ctx, proofsDir, math.MaxUint, math.MaxUint, extraVmArgs...)
require.NoError(t, err, "failed to generate proof")

state, err := versions.LoadStateFromFile(vm.FinalStatePath(proofsDir, cfg.Cannon.BinarySnapshots))
require.NoError(t, err, "failed to parse state")
require.True(t, state.GetExited(), "cannon did not exit")
require.Zero(t, state.GetExitCode(), "cannon failed with exit code %d", state.GetExitCode())
t.Logf("Completed in %d steps", state.GetStep())
stdOut, _, err := runCmd(ctx, cfg.Cannon.VmBin, "witness", "--input", vm.FinalStatePath(proofsDir, cfg.Cannon.BinarySnapshots))
require.NoError(t, err, "failed to run witness cmd")
type stateData struct {
Step uint64 `json:"step"`
ExitCode uint8 `json:"exitCode"`
Exited bool `json:"exited"`
}
var data stateData
err = json.Unmarshal([]byte(stdOut), &data)
require.NoError(t, err, "failed to parse state data")
require.True(t, data.Exited, "cannon did not exit")
require.Zero(t, data.ExitCode, "cannon failed with exit code %d", data.ExitCode)
t.Logf("Completed in %d steps", data.Step)
}

func runCmd(ctx context.Context, binary string, args ...string) (stdOut string, stdErr string, err error) {
var outBuf bytes.Buffer
var errBuf bytes.Buffer
cmd := exec.CommandContext(ctx, binary, args...)
cmd.Stdout = &outBuf
cmd.Stderr = &errBuf
err = cmd.Run()
stdOut = outBuf.String()
stdErr = errBuf.String()
return
}
1 change: 1 addition & 0 deletions op-program/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ After running `make reproducible-prestate`, the following files can be found in
[./bin/](./bin/):
- [`op-program`](./bin/op-program)
- [`op-program-client.elf`](./bin/op-program-client.elf)
- [`op-program-client64.elf`](./bin/op-program-client64.elf)
- [`prestate.bin.gz`](./bin/prestate.bin.gz)
- [`prestate-proof.json`](./bin/prestate-proof.json)

Expand Down
6 changes: 3 additions & 3 deletions packages/contracts-bedrock/scripts/deploy/Deploy.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -695,12 +695,12 @@ contract Deploy is Deployer {
addr_ = address(oracle);
}

/// @notice Deploy Mips VM. Deploys either MIPS or MIPS2 depending on the environment
/// @notice Deploy Mips VM. Deploys either MIPS or MIPS64 depending on the environment
function deployMips() public broadcast returns (address addr_) {
addr_ = DeployUtils.create2AndSave({
_save: this,
_salt: _implSalt(),
_name: Config.useMultithreadedCannon() ? "MIPS2" : "MIPS",
_name: Config.useMultithreadedCannon() ? "MIPS64" : "MIPS",
_args: DeployUtils.encodeConstructor(
abi.encodeCall(IMIPS2.__constructor__, (IPreimageOracle(mustGetAddress("PreimageOracle"))))
)
Expand Down Expand Up @@ -1019,7 +1019,7 @@ contract Deploy is Deployer {
mipsAbsolutePrestate_ =
Claim.wrap(abi.decode(bytes(Process.bash(string.concat("cat ", filePath, " | jq -r .pre"))), (bytes32)));
console.log(
"[MT-Cannon Dispute Game] Using devnet MIPS2 Absolute prestate: %s",
"[MT-Cannon Dispute Game] Using devnet MIPS64 Absolute prestate: %s",
vm.toString(Claim.unwrap(mipsAbsolutePrestate_))
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,7 @@ contract DeployDisputeGame is Script {
vm.broadcast(msg.sender);
singleton = IMIPS(
DeployUtils.create1({
_name: mipsVersion == 1 ? "MIPS" : "MIPS2",
_name: mipsVersion == 1 ? "MIPS" : "MIPS64",
_args: DeployUtils.encodeConstructor(abi.encodeCall(IMIPS.__constructor__, (preimageOracle)))
})
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -802,7 +802,7 @@ contract DeployImplementations is Script {
vm.broadcast(msg.sender);
singleton = IMIPS(
DeployUtils.create1({
_name: mipsVersion == 1 ? "MIPS" : "MIPS2",
_name: mipsVersion == 1 ? "MIPS" : "MIPS64",
_args: DeployUtils.encodeConstructor(abi.encodeCall(IMIPS.__constructor__, (preimageOracle)))
})
);
Expand Down
2 changes: 1 addition & 1 deletion packages/contracts-bedrock/scripts/deploy/DeployMIPS.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ contract DeployMIPS is Script {
vm.broadcast(msg.sender);
singleton = IMIPS(
DeployUtils.create1({
_name: mipsVersion == 1 ? "MIPS" : "MIPS2",
_name: mipsVersion == 1 ? "MIPS" : "MIPS64",
_args: DeployUtils.encodeConstructor(abi.encodeCall(IMIPS.__constructor__, (preimageOracle)))
})
);
Expand Down

0 comments on commit 914157f

Please sign in to comment.