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
7c3b3af0
Commit
7c3b3af0
authored
3 years ago
by
George Hotz
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
allow mipsevm to use both unicorn and the evm
parent
20d6c36d
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
43 additions
and
26 deletions
+43
-26
test_challenge.yml
.github/workflows/test_challenge.yml
+1
-1
main.go
mipsevm/main.go
+41
-24
run_unicorn.go
mipsevm/run_unicorn.go
+1
-1
No files found.
.github/workflows/test_challenge.yml
View file @
7c3b3af0
...
...
@@ -34,6 +34,6 @@ jobs:
cd mipsevm
go build
-
name
:
Generate checkpoints for
13284469
run
:
mipsevm
/mipsevm
13284469
run
:
cd mipsevm && .
/mipsevm
13284469
-
name
:
Run test challenge
run
:
npx hardhat test test/challenge_test.js
This diff is collapsed.
Click to expand it.
mipsevm/main.go
View file @
7c3b3af0
...
...
@@ -26,39 +26,56 @@ func main() {
if
len
(
os
.
Args
)
>
2
{
target
,
_
=
strconv
.
Atoi
(
os
.
Args
[
2
])
}
evm
:=
false
if
len
(
os
.
Args
)
>
3
&&
os
.
Args
[
3
]
==
"evm"
{
evm
=
true
}
// step 1, generate the checkpoints every million steps using unicorn
ram
:=
make
(
map
[
uint32
](
uint32
))
lastStep
:=
0
mu
:=
GetHookedUnicorn
(
root
,
ram
,
func
(
step
int
,
mu
uc
.
Unicorn
,
ram
map
[
uint32
](
uint32
))
{
// this can be raised to 10,000,000 if the files are too large
if
step
%
10000000
==
0
||
step
==
target
{
SyncRegs
(
mu
,
ram
)
fn
:=
fmt
.
Sprintf
(
"%s/checkpoint_%d.json"
,
root
,
step
)
WriteCheckpoint
(
ram
,
fn
,
step
)
if
step
==
target
{
// done
mu
.
RegWrite
(
uc
.
MIPS_REG_PC
,
0x5ead0004
)
lastStep
:=
1
if
evm
{
ZeroRegisters
(
ram
)
LoadMappedFile
(
"../mipigo/minigeth.bin"
,
ram
,
0
)
WriteCheckpoint
(
ram
,
"/tmp/cannon/golden.json"
,
-
1
)
LoadMappedFile
(
fmt
.
Sprintf
(
"%s/input"
,
root
),
ram
,
0x30000000
)
RunWithRam
(
ram
,
target
-
1
,
0
,
nil
)
lastStep
+=
target
-
1
fn
:=
fmt
.
Sprintf
(
"%s/checkpoint_%d.json"
,
root
,
lastStep
)
WriteCheckpoint
(
ram
,
fn
,
lastStep
)
}
else
{
mu
:=
GetHookedUnicorn
(
root
,
ram
,
func
(
lstep
int
,
mu
uc
.
Unicorn
,
ram
map
[
uint32
](
uint32
))
{
step
:=
lstep
+
1
// this can be raised to 10,000,000 if the files are too large
if
step
%
10000000
==
0
||
step
==
target
{
SyncRegs
(
mu
,
ram
)
fn
:=
fmt
.
Sprintf
(
"%s/checkpoint_%d.json"
,
root
,
step
)
WriteCheckpoint
(
ram
,
fn
,
step
)
if
step
==
target
{
// done
mu
.
RegWrite
(
uc
.
MIPS_REG_PC
,
0x5ead0004
)
}
}
lastStep
=
step
})
ZeroRegisters
(
ram
)
// not ready for golden yet
LoadMappedFileUnicorn
(
mu
,
"../mipigo/minigeth.bin"
,
ram
,
0
)
WriteCheckpoint
(
ram
,
"/tmp/cannon/golden.json"
,
-
1
)
if
root
==
""
{
fmt
.
Println
(
"exiting early without a block number"
)
os
.
Exit
(
0
)
}
lastStep
=
step
})
ZeroRegisters
(
ram
)
// not ready for golden yet
LoadMappedFileUnicorn
(
mu
,
"mipigo/minigeth.bin"
,
ram
,
0
)
WriteCheckpoint
(
ram
,
"/tmp/cannon/golden.json"
,
-
1
)
if
root
==
""
{
fmt
.
Println
(
"exiting early without a block number"
)
os
.
Exit
(
0
)
}
// TODO: this is actually step 0->1. Renumber as appropriate
LoadMappedFileUnicorn
(
mu
,
fmt
.
Sprintf
(
"%s/input"
,
root
),
ram
,
0x30000000
)
// TODO: this is actually step 0->1. Renumber as appropriate
LoadMappedFileUnicorn
(
mu
,
fmt
.
Sprintf
(
"%s/input"
,
root
),
ram
,
0x30000000
)
mu
.
Start
(
0
,
0x5ead0004
)
SyncRegs
(
mu
,
ram
)
}
mu
.
Start
(
0
,
0x5ead0004
)
SyncRegs
(
mu
,
ram
)
if
target
==
-
1
{
WriteCheckpoint
(
ram
,
fmt
.
Sprintf
(
"%s/checkpoint_final.json"
,
root
),
lastStep
)
}
...
...
This diff is collapsed.
Click to expand it.
mipsevm/run_unicorn.go
View file @
7c3b3af0
...
...
@@ -20,7 +20,7 @@ func check(err error) {
}
}
var
steps
int
=
1
var
steps
int
=
0
var
heap_start
uint64
=
0
func
WriteBytes
(
fd
int
,
bytes
[]
byte
)
{
...
...
This diff is collapsed.
Click to expand it.
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