Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
N
nebula
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
exchain
nebula
Commits
b5944065
Commit
b5944065
authored
Jun 13, 2022
by
Nicolas "Norswap" Laurent
Committed by
norswap
Jun 13, 2022
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add L2 on L2 demo scripts
parent
bfffc121
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
113 additions
and
26 deletions
+113
-26
challenge_fault.sh
demo/challenge_fault.sh
+29
-15
challenge_simple.sh
demo/challenge_simple.sh
+10
-6
l2_challenge_fault.sh
demo/l2_challenge_fault.sh
+10
-0
l2_challenge_simple.sh
demo/l2_challenge_simple.sh
+11
-0
l2-on-l2.md
docs/l2-on-l2.md
+44
-0
hardhat.config.js
hardhat.config.js
+5
-4
challenge.js
scripts/challenge.js
+4
-1
No files found.
demo/challenge_fault.sh
View file @
b5944065
#!/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
demo/challenge_simple.sh
View file @
b5944065
...
...
@@ -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
demo/l2_challenge_fault.sh
0 → 100644
View file @
b5944065
#!/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"
demo/l2_challenge_simple.sh
0 → 100644
View file @
b5944065
#!/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"
docs/l2-on-l2.md
0 → 100644
View file @
b5944065
# 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
```
hardhat.config.js
View file @
b5944065
...
...
@@ -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
:
{
...
...
scripts/challenge.js
View file @
b5944065
...
...
@@ -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
()
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment