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
6d1ca43f
Commit
6d1ca43f
authored
Dec 10, 2021
by
George Hotz
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix the blockhash issue by forking at block
parent
b5d884fb
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
17 additions
and
18 deletions
+17
-18
README.md
README.md
+11
-10
Challenge.sol
contracts/Challenge.sol
+3
-4
main.go
mipsevm/main.go
+0
-1
challenge.js
scripts/challenge.js
+3
-3
No files found.
README.md
View file @
6d1ca43f
...
@@ -47,31 +47,32 @@ npx hardhat run scripts/deploy.js
...
@@ -47,31 +47,32 @@ npx hardhat run scripts/deploy.js
## Full Challenge / Response
## Full Challenge / Response
```
```
# testing on hardhat (forked mainnet)
# testing on hardhat (forked mainnet
, a few blocks ahead of challenge
)
npx hardhat node --fork https://mainnet.infura.io/v3/9aa3d95b3bc440fa88ea12eaa4456161
npx hardhat node --fork https://mainnet.infura.io/v3/9aa3d95b3bc440fa88ea12eaa4456161
--fork-block-number 13284495
# challenger is pretending the block 1
0 transition is the transition for 1171895
# challenger is pretending the block 1
3284491 transition is the transition for 13284469
# this will conflict at the first step
# this will conflict at the first step
rm -rf /tmp/cannon/*
rm -rf /tmp/cannon/*
mipsevm/mipsevm
mipsevm/mipsevm
npx hardhat run scripts/deploy.js --network hosthat
npx hardhat run scripts/deploy.js --network hosthat
minigeth/go-ethereum 1171895 && mipsevm/mipsevm 1171895
# compute the MIPS checkpoints
minigeth/go-ethereum 10 && mipsevm/mipsevm 10
minigeth/go-ethereum 13284491 && mipsevm/mipsevm 13284491
BLOCK=1171895 npx hardhat run scripts/challenge.js --network hosthat
minigeth/go-ethereum 13284469 && mipsevm/mipsevm 13284469
BLOCK=13284469 npx hardhat run scripts/challenge.js --network hosthat
# do binary search
# do binary search
for i in {1..23}
for i in {1..23}
do
do
ID=0 BLOCK=1
0
CHALLENGER=1 npx hardhat run scripts/respond.js --network hosthat
ID=0 BLOCK=1
3284491
CHALLENGER=1 npx hardhat run scripts/respond.js --network hosthat
ID=0 BLOCK=1
171895
npx hardhat run scripts/respond.js --network hosthat
ID=0 BLOCK=1
3284469
npx hardhat run scripts/respond.js --network hosthat
done
done
# assert as challenger (fails)
# assert as challenger (fails)
ID=0 BLOCK=1
0
CHALLENGER=1 npx hardhat run scripts/assert.js --network hosthat
ID=0 BLOCK=1
3284491
CHALLENGER=1 npx hardhat run scripts/assert.js --network hosthat
# assert as defender (passes)
# assert as defender (passes)
ID=0 BLOCK=1
171895
npx hardhat run scripts/assert.js --network hosthat
ID=0 BLOCK=1
3284469
npx hardhat run scripts/assert.js --network hosthat
```
```
## State Oracle API
## State Oracle API
...
...
contracts/Challenge.sol
View file @
6d1ca43f
...
@@ -105,18 +105,17 @@ contract Challenge {
...
@@ -105,18 +105,17 @@ contract Challenge {
bytes32 blockNumberNHash = blockhash(blockNumberN);
bytes32 blockNumberNHash = blockhash(blockNumberN);
bytes32 blockNumberNp1Hash = blockhash(blockNumberN+1);
bytes32 blockNumberNp1Hash = blockhash(blockNumberN+1);
// TODO: this is only removed for testing. zero security without it
if (blockNumberNHash == bytes32(0) || blockNumberNp1Hash == bytes32(0)) {
/*if (blockNumberNHash == bytes32(0) || blockNumberNp1Hash == bytes32(0)) {
revert("block number too old to challenge");
revert("block number too old to challenge");
}
}
require(blockNumberNp1Hash == computedBlockHash, "end block hash wrong");
*/
require(blockNumberNp1Hash == computedBlockHash, "end block hash wrong");
// decode the blocks
// decode the blocks
bytes32 inputHash;
bytes32 inputHash;
{
{
Lib_RLPReader.RLPItem[] memory blockNp1 = Lib_RLPReader.readList(blockHeaderNp1);
Lib_RLPReader.RLPItem[] memory blockNp1 = Lib_RLPReader.readList(blockHeaderNp1);
bytes32 parentHash = Lib_RLPReader.readBytes32(blockNp1[0]);
bytes32 parentHash = Lib_RLPReader.readBytes32(blockNp1[0]);
//
require(blockNumberNHash == parentHash, "parent block hash somehow wrong");
require(blockNumberNHash == parentHash, "parent block hash somehow wrong");
bytes32 newroot = Lib_RLPReader.readBytes32(blockNp1[3]);
bytes32 newroot = Lib_RLPReader.readBytes32(blockNp1[3]);
require(assertionRoot != newroot, "asserting that the real state is correct is not a challenge");
require(assertionRoot != newroot, "asserting that the real state is correct is not a challenge");
...
...
mipsevm/main.go
View file @
6d1ca43f
...
@@ -58,7 +58,6 @@ func main() {
...
@@ -58,7 +58,6 @@ func main() {
mu
.
RegWrite
(
uc
.
MIPS_REG_PC
,
0x5ead0004
)
mu
.
RegWrite
(
uc
.
MIPS_REG_PC
,
0x5ead0004
)
}
}
}
}
// TODO: is this where the plus 1 goes?
lastStep
=
step
+
1
lastStep
=
step
+
1
})
})
...
...
scripts/challenge.js
View file @
6d1ca43f
...
@@ -21,9 +21,9 @@ async function main() {
...
@@ -21,9 +21,9 @@ async function main() {
/*const assertionRoot = "0x1111111111111111111111111111111111111111111111111111111111111111"
/*const assertionRoot = "0x1111111111111111111111111111111111111111111111111111111111111111"
let finalTrie = JSON.parse(fs.readFileSync("/tmp/cannon/0_"+blockNumberN.toString()+"/checkpoint_final.json"))*/
let finalTrie = JSON.parse(fs.readFileSync("/tmp/cannon/0_"+blockNumberN.toString()+"/checkpoint_final.json"))*/
// we are submitting the (wrong) transition for block 1
0
as the attacker
// we are submitting the (wrong) transition for block 1
3284469
as the attacker
const
assertionRoot
=
"
0x
03f930c087b70f3385db68fe6bf128719e2d9a4b0a133e53b32db2fa25d345fd
"
const
assertionRoot
=
"
0x
b0b8fc0cf929b8b7a1a31059e1dfb321e78ff0dfe5912d5c615beaf37ec608e7
"
let
finalTrie
=
JSON
.
parse
(
fs
.
readFileSync
(
"
/tmp/cannon/0_1
0
/checkpoint_final.json
"
))
let
finalTrie
=
JSON
.
parse
(
fs
.
readFileSync
(
"
/tmp/cannon/0_1
3284491
/checkpoint_final.json
"
))
let
preimages
=
Object
.
assign
({},
startTrie
[
'
preimages
'
],
finalTrie
[
'
preimages
'
]);
let
preimages
=
Object
.
assign
({},
startTrie
[
'
preimages
'
],
finalTrie
[
'
preimages
'
]);
const
finalSystemState
=
finalTrie
[
'
root
'
]
const
finalSystemState
=
finalTrie
[
'
root
'
]
...
...
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