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
6c0d0df5
Commit
6c0d0df5
authored
Nov 04, 2021
by
George Hotz
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
mipsevm builds golden
parent
05db1a9b
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
29 additions
and
14 deletions
+29
-14
main.go
mipsevm/main.go
+19
-7
deploy.js
scripts/deploy.js
+1
-0
lib.js
scripts/lib.js
+5
-1
challenge_test.js
test/challenge_test.js
+4
-6
No files found.
mipsevm/main.go
View file @
6c0d0df5
...
...
@@ -3,20 +3,26 @@ package main
import
(
"fmt"
"io/ioutil"
"os"
"strconv"
uc
"github.com/unicorn-engine/unicorn/bindings/go/unicorn"
)
func
WriteCheckpoint
(
ram
map
[
uint32
](
uint32
),
root
string
,
step
int
)
{
func
WriteCheckpoint
(
ram
map
[
uint32
](
uint32
),
fn
string
)
{
trieroot
:=
RamToTrie
(
ram
)
dat
:=
TrieToJson
(
trieroot
)
fn
:=
fmt
.
Sprintf
(
"%s/checkpoint_%d.json"
,
root
,
step
)
fmt
.
Printf
(
"writing %s len %d with root %s
\n
"
,
fn
,
len
(
dat
),
trieroot
)
ioutil
.
WriteFile
(
fn
,
dat
,
0644
)
}
func
main
()
{
root
:=
fmt
.
Sprintf
(
"/tmp/cannon/%d_%d"
,
0
,
13284469
)
root
:=
""
if
len
(
os
.
Args
)
>
1
{
blockNumber
,
_
:=
strconv
.
Atoi
(
os
.
Args
[
1
])
root
=
fmt
.
Sprintf
(
"/tmp/cannon/%d_%d"
,
0
,
blockNumber
)
}
// step 1, generate the checkpoints every million steps using unicorn
ram
:=
make
(
map
[
uint32
](
uint32
))
...
...
@@ -25,20 +31,26 @@ func main() {
// this can be raised to 10,000,000 if the files are too large
if
step
%
10000000
==
0
{
SyncRegs
(
mu
,
ram
)
WriteCheckpoint
(
ram
,
root
,
step
)
fn
:=
fmt
.
Sprintf
(
"%s/checkpoint_%d.json"
,
root
,
step
)
WriteCheckpoint
(
ram
,
fn
)
}
lastStep
=
step
})
ZeroRegisters
(
ram
)
// not ready for golden yet
LoadMappedFileUnicorn
(
mu
,
"../mipigo/minigeth.bin"
,
ram
,
0
)
WriteCheckpoint
(
ram
,
root
,
-
1
)
LoadMappedFileUnicorn
(
mu
,
"mipigo/minigeth.bin"
,
ram
,
0
)
WriteCheckpoint
(
ram
,
"/tmp/cannon/golden.json"
)
if
root
==
""
{
fmt
.
Println
(
"exiting early without a block number"
)
os
.
Exit
(
0
)
}
LoadMappedFileUnicorn
(
mu
,
fmt
.
Sprintf
(
"%s/input"
,
root
),
ram
,
0x30000000
)
mu
.
Start
(
0
,
0x5ead0004
)
SyncRegs
(
mu
,
ram
)
WriteCheckpoint
(
ram
,
root
,
lastStep
)
WriteCheckpoint
(
ram
,
fmt
.
Sprintf
(
"%s/checkpoint_%d.json"
,
root
,
lastStep
)
)
// step 2 (optional), validate each 1 million chunk in EVM
...
...
scripts/deploy.js
View file @
6c0d0df5
...
...
@@ -9,6 +9,7 @@ async function main() {
"
MIPSMemory
"
:
mm
.
address
,
}
console
.
log
(
"
deployed
"
,
json
)
fs
.
writeFileSync
(
"
/tmp/cannon/deployed.json
"
,
JSON
.
stringify
(
json
))
}
main
()
...
...
scripts/lib.js
View file @
6c0d0df5
const
goldenRoot
=
"
0x1f6285b6d372ee187815a8580d1af3ab348cea34abbee18a8e13272454a4c4af
"
const
fs
=
require
(
"
fs
"
)
async
function
deploy
()
{
const
MIPS
=
await
ethers
.
getContractFactory
(
"
MIPS
"
)
const
m
=
await
MIPS
.
deploy
()
const
mm
=
await
ethers
.
getContractAt
(
"
MIPSMemory
"
,
await
m
.
m
())
let
startTrie
=
JSON
.
parse
(
fs
.
readFileSync
(
"
/tmp/cannon/golden.json
"
))
let
goldenRoot
=
startTrie
[
"
root
"
]
console
.
log
(
"
goldenRoot is
"
,
goldenRoot
)
const
Challenge
=
await
ethers
.
getContractFactory
(
"
Challenge
"
)
const
c
=
await
Challenge
.
deploy
(
m
.
address
,
goldenRoot
)
...
...
test/challenge_test.js
View file @
6c0d0df5
...
...
@@ -2,9 +2,6 @@ const { expect } = require("chai")
const
fs
=
require
(
"
fs
"
)
const
{
deploy
}
=
require
(
"
../scripts/lib
"
)
// golden minigeth.bin hash
const
goldenRoot
=
"
0x1f6285b6d372ee187815a8580d1af3ab348cea34abbee18a8e13272454a4c4af
"
describe
(
"
Challenge contract
"
,
function
()
{
beforeEach
(
async
function
()
{
[
c
,
m
,
mm
]
=
await
deploy
()
...
...
@@ -23,13 +20,14 @@ describe("Challenge contract", function () {
const
blockNp1Rlp
=
blockNp1
.
header
.
serialize
()
const
assertionRoot
=
"
0x9e0261efe4509912b8862f3d45a0cb8404b99b239247df9c55871bd3844cebbd
"
const
finalSystemState
=
"
0xf02b4450a07d492c17b4b554851f0dcb12192e2439a507b12fcea8f801a596a6
"
let
startTrie
=
JSON
.
parse
(
fs
.
readFileSync
(
"
/tmp/cannon/0_13284469/checkpoint_-1.json
"
))
let
startTrie
=
JSON
.
parse
(
fs
.
readFileSync
(
"
/tmp/cannon/golden.json
"
))
let
finalTrie
=
JSON
.
parse
(
fs
.
readFileSync
(
"
/tmp/cannon/0_13284469/checkpoint_85059435.json
"
))
const
finalSystemState
=
finalTrie
[
'
root
'
]
while
(
1
)
{
try
{
// TODO: make this eth call?
// needs something like InitiateChallengeWithTrieNodes
await
c
.
InitiateChallenge
(
blockNumberN
,
blockNp1Rlp
,
assertionRoot
,
finalSystemState
,
1
)
break
}
catch
(
e
)
{
...
...
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