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
3e56fb71
Commit
3e56fb71
authored
Dec 10, 2021
by
George Hotz
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
support dynamically posting the hashes
parent
dd005b78
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
48 additions
and
9 deletions
+48
-9
lib.js
scripts/lib.js
+14
-1
mips_test_execwtrie_dynamic.js
test/mips_test_execwtrie_dynamic.js
+34
-8
No files found.
scripts/lib.js
View file @
3e56fb71
...
...
@@ -56,6 +56,14 @@ async function deployed() {
return
[
c
,
m
,
mm
]
}
class
MissingHashError
extends
Error
{
constructor
(
hash
,
offset
)
{
super
(
"
hash is missing
"
)
this
.
hash
=
hash
this
.
offset
=
offset
}
}
async
function
getTrieNodesForCall
(
c
,
caddress
,
cdat
,
preimages
)
{
let
nodes
=
[]
while
(
1
)
{
...
...
@@ -83,6 +91,11 @@ async function getTrieNodesForCall(c, caddress, cdat, preimages) {
const
bin
=
Uint8Array
.
from
(
Buffer
.
from
(
node
,
'
base64
'
).
toString
(
'
binary
'
),
c
=>
c
.
charCodeAt
(
0
))
nodes
.
push
(
bin
)
continue
}
else
if
(
missing
!==
undefined
&&
missing
.
length
==
128
)
{
let
hash
=
missing
.
slice
(
0
,
64
)
let
offset
=
parseInt
(
missing
.
slice
(
64
,
128
),
16
)
console
.
log
(
"
requested hash oracle
"
,
hash
,
offset
)
throw
new
MissingHashError
(
hash
,
offset
)
}
else
{
console
.
log
(
e
)
break
...
...
@@ -120,4 +133,4 @@ async function writeMemory(mm, root, addr, data, bytes32=false) {
return
root
}
module
.
exports
=
{
deploy
,
deployed
,
getTrieNodesForCall
,
getBlockRlp
,
getTrieAtStep
,
writeMemory
}
module
.
exports
=
{
deploy
,
deployed
,
getTrieNodesForCall
,
getBlockRlp
,
getTrieAtStep
,
writeMemory
,
MissingHashError
}
test/mips_test_execwtrie_dynamic.js
View file @
3e56fb71
const
fs
=
require
(
"
fs
"
)
const
{
expect
}
=
require
(
"
chai
"
)
const
{
deploy
,
getTrieNodesForCall
}
=
require
(
"
../scripts/lib
"
)
const
{
deploy
,
getTrieNodesForCall
,
MissingHashError
}
=
require
(
"
../scripts/lib
"
)
const
trieAdd
=
{
"
root
"
:
"
0x22ffce7c56d926c2d8d6337d8917fa0e1880e1869e189c15385ead63c6c45b93
"
,
"
preimages
"
:{
"
0x044371dc86fb8c621bc84b69dce16de366de1126777250888b17416d0bd11279
"
:
"
+FPGIIQ8EL//xiCENhD/8MYghDQRAAHGIIQ8CP//xiCENQj//cYghDQJAAPGIIQBCVAgxiCELUIAAcYghK4CAAjGIISuEQAExiCEA+AACICAgICAgA==
"
,
"
0x0fdfcc24b1b21d78ef2b7c6503eb9354677743685c2d00a14a8b502a177911b0
"
:
"
+HGgL4Jb+u0gEWM4e9G4lO/GsyUEY/heVoGOAfiI04qPXfSgLCZprT7WBOLipiwJxxI0vy09rw9iPR+x0p/Xz1p3X5WgaNY/x30waJPsd6PWg76b094l8vUmmL6XB1XdUFy+xfWAgICAgICAgICAgICAgA==
"
,
"
0x11228d4f4a028a9088e6ec0aa6513e0d4731d9dc488e2af1957e46ba80624a69
"
:
"
5oQAAAAAoARDcdyG+4xiG8hLadzhbeNm3hEmd3JQiIsXQW0L0RJ5
"
,
"
0x22ffce7c56d926c2d8d6337d8917fa0e1880e1869e189c15385ead63c6c45b93
"
:
"
+FGgESKNT0oCipCI5uwKplE+DUcx2dxIjirxlX5GuoBiSmmAgKBv5gezlmGtxjQAs8Du76D93mAxExw5qWgAZjJQp1xmfICAgICAgICAgICAgIA=
"
,
"
0x2c2669ad3ed604e2e2a62c09c71234bf2d3daf0f623d1fb1d29fd7cf5a775f95
"
:
"
+HHGIIQAAAAAxiCEAAAAAMYghAAAAADGIIQAAAAAxiCEAAAAAMYghAAAAADGIIQAAAAAxiCEAAAAAMYghAAAAADGIIQAAAAAxiCEAAAAAMYghAAAAADGIIQAAAAAxiCEAAAAAMYghAAAAADGIIRerQAAgA==
"
,
"
0x2f825bfaed201163387bd1b894efc6b3250463f85e56818e01f888d38a8f5df4
"
:
"
+HHGIIQAAAAAxiCEAAAAAMYghAAAAADGIIQAAAAAxiCEAAAAAMYghAAAAADGIIQAAAAAxiCEAAAAAMYghAAAAADGIIQAAAAAxiCEAAAAAMYghAAAAADGIIQAAAAAxiCEAAAAAMYghAAAAADGIIQAAAAAgA==
"
,
"
0x68d63fc77d306893ec77a3d683be9bd3de25f2f52698be970755dd505cbec5f5
"
:
"
6cYghAAAAADGIIQAAAAAxiCEAAAAAMYghAAAAACAgICAgICAgICAgICA
"
,
"
0x6fe607b39661adc63400b3c0eeefa0fdde6031131c39a96800663250a75c667c
"
:
"
5YMQAACgD9/MJLGyHXjvK3xlA+uTVGd3Q2hcLQChSotQKhd5EbA=
"
}};
const
trieOracle
=
{
"
root
"
:
"
0x26595bd4f73f14273d9f43f0c5253eef964f4581d5e293cded54d23f1cf3db5f
"
,
"
step
"
:
-
1
,
"
preimages
"
:{
"
0x0fdfcc24b1b21d78ef2b7c6503eb9354677743685c2d00a14a8b502a177911b0
"
:
"
+HGgL4Jb+u0gEWM4e9G4lO/GsyUEY/heVoGOAfiI04qPXfSgLCZprT7WBOLipiwJxxI0vy09rw9iPR+x0p/Xz1p3X5WgaNY/x30waJPsd6PWg76b094l8vUmmL6XB1XdUFy+xfWAgICAgICAgICAgICAgA==
"
,
"
0x16e7f9821e0a3a2fc92d337f6d269c4c0ddb4d5c10a04b49d368643c9818ec1d
"
:
"
5YMQAACgoLKCLk7kk3rBB2CtW7YQizz670HG0TNCobpfs/1MJqs=
"
,
"
0x26595bd4f73f14273d9f43f0c5253eef964f4581d5e293cded54d23f1cf3db5f
"
:
"
+FGgFuf5gh4KOi/JLTN/bSacTA3bTVwQoEtJ02hkPJgY7B2AgKBv5gezlmGtxjQAs8Du76D93mAxExw5qWgAZjJQp1xmfICAgICAgICAgICAgIA=
"
,
"
0x2c2669ad3ed604e2e2a62c09c71234bf2d3daf0f623d1fb1d29fd7cf5a775f95
"
:
"
+HHGIIQAAAAAxiCEAAAAAMYghAAAAADGIIQAAAAAxiCEAAAAAMYghAAAAADGIIQAAAAAxiCEAAAAAMYghAAAAADGIIQAAAAAxiCEAAAAAMYghAAAAADGIIQAAAAAxiCEAAAAAMYghAAAAADGIIRerQAAgA==
"
,
"
0x2f825bfaed201163387bd1b894efc6b3250463f85e56818e01f888d38a8f5df4
"
:
"
+HHGIIQAAAAAxiCEAAAAAMYghAAAAADGIIQAAAAAxiCEAAAAAMYghAAAAADGIIQAAAAAxiCEAAAAAMYghAAAAADGIIQAAAAAxiCEAAAAAMYghAAAAADGIIQAAAAAxiCEAAAAAMYghAAAAADGIIQAAAAAgA==
"
,
"
0x65c024ed3b68b3f86a44f6af5179e4ad055ac046ac2e954355d476c611947b16
"
:
"
+HHGIISuCAAQxiCEPAhCpcYghDUI7F/GIISuCAAUxiCEPAgDu8YghDUI+iXGIISuCAAYxiCEPAhMsMYghDUIH63GIISuCAAcxiCEJAIPtMYghAAAAAzGIIQ8ETEAxiCEjigAAMYghCQMAAvGIIQBDGgjgA==
"
,
"
0x68d63fc77d306893ec77a3d683be9bd3de25f2f52698be970755dd505cbec5f5
"
:
"
6cYghAAAAADGIIQAAAAAxiCEAAAAAMYghAAAAACAgICAgICAgICAgICA
"
,
"
0x6fe607b39661adc63400b3c0eeefa0fdde6031131c39a96800663250a75c667c
"
:
"
5YMQAACgD9/MJLGyHXjvK3xlA+uTVGd3Q2hcLQChSotQKhd5EbA=
"
,
"
0x8cd6ed962850eebdb5bf360b496b5ab3425659a8ba3d115d5bb71055981a6bc2
"
:
"
+F/GIIQtogABxiCEjigABMYghDwMaGXGIIQ1jGxsxiCEAQxoI8YghC2jAAHGIIQAQxAkxiCEPBC//8YghDYQ//DGIIQ0EQABxiCErgIACMYghK4RAATGIIQD4AAIgICAgA==
"
,
"
0xa0b2822e4ee4937ac10760ad5bb6108b3cfaef41c6d13342a1ba5fb3fd4c26ab
"
:
"
+HGgt8fQkZe4faINYK98tz2Czvb1LZ/LaDPtw0E2aioQ4lagZcAk7Ttos/hqRPavUXnkrQVawEasLpVDVdR2xhGUexagjNbtlihQ7r21vzYLSWtas0JWWai6PRFdW7cQVZgaa8KAgICAgICAgICAgICAgA==
"
,
"
0xb7c7d09197b87da20d60af7cb73d82cef6f52d9fcb6833edc341366a2a10e256
"
:
"
+HHGIIQ8EDAAxiCENhAQAMYghDwIRxfGIIQ1CDKFxiCErggAAMYghDwIqNfGIIQ1CDQexiCErggABMYghDwIXpfGIIQ1CC/GxiCErggACMYghDwIdyjGIIQ1CGOExiCErggADMYghDwI+ALGIIQ1CPjvgA==
"
}};
async
function
dynamicExecWithTrie
(
c
,
m
,
mm
,
root
,
preimages
)
{
async
function
dynamicExecWithTrie
(
c
,
m
,
mm
,
root
,
preimages
,
rootdir
)
{
let
mdat
=
m
.
interface
.
encodeFunctionData
(
"
Step
"
,
[
root
])
let
nodes
=
await
getTrieNodesForCall
(
c
,
m
.
address
,
mdat
,
preimages
)
let
nodes
while
(
true
)
{
try
{
nodes
=
await
getTrieNodesForCall
(
c
,
m
.
address
,
mdat
,
preimages
)
}
catch
(
err
)
{
if
(
err
instanceof
MissingHashError
)
{
let
value
=
fs
.
readFileSync
(
rootdir
+
"
0x
"
+
err
.
hash
)
console
.
log
(
"
handling hash oracle request
"
)
await
mm
.
AddPreimage
(
value
,
err
.
offset
)
continue
}
else
{
throw
err
}
}
break
}
for
(
n
of
nodes
)
{
await
mm
.
AddTrieNode
(
n
)
...
...
@@ -24,22 +43,29 @@ async function dynamicExecWithTrie(c, m, mm, root, preimages) {
// really a copy of mips_test_execwtrie
describe
(
"
Exec with trie dynamic
"
,
function
()
{
beforeEach
(
async
function
()
{
[
c
,
m
,
mm
]
=
await
deploy
()
const
MIPS
=
await
ethers
.
getContractFactory
(
"
MIPS
"
)
m
=
await
MIPS
.
deploy
()
mm
=
await
ethers
.
getContractAt
(
"
MIPSMemory
"
,
await
m
.
m
())
// fake challenge for use of getTrieNodesForCall
const
Challenge
=
await
ethers
.
getContractFactory
(
"
Challenge
"
)
const
fakeGoldenHash
=
'
0x0000000000000000000000000000000000000000000000000000000000000000
'
c
=
await
Challenge
.
deploy
(
m
.
address
,
fakeGoldenHash
)
})
it
(
"
add should work
"
,
async
function
()
{
let
root
=
trieAdd
[
'
root
'
]
for
(
let
i
=
0
;
i
<
12
;
i
++
)
{
root
=
await
dynamicExecWithTrie
(
c
,
m
,
mm
,
root
,
trieAdd
[
'
preimages
'
])
root
=
await
dynamicExecWithTrie
(
c
,
m
,
mm
,
root
,
trieAdd
[
'
preimages
'
]
,
nil
)
console
.
log
(
i
,
root
)
}
})
/*
it("oracle should work", async function () {
it
(
"
oracle should work
"
,
async
function
()
{
let
root
=
trieOracle
[
'
root
'
]
let
pc
=
0
,
out1
,
out2
while
(
pc
!=
0x5ead0000
)
{
root = await dynamicExecWithTrie(c, m, mm, root, trieOracle['preimages'])
root
=
await
dynamicExecWithTrie
(
c
,
m
,
mm
,
root
,
trieOracle
[
'
preimages
'
]
,
"
mipsevm/testoracle/
"
)
pc
=
await
mm
.
ReadMemory
(
root
,
0xc0000080
)
out1
=
await
mm
.
ReadMemory
(
root
,
0xbffffff4
)
...
...
@@ -48,5 +74,5 @@ describe("Exec with trie dynamic", function () {
}
expect
(
out1
).
to
.
equal
(
1
)
expect
(
out2
).
to
.
equal
(
1
)
}).timeout(120000)
*/
}).
timeout
(
120000
)
})
\ 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