Commit b5944065 authored by Nicolas "Norswap" Laurent's avatar Nicolas "Norswap" Laurent Committed by norswap

add L2 on L2 demo scripts

parent bfffc121
#!/usr/bin/env bash
# The following variables can be overridden as environment variables:
# * BLOCK (block whose transition will be challenged)
# * SKIP_NODE (skip forking a node, useful if you've already forked a node)
#
# Example usage:
# SKIP_NODE=1 BLOCK=13284469 ./demo/challenge_fault.sh
# --- DOC ----------------------------------------------------------------------
# Unlike the simple scenario (cf. challenge_simple.sh), in this
......@@ -60,24 +67,31 @@ trap "exit_trap" SIGINT SIGTERM EXIT
# --- BOOT MAINNET FORK --------------------------------------------------------
NODE_LOG="challenge_fault_node.log"
if [[ ! "$SKIP_NODE" ]]; then
NODE_LOG="challenge_fault_node.log"
shout "BOOTING MAINNET FORK NODE IN BACKGROUND (LOG: $NODE_LOG)"
shout "BOOTING MAINNET FORK NODE IN BACKGROUND (LOG: $NODE_LOG)"
# get directory containing this file
SCRIPT_DIR=$(dirname "$(readlink -f "$0")")
# get directory containing this file
SCRIPT_DIR=$(dirname "$(readlink -f "$0")")
# run a hardhat mainnet fork node
"$SCRIPT_DIR/forked_node.sh" > "$NODE_LOG" 2>&1 &
# run a hardhat mainnet fork node
"$SCRIPT_DIR/forked_node.sh" > "$NODE_LOG" 2>&1 &
# give the node some time to boot up
sleep 10
# give the node some time to boot up
sleep 10
fi
# --- CHALLENGE SETUP ----------------------------------------------------------
# hardhat network to use
NETWORK=${NETWORK:-l1}
export NETWORK
# block whose transition will be challenged
# this variable is read by challenge.js, respond.js and assert.js
export BLOCK=13284491
BLOCK=${BLOCK:-13284491}
export BLOCK
# challenge ID, read by respond.js and assert.js
export ID=0
......@@ -90,7 +104,7 @@ shout "GENERATING INITIAL MEMORY STATE CHECKPOINT"
mipsevm/mipsevm
shout "DEPLOYING CONTRACTS"
npx hardhat run scripts/deploy.js --network hosthat
npx hardhat run scripts/deploy.js --network $NETWORK
# challenger will use same initial memory checkpoint and deployed contracts
cp /tmp/cannon/{golden,deployed}.json /tmp/cannon_fault/
......@@ -116,23 +130,23 @@ OUTPUTFAULT=1 BASEDIR=/tmp/cannon_fault mipsevm/mipsevm $BLOCK
# --- BINARY SEARCH ------------------------------------------------------------
shout "STARTING CHALLENGE"
BASEDIR=/tmp/cannon_fault npx hardhat run scripts/challenge.js --network hosthat
BASEDIR=/tmp/cannon_fault npx hardhat run scripts/challenge.js --network $NETWORK
shout "BINARY SEARCH"
for i in {1..25}; do
echo ""
echo "--- STEP $i / 25 --"
echo ""
OUTPUTFAULT=1 BASEDIR=/tmp/cannon_fault CHALLENGER=1 npx hardhat run scripts/respond.js --network hosthat
npx hardhat run scripts/respond.js --network hosthat
OUTPUTFAULT=1 BASEDIR=/tmp/cannon_fault CHALLENGER=1 npx hardhat run scripts/respond.js --network $NETWORK
npx hardhat run scripts/respond.js --network $NETWORK
done
# --- SINGLE STEP EXECUTION ----------------------------------------------------
shout "ASSERTING AS CHALLENGER (should fail)"
set +e # this should fail!
BASEDIR=/tmp/cannon_fault CHALLENGER=1 npx hardhat run scripts/assert.js --network hosthat
BASEDIR=/tmp/cannon_fault CHALLENGER=1 npx hardhat run scripts/assert.js --network $NETWORK
set -e
shout "ASSERTING AS DEFENDER (should pass)"
npx hardhat run scripts/assert.js --network hosthat
npx hardhat run scripts/assert.js --network $NETWORK
......@@ -77,6 +77,10 @@ fi
# --- CHALLENGE SETUP ----------------------------------------------------------
# hardhat network to use
NETWORK=${NETWORK:-l1}
export NETWORK
# challenge ID, read by respond.js and assert.js
export ID=0
......@@ -96,7 +100,7 @@ shout "GENERATING INITIAL MEMORY STATE CHECKPOINT"
mipsevm/mipsevm
shout "DEPLOYING CONTRACTS"
npx hardhat run scripts/deploy.js --network hosthat
npx hardhat run scripts/deploy.js --network $NETWORK
# challenger will use same initial memory checkpoint and deployed contracts
cp /tmp/cannon/{golden,deployed}.json /tmp/cannon_fault/
......@@ -119,23 +123,23 @@ ln -s /tmp/cannon_fault/0_$WRONG_BLOCK /tmp/cannon_fault/0_$BLOCK
# --- BINARY SEARCH ------------------------------------------------------------
shout "STARTING CHALLENGE"
BASEDIR=/tmp/cannon_fault npx hardhat run scripts/challenge.js --network hosthat
BASEDIR=/tmp/cannon_fault npx hardhat run scripts/challenge.js --network $NETWORK
shout "BINARY SEARCH"
for i in {1..23}; do
echo ""
echo "--- STEP $i / 23 ---"
echo ""
BASEDIR=/tmp/cannon_fault CHALLENGER=1 npx hardhat run scripts/respond.js --network hosthat
npx hardhat run scripts/respond.js --network hosthat
BASEDIR=/tmp/cannon_fault CHALLENGER=1 npx hardhat run scripts/respond.js --network $NETWORK
npx hardhat run scripts/respond.js --network $NETWORK
done
# --- SINGLE STEP EXECUTION ----------------------------------------------------
shout "ASSERTING AS CHALLENGER (should fail)"
set +e # this should fail!
BASEDIR=/tmp/cannon_fault CHALLENGER=1 npx hardhat run scripts/assert.js --network hosthat
BASEDIR=/tmp/cannon_fault CHALLENGER=1 npx hardhat run scripts/assert.js --network $NETWORK
set -e
shout "ASSERTING AS DEFENDER (should pass)"
npx hardhat run scripts/assert.js --network hosthat
npx hardhat run scripts/assert.js --network $NETWORK
#!/usr/bin/env bash
# Similar to challenge_fault.sh, but runs on L2!
SCRIPT_DIR=$(dirname "$(readlink -f "$0")")
export ETH_RPC_URL=http://127.0.0.1:9545/
export BLOCK=$(cast block-number)
SKIP_NODE=1 NETWORK=l2 "$SCRIPT_DIR/challenge_fault.sh"
#!/usr/bin/env bash
# Similar to challenge_simple.sh, but runs on L2!
SCRIPT_DIR=$(dirname "$(readlink -f "$0")")
export ETH_RPC_URL=http://127.0.0.1:9545/
export BLOCK=$(cast block-number)
export WRONG_BLOCK=$(expr $BLOCK - 1)
SKIP_NODE=1 NETWORK=l2 "$SCRIPT_DIR/challenge_simple.sh"
# Running Cannon on L2
The original Cannon prototype allows challenging L1 blocks on L1. Normally, the
challenger should always fail, as L1 blocks are valid by virtue of being
included on-chain.
The next milestone is to allow challenging L2 blocks on L2. What this proves is
that the extra logic we added in
[l2geth](https://github.com/ethereum-optimism/reference-optimistic-geth) (aka
reference-optimism-geth) does not break anything. It's also a good way to
exercise our devnet infrastructure.
Running the Cannon demo on a mainnet (L1) fork is a simple as doing:
```bash
# from repo root
demo/challenge_simple.sh
# or
demo/challenge_fault.sh
```
For L2, you'll need first to run the devnet locally. For this, clone the
`develop` branch of the [optimism
monorepo](https://github.com/ethereum-optimism/optimism), then run:
```bash
yarn && make build && make devnet-clean && make devnet-up
```
If you're having trouble building, here's a [full
transcript](https://github.com/ethereum-optimism/cannon/wiki/Bedrock-Full-Devnet-Setup)
of all the commands required to run on a fresh cloud linux machine.
Note it's important to run `make devnet-clean` before each invocation of `make
devnet-up` to work around some issues at the time of writing.
Then you can run the L2 demos:
```bash
# from repo root
demo/l2_challenge_simple.sh
# or
demo/l2_challenge_fault.sh
```
......@@ -17,14 +17,15 @@ try {
module.exports = {
//defaultNetwork: "hosthat",
networks: {
hosthat: {
l1: {
url: "http://127.0.0.1:8545/",
accounts: ["0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80"],
timeout: 600_000,
},
cheapeth: {
url: "https://rpc.cheapeth.org/rpc",
accounts: [private]
l2: {
url: "http://127.0.0.1:9545/",
accounts: ["0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80"],
timeout: 600_000,
},
},
solidity: {
......
......@@ -39,7 +39,10 @@ async function main() {
for (n of nodes) {
await mm.AddTrieNode(n)
}
let ret = await c.initiateChallenge(...args)
// TODO: Setting the gas limit explicitly here shouldn't be necessary, for some
// weird reason (to be investigated), it is for L2.
// let ret = await c.initiateChallenge(...args)
let ret = await c.initiateChallenge(...args, { gasLimit: 10_000_000 })
let receipt = await ret.wait()
// ChallengeCreated event
let challengeId = receipt.events[0].args['challengeId'].toNumber()
......
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