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
0daac0f6
Commit
0daac0f6
authored
Nov 04, 2021
by
George Hotz
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
CallWithTrieNodes in progress
parent
20112775
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
26 additions
and
14 deletions
+26
-14
Challenge.sol
contracts/Challenge.sol
+18
-0
Lib_MerkleTrie.sol
contracts/lib/Lib_MerkleTrie.sol
+1
-7
challenge_test.js
test/challenge_test.js
+7
-7
No files found.
contracts/Challenge.sol
View file @
0daac0f6
// SPDX-License-Identifier: MIT
// SPDX-License-Identifier: MIT
pragma solidity ^0.7.3;
pragma solidity ^0.7.3;
pragma experimental ABIEncoderV2;
import "./lib/Lib_RLPReader.sol";
import "./lib/Lib_RLPReader.sol";
import "hardhat/console.sol";
import "hardhat/console.sol";
...
@@ -10,6 +11,7 @@ interface IMIPS {
...
@@ -10,6 +11,7 @@ interface IMIPS {
}
}
interface IMIPSMemory {
interface IMIPSMemory {
function AddTrieNode(bytes calldata anything) external;
function ReadMemory(bytes32 stateHash, uint32 addr) external view returns (uint32);
function ReadMemory(bytes32 stateHash, uint32 addr) external view returns (uint32);
function ReadBytes32(bytes32 stateHash, uint32 addr) external view returns (bytes32);
function ReadBytes32(bytes32 stateHash, uint32 addr) external view returns (bytes32);
function WriteMemory(bytes32 stateHash, uint32 addr, uint32 val) external returns (bytes32);
function WriteMemory(bytes32 stateHash, uint32 addr, uint32 val) external returns (bytes32);
...
@@ -74,6 +76,22 @@ contract Challenge {
...
@@ -74,6 +76,22 @@ contract Challenge {
return challengeId;
return challengeId;
}
}
// helper function to determine what nodes we need
function CallWithTrieNodes(bytes calldata dat, bytes[] calldata nodes) public {
for (uint i = 0; i < nodes.length; i++) {
mem.AddTrieNode(nodes[i]);
}
(bool success, bytes memory revertData) = address(this).call(dat);
// TODO: better way to revert?
if (!success) {
uint256 revertDataLength = revertData.length;
assembly {
let revertDataStart := add(revertData, 32)
revert(revertDataStart, revertDataLength)
}
}
}
function InitiateChallenge(uint blockNumberN, bytes calldata blockHeaderNp1,
function InitiateChallenge(uint blockNumberN, bytes calldata blockHeaderNp1,
bytes32 assertionRoot, bytes32 finalSystemState, uint256 stepCount) external returns (uint256) {
bytes32 assertionRoot, bytes32 finalSystemState, uint256 stepCount) external returns (uint256) {
bytes32 computedBlockHash = keccak256(blockHeaderNp1);
bytes32 computedBlockHash = keccak256(blockHeaderNp1);
...
...
contracts/lib/Lib_MerkleTrie.sol
View file @
0daac0f6
...
@@ -111,13 +111,7 @@ library Lib_MerkleTrie {
...
@@ -111,13 +111,7 @@ library Lib_MerkleTrie {
node[i] = bytes1(uint8(node[i]) + uint8(0x61-10));
node[i] = bytes1(uint8(node[i]) + uint8(0x61-10));
}
}
}
}
// Error(string)
revert(string(node));
bytes memory revertData = abi.encodeWithSelector(0x08c379a0, string(node));
uint256 revertDataLength = revertData.length;
assembly {
let revertDataStart := add(revertData, 32)
revert(revertDataStart, revertDataLength)
}
}
}
require(keccak256(encoded) == nodeId, "bad hash in trie lookup");
require(keccak256(encoded) == nodeId, "bad hash in trie lookup");
return getRawNode(encoded);
return getRawNode(encoded);
...
...
test/challenge_test.js
View file @
0daac0f6
...
@@ -26,23 +26,23 @@ describe("Challenge contract", function () {
...
@@ -26,23 +26,23 @@ describe("Challenge contract", function () {
const
assertionRoot
=
"
0x9e0261efe4509912b8862f3d45a0cb8404b99b239247df9c55871bd3844cebbd
"
const
assertionRoot
=
"
0x9e0261efe4509912b8862f3d45a0cb8404b99b239247df9c55871bd3844cebbd
"
let
startTrie
=
JSON
.
parse
(
fs
.
readFileSync
(
"
/tmp/cannon/golden.json
"
))
let
startTrie
=
JSON
.
parse
(
fs
.
readFileSync
(
"
/tmp/cannon/golden.json
"
))
let
finalTrie
=
JSON
.
parse
(
fs
.
readFileSync
(
"
/tmp/cannon/0_13284469/checkpoint_85059435.json
"
))
let
finalTrie
=
JSON
.
parse
(
fs
.
readFileSync
(
"
/tmp/cannon/0_13284469/checkpoint_final.json
"
))
let
preimages
=
Object
.
assign
({},
startTrie
[
'
preimages
'
],
finalTrie
[
'
preimages
'
]);
const
finalSystemState
=
finalTrie
[
'
root
'
]
const
finalSystemState
=
finalTrie
[
'
root
'
]
let
cdat
=
c
.
interface
.
encodeFunctionData
(
"
InitiateChallenge
"
,
[
blockNumberN
,
blockNp1Rlp
,
assertionRoot
,
finalSystemState
,
1
])
while
(
1
)
{
while
(
1
)
{
try
{
try
{
// TODO: make this eth call?
// TODO: make this eth call?
// needs something like InitiateChallengeWithTrieNodes
// needs something like InitiateChallengeWithTrieNodes
j
await
c
.
InitiateChallenge
(
blockNumberN
,
blockNp1Rlp
,
assertionRoot
,
finalSystemState
,
1
)
await
c
.
CallWithTrieNodes
(
cdat
,
[]
)
break
break
}
catch
(
e
)
{
}
catch
(
e
)
{
const
missing
=
e
.
toString
().
split
(
"
'
"
)[
1
]
const
missing
=
e
.
toString
().
split
(
"
'
"
)[
1
]
if
(
missing
.
length
==
64
)
{
if
(
missing
.
length
==
64
)
{
console
.
log
(
"
requested node
"
,
missing
)
console
.
log
(
"
requested node
"
,
missing
)
let
node
=
startTrie
[
'
preimages
'
][
"
0x
"
+
missing
]
let
node
=
preimages
[
"
0x
"
+
missing
]
if
(
node
===
undefined
)
{
node
=
finalTrie
[
'
preimages
'
][
"
0x
"
+
missing
]
}
expect
(
node
).
to
.
not
.
be
.
an
(
'
undefined
'
)
expect
(
node
).
to
.
not
.
be
.
an
(
'
undefined
'
)
const
bin
=
Uint8Array
.
from
(
Buffer
.
from
(
node
,
'
base64
'
).
toString
(
'
binary
'
),
c
=>
c
.
charCodeAt
(
0
))
const
bin
=
Uint8Array
.
from
(
Buffer
.
from
(
node
,
'
base64
'
).
toString
(
'
binary
'
),
c
=>
c
.
charCodeAt
(
0
))
await
mm
.
AddTrieNode
(
bin
)
await
mm
.
AddTrieNode
(
bin
)
...
...
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