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
34b1fedf
Commit
34b1fedf
authored
Nov 04, 2021
by
George Hotz
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
factor out getTrieNodesForCall
parent
0daac0f6
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
44 additions
and
27 deletions
+44
-27
lib.js
scripts/lib.js
+35
-1
challenge_test.js
test/challenge_test.js
+9
-26
No files found.
scripts/lib.js
View file @
34b1fedf
const
fs
=
require
(
"
fs
"
)
const
{
hasUncaughtExceptionCaptureCallback
}
=
require
(
"
process
"
)
async
function
deploy
()
{
const
MIPS
=
await
ethers
.
getContractFactory
(
"
MIPS
"
)
...
...
@@ -15,4 +16,37 @@ async function deploy() {
return
[
c
,
m
,
mm
]
}
module
.
exports
=
{
deploy
}
async
function
getTrieNodesForCall
(
c
,
cdat
,
preimages
)
{
let
nodes
=
[]
while
(
1
)
{
try
{
// TODO: make this eth call?
// needs something like InitiateChallengeWithTrieNodesj
let
calldata
=
c
.
interface
.
encodeFunctionData
(
"
CallWithTrieNodes
"
,
[
cdat
,
nodes
])
ret
=
await
ethers
.
provider
.
call
({
to
:
c
.
address
,
data
:
calldata
});
console
.
log
(
ret
)
break
}
catch
(
e
)
{
const
missing
=
e
.
toString
().
split
(
"
'
"
)[
1
]
if
(
missing
.
length
==
64
)
{
console
.
log
(
"
requested node
"
,
missing
)
let
node
=
preimages
[
"
0x
"
+
missing
]
if
(
node
===
undefined
)
{
throw
(
"
node not found
"
)
}
const
bin
=
Uint8Array
.
from
(
Buffer
.
from
(
node
,
'
base64
'
).
toString
(
'
binary
'
),
c
=>
c
.
charCodeAt
(
0
))
nodes
.
push
(
bin
)
continue
}
else
{
console
.
log
(
e
)
break
}
}
}
return
nodes
}
module
.
exports
=
{
deploy
,
getTrieNodesForCall
}
test/challenge_test.js
View file @
34b1fedf
const
{
expect
}
=
require
(
"
chai
"
)
const
fs
=
require
(
"
fs
"
)
const
{
deploy
}
=
require
(
"
../scripts/lib
"
)
const
{
deploy
,
getTrieNodesForCall
}
=
require
(
"
../scripts/lib
"
)
describe
(
"
Challenge contract
"
,
function
()
{
if
(
!
fs
.
existsSync
(
"
/tmp/cannon/golden.json
"
))
{
...
...
@@ -20,7 +20,7 @@ describe("Challenge contract", function () {
const
blockchain
=
hardhat
.
_node
.
_blockchain
// get data
const
blockNumberN
=
(
await
ethers
.
provider
.
getBlockNumber
())
-
1
;
const
blockNumberN
=
(
await
ethers
.
provider
.
getBlockNumber
())
-
2
;
const
blockNp1
=
blockchain
.
_data
.
_blocksByNumber
.
get
(
blockNumberN
+
1
)
const
blockNp1Rlp
=
blockNp1
.
header
.
serialize
()
...
...
@@ -30,31 +30,14 @@ describe("Challenge contract", function () {
let
preimages
=
Object
.
assign
({},
startTrie
[
'
preimages
'
],
finalTrie
[
'
preimages
'
]);
const
finalSystemState
=
finalTrie
[
'
root
'
]
let
cdat
=
c
.
interface
.
encodeFunctionData
(
"
InitiateChallenge
"
,
[
blockNumberN
,
blockNp1Rlp
,
assertionRoot
,
finalSystemState
,
1
])
let
args
=
[
blockNumberN
,
blockNp1Rlp
,
assertionRoot
,
finalSystemState
,
1
]
let
cdat
=
c
.
interface
.
encodeFunctionData
(
"
InitiateChallenge
"
,
args
)
let
nodes
=
await
getTrieNodesForCall
(
c
,
cdat
,
preimages
)
while
(
1
)
{
try
{
// TODO: make this eth call?
// needs something like InitiateChallengeWithTrieNodesj
await
c
.
CallWithTrieNodes
(
cdat
,
[])
break
}
catch
(
e
)
{
const
missing
=
e
.
toString
().
split
(
"
'
"
)[
1
]
if
(
missing
.
length
==
64
)
{
console
.
log
(
"
requested node
"
,
missing
)
let
node
=
preimages
[
"
0x
"
+
missing
]
expect
(
node
).
to
.
not
.
be
.
an
(
'
undefined
'
)
const
bin
=
Uint8Array
.
from
(
Buffer
.
from
(
node
,
'
base64
'
).
toString
(
'
binary
'
),
c
=>
c
.
charCodeAt
(
0
))
await
mm
.
AddTrieNode
(
bin
)
continue
}
else
{
console
.
log
(
e
)
break
}
}
// run "on chain"
for
(
n
of
nodes
)
{
await
mm
.
AddTrieNode
(
n
)
}
//const blockHeaderNp1 = getBlockRlp(await ethers.provider.getBlock(blockNumberN+1));
//console.log(blockNumberN, blockHeaderNp1);
await
c
.
InitiateChallenge
(...
args
)
})
})
\ No newline at end of file
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