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
2f8af412
Commit
2f8af412
authored
Feb 08, 2022
by
George Hotz
Committed by
George Hotz
Feb 09, 2022
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
support output fault injection also
parent
41b47702
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
39 additions
and
3 deletions
+39
-3
README.md
README.md
+33
-3
run_unicorn.go
mipsevm/run_unicorn.go
+6
-0
No files found.
README.md
View file @
2f8af412
...
@@ -53,8 +53,7 @@ npx hardhat run scripts/deploy.js
...
@@ -53,8 +53,7 @@ npx hardhat run scripts/deploy.js
# testing on hardhat (forked mainnet, a few blocks ahead of challenge)
# testing on hardhat (forked mainnet, a few blocks ahead of challenge)
npx hardhat node --fork https://mainnet.infura.io/v3/9aa3d95b3bc440fa88ea12eaa4456161 --fork-block-number 13284495
npx hardhat node --fork https://mainnet.infura.io/v3/9aa3d95b3bc440fa88ea12eaa4456161 --fork-block-number 13284495
# challenger is pretending the block 13284491 transition is the transition for 13284469
# setup and deploy contracts
# this will conflict at the first step
mkdir -p /tmp/cannon /tmp/cannon_fault && rm -rf /tmp/cannon/* /tmp/cannon_fault/*
mkdir -p /tmp/cannon /tmp/cannon_fault && rm -rf /tmp/cannon/* /tmp/cannon_fault/*
mipsevm/mipsevm
mipsevm/mipsevm
npx hardhat run scripts/deploy.js --network hosthat
npx hardhat run scripts/deploy.js --network hosthat
...
@@ -63,10 +62,12 @@ cp /tmp/cannon/*.json /tmp/cannon_fault/
...
@@ -63,10 +62,12 @@ cp /tmp/cannon/*.json /tmp/cannon_fault/
# compute real MIPS checkpoint
# compute real MIPS checkpoint
minigeth/go-ethereum 13284469 && mipsevm/mipsevm 13284469
minigeth/go-ethereum 13284469 && mipsevm/mipsevm 13284469
# compute fake MIPS checkpoint (use a symlink to pretend)
# compute fake MIPS checkpoint
# challenger is pretending the block 13284491 transition is the transition for 13284469
BASEDIR=/tmp/cannon_fault minigeth/go-ethereum 13284491 && BASEDIR=/tmp/cannon_fault mipsevm/mipsevm 13284491
BASEDIR=/tmp/cannon_fault minigeth/go-ethereum 13284491 && BASEDIR=/tmp/cannon_fault mipsevm/mipsevm 13284491
ln -s /tmp/cannon_fault/0_13284491 /tmp/cannon_fault/0_13284469
ln -s /tmp/cannon_fault/0_13284491 /tmp/cannon_fault/0_13284469
# start challenge
BASEDIR=/tmp/cannon_fault BLOCK=13284469 npx hardhat run scripts/challenge.js --network hosthat
BASEDIR=/tmp/cannon_fault BLOCK=13284469 npx hardhat run scripts/challenge.js --network hosthat
# do binary search
# do binary search
...
@@ -83,6 +84,35 @@ BASEDIR=/tmp/cannon_fault ID=0 BLOCK=13284469 CHALLENGER=1 npx hardhat run scrip
...
@@ -83,6 +84,35 @@ BASEDIR=/tmp/cannon_fault ID=0 BLOCK=13284469 CHALLENGER=1 npx hardhat run scrip
ID=0 BLOCK=13284469 npx hardhat run scripts/assert.js --network hosthat
ID=0 BLOCK=13284469 npx hardhat run scripts/assert.js --network hosthat
```
```
## Alternate challenge with output fault (much slower)
```
# reset as above
# compute real MIPS checkpoint
minigeth/go-ethereum 13284491 && mipsevm/mipsevm 13284491
# alternate fake MIPS checkpoint
BASEDIR=/tmp/cannon_fault minigeth/go-ethereum 13284491 && OUTPUTFAULT=1 BASEDIR=/tmp/cannon_fault mipsevm/mipsevm 13284491
python3 -c 'f="/tmp/cannon_fault/0_13284491/output";o=b"\xba\xba\xba\xba"+open(f, "rb").read()[4:]; open(f, "wb").write(o)'
# start challenge
BASEDIR=/tmp/cannon_fault BLOCK=13284491 npx hardhat run scripts/challenge.js --network hosthat
# do binary search
for i in {1..25}
do
OUTPUTFAULT=1 BASEDIR=/tmp/cannon_fault ID=0 BLOCK=13284491 CHALLENGER=1 npx hardhat run scripts/respond.js --network hosthat
ID=0 BLOCK=13284491 npx hardhat run scripts/respond.js --network hosthat
done
# assert as challenger (fails)
OUTPUTFAULT=1 BASEDIR=/tmp/cannon_fault ID=0 BLOCK=13284491 CHALLENGER=1 npx hardhat run scripts/assert.js --network hosthat
# assert as defender (passes)
ID=0 BLOCK=13284491 npx hardhat run scripts/assert.js --network hosthat
```
## State Oracle API
## State Oracle API
On chain / in MIPS, we have two simple oracles
On chain / in MIPS, we have two simple oracles
...
...
mipsevm/run_unicorn.go
View file @
2f8af412
...
@@ -73,6 +73,8 @@ func GetHookedUnicorn(root string, ram map[uint32](uint32), callback func(int, u
...
@@ -73,6 +73,8 @@ func GetHookedUnicorn(root string, ram map[uint32](uint32), callback func(int, u
mu
,
err
:=
uc
.
NewUnicorn
(
uc
.
ARCH_MIPS
,
uc
.
MODE_32
|
uc
.
MODE_BIG_ENDIAN
)
mu
,
err
:=
uc
.
NewUnicorn
(
uc
.
ARCH_MIPS
,
uc
.
MODE_32
|
uc
.
MODE_BIG_ENDIAN
)
check
(
err
)
check
(
err
)
_
,
outputfault
:=
os
.
LookupEnv
(
"OUTPUTFAULT"
)
mu
.
HookAdd
(
uc
.
HOOK_INTR
,
func
(
mu
uc
.
Unicorn
,
intno
uint32
)
{
mu
.
HookAdd
(
uc
.
HOOK_INTR
,
func
(
mu
uc
.
Unicorn
,
intno
uint32
)
{
if
intno
!=
17
{
if
intno
!=
17
{
log
.
Fatal
(
"invalid interrupt "
,
intno
,
" at step "
,
steps
)
log
.
Fatal
(
"invalid interrupt "
,
intno
,
" at step "
,
steps
)
...
@@ -130,6 +132,10 @@ func GetHookedUnicorn(root string, ram map[uint32](uint32), callback func(int, u
...
@@ -130,6 +132,10 @@ func GetHookedUnicorn(root string, ram map[uint32](uint32), callback func(int, u
rt
:=
value
rt
:=
value
rs
:=
addr64
&
3
rs
:=
addr64
&
3
addr
:=
uint32
(
addr64
&
0xFFFFFFFC
)
addr
:=
uint32
(
addr64
&
0xFFFFFFFC
)
if
outputfault
&&
addr
==
0x30000804
{
fmt
.
Printf
(
"injecting output fault over %x
\n
"
,
rt
)
rt
=
0xbabababa
}
//fmt.Printf("%X(%d) = %x (at step %d)\n", addr, size, value, steps)
//fmt.Printf("%X(%d) = %x (at step %d)\n", addr, size, value, steps)
if
size
==
1
{
if
size
==
1
{
mem
:=
ram
[
addr
]
mem
:=
ram
[
addr
]
...
...
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