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
690f9803
Commit
690f9803
authored
Nov 08, 2021
by
George Hotz
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
pushed a challenge to cheapeth
parent
2ed9dcae
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
50 additions
and
9 deletions
+50
-9
README.md
README.md
+5
-3
Challenge.sol
contracts/Challenge.sol
+11
-2
challenge.js
scripts/challenge.js
+28
-2
lib.js
scripts/lib.js
+6
-2
No files found.
README.md
View file @
690f9803
...
...
@@ -57,12 +57,14 @@ process done with hash 0x5c45998dfbf9ce70bcbb80574ed7a622922d2c775e0a2331fe5a8b8
```
# testing on cheapeth
npx hardhat node
# only works for pre fork blocks
minigeth/go-ethereum 1171895
(cd mipsevm && ./mipsevm 1171895)
npx hardhat run scripts/deploy.js
BLOCK=1
365217
5 npx hardhat run scripts/challenge.js
BLOCK=1
17189
5 npx hardhat run scripts/challenge.js
```
## State Oracle API
On chain / in MIPS, we have two oracles
...
...
contracts/Challenge.sol
View file @
690f9803
...
...
@@ -97,14 +97,23 @@ contract Challenge {
function InitiateChallenge(uint blockNumberN, bytes calldata blockHeaderNp1,
bytes32 assertionRoot, bytes32 finalSystemState, uint256 stepCount) external returns (uint256) {
bytes32 computedBlockHash = keccak256(blockHeaderNp1);
require(blockhash(blockNumberN+1) == computedBlockHash, "end block hash wrong");
// get block hashes, can replace with oracle
bytes32 blockNumberNHash = blockhash(blockNumberN);
bytes32 blockNumberNp1Hash = blockhash(blockNumberN+1);
// TODO: this is only removed for testing. zero security without it
/*if (blockNumberNHash == bytes32(0) || blockNumberNp1Hash == bytes32(0)) {
revert("block number too old to challenge");
}
require(blockNumberNp1Hash == computedBlockHash, "end block hash wrong");*/
// decode the blocks
bytes32 inputHash;
{
Lib_RLPReader.RLPItem[] memory blockNp1 = Lib_RLPReader.readList(blockHeaderNp1);
bytes32 parentHash = Lib_RLPReader.readBytes32(blockNp1[0]);
require(blockhash(blockNumberN)
== parentHash, "parent block hash somehow wrong");
//require(blockNumberNHash
== parentHash, "parent block hash somehow wrong");
bytes32 newroot = Lib_RLPReader.readBytes32(blockNp1[3]);
require(assertionRoot != newroot, "asserting that the real state is correct is not a challenge");
...
...
scripts/challenge.js
View file @
690f9803
const
{
deployed
,
getBlockRlp
}
=
require
(
"
../scripts/lib
"
)
const
fs
=
require
(
"
fs
"
)
const
{
deployed
,
getBlockRlp
,
getTrieNodesForCall
}
=
require
(
"
../scripts/lib
"
)
async
function
main
()
{
let
[
c
,
m
,
mm
]
=
await
deployed
()
...
...
@@ -14,7 +15,32 @@ async function main() {
const
blockNp1Rlp
=
getBlockRlp
(
blockNp1
)
console
.
log
(
c
.
address
,
m
.
address
,
mm
.
address
)
// TODO: finish this
// TODO: move this to lib, it's shared with the test
let
startTrie
=
JSON
.
parse
(
fs
.
readFileSync
(
"
/tmp/cannon/golden.json
"
))
/*const assertionRoot = "0x1111111111111111111111111111111111111111111111111111111111111111"
let finalTrie = JSON.parse(fs.readFileSync("/tmp/cannon/0_"+blockNumberN.toString()+"/checkpoint_final.json"))*/
// fake for testing (it's the next block)
const
assertionRoot
=
"
0xb135cb00efbc2341905eafc034eca0dcec40b039a1b28860bf7c309c872e5644
"
let
finalTrie
=
JSON
.
parse
(
fs
.
readFileSync
(
"
/tmp/cannon/0_1171896/checkpoint_final.json
"
))
let
preimages
=
Object
.
assign
({},
startTrie
[
'
preimages
'
],
finalTrie
[
'
preimages
'
]);
const
finalSystemState
=
finalTrie
[
'
root
'
]
let
args
=
[
blockNumberN
,
blockNp1Rlp
,
assertionRoot
,
finalSystemState
,
finalTrie
[
'
step
'
]]
let
cdat
=
c
.
interface
.
encodeFunctionData
(
"
InitiateChallenge
"
,
args
)
let
nodes
=
await
getTrieNodesForCall
(
c
,
cdat
,
preimages
)
// run "on chain"
for
(
n
of
nodes
)
{
await
mm
.
AddTrieNode
(
n
)
}
let
ret
=
await
c
.
InitiateChallenge
(...
args
)
let
receipt
=
await
ret
.
wait
()
// ChallengeCreate event
let
challengeId
=
receipt
.
events
[
0
].
args
[
'
challengeId
'
].
toNumber
()
console
.
log
(
"
new challenge with id
"
,
challengeId
)
}
main
()
...
...
scripts/lib.js
View file @
690f9803
...
...
@@ -68,8 +68,12 @@ async function getTrieNodesForCall(c, cdat, preimages) {
});
break
}
catch
(
e
)
{
const
missing
=
e
.
toString
().
split
(
"
'
"
)[
1
]
if
(
missing
.
length
==
64
)
{
let
missing
=
e
.
toString
().
split
(
"
'
"
)[
1
]
if
(
missing
==
undefined
)
{
// other kind of error from HTTPProvider
missing
=
e
.
error
.
message
.
toString
().
split
(
"
execution reverted:
"
)[
1
]
}
if
(
missing
!==
undefined
&&
missing
.
length
==
64
)
{
console
.
log
(
"
requested node
"
,
missing
)
let
node
=
preimages
[
"
0x
"
+
missing
]
if
(
node
===
undefined
)
{
...
...
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