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
3e9acb85
Commit
3e9acb85
authored
Oct 31, 2021
by
George Hotz
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
a bit simpler
parent
eaa6641c
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
12 additions
and
15 deletions
+12
-15
compare_unievm_test.go
mipsevm/compare_unievm_test.go
+6
-1
mips_run_test.go
mipsevm/mips_run_test.go
+1
-1
unicorn.go
mipsevm/unicorn.go
+5
-13
No files found.
mipsevm/compare_unievm_test.go
View file @
3e9acb85
...
@@ -49,11 +49,16 @@ func TestCompareUnicornEvm(t *testing.T) {
...
@@ -49,11 +49,16 @@ func TestCompareUnicornEvm(t *testing.T) {
})
})
uniram
:=
make
(
map
[
uint32
](
uint32
))
uniram
:=
make
(
map
[
uint32
](
uint32
))
go
RunUnicorn
(
fn
,
uniram
,
true
,
false
,
func
(
step
int
,
mu
uc
.
Unicorn
,
ram
map
[
uint32
](
uint32
))
{
ministart
:=
time
.
Now
()
go
RunUnicorn
(
fn
,
uniram
,
false
,
func
(
step
int
,
mu
uc
.
Unicorn
,
ram
map
[
uint32
](
uint32
))
{
SyncRegs
(
mu
,
ram
)
SyncRegs
(
mu
,
ram
)
cuni
<-
RegSerialize
(
ram
)
cuni
<-
RegSerialize
(
ram
)
done
.
Lock
()
done
.
Lock
()
done
.
Unlock
()
done
.
Unlock
()
if
step
%
1000000
==
0
{
steps_per_sec
:=
float64
(
step
)
*
1e9
/
float64
(
time
.
Now
()
.
Sub
(
ministart
)
.
Nanoseconds
())
fmt
.
Printf
(
"%10d pc: %x steps per s %f ram entries %d
\n
"
,
step
,
ram
[
0xc0000080
],
steps_per_sec
,
len
(
ram
))
}
// halt at steps
// halt at steps
if
step
==
steps
{
if
step
==
steps
{
mu
.
RegWrite
(
uc
.
MIPS_REG_PC
,
0x5ead0004
)
mu
.
RegWrite
(
uc
.
MIPS_REG_PC
,
0x5ead0004
)
...
...
mipsevm/mips_run_test.go
View file @
3e9acb85
...
@@ -10,7 +10,7 @@ import (
...
@@ -10,7 +10,7 @@ import (
func
TestMinigethUnicorn
(
t
*
testing
.
T
)
{
func
TestMinigethUnicorn
(
t
*
testing
.
T
)
{
uniram
:=
make
(
map
[
uint32
](
uint32
))
uniram
:=
make
(
map
[
uint32
](
uint32
))
RunUnicorn
(
"../mipigo/minigeth.bin"
,
uniram
,
false
,
true
,
nil
)
RunUnicorn
(
"../mipigo/minigeth.bin"
,
uniram
,
true
,
nil
)
}
}
func
TestSimpleEVM
(
t
*
testing
.
T
)
{
func
TestSimpleEVM
(
t
*
testing
.
T
)
{
...
...
mipsevm/unicorn.go
View file @
3e9acb85
...
@@ -7,7 +7,6 @@ import (
...
@@ -7,7 +7,6 @@ import (
"io/ioutil"
"io/ioutil"
"log"
"log"
"os"
"os"
"time"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common"
"github.com/fatih/color"
"github.com/fatih/color"
...
@@ -70,7 +69,7 @@ func SyncRegs(mu uc.Unicorn, ram map[uint32](uint32)) {
...
@@ -70,7 +69,7 @@ func SyncRegs(mu uc.Unicorn, ram map[uint32](uint32)) {
WriteRam
(
ram
,
REG_HEAP
,
uint32
(
heap_start
))
WriteRam
(
ram
,
REG_HEAP
,
uint32
(
heap_start
))
}
}
func
GetHookedUnicorn
(
root
string
,
ram
map
[
uint32
](
uint32
),
slowMode
bool
,
callback
func
(
int
,
uc
.
Unicorn
,
map
[
uint32
](
uint32
)))
uc
.
Unicorn
{
func
GetHookedUnicorn
(
root
string
,
ram
map
[
uint32
](
uint32
),
callback
func
(
int
,
uc
.
Unicorn
,
map
[
uint32
](
uint32
)))
uc
.
Unicorn
{
mu
,
err
:=
uc
.
NewUnicorn
(
uc
.
ARCH_MIPS
,
uc
.
MODE_32
|
uc
.
MODE_BIG_ENDIAN
)
mu
,
err
:=
uc
.
NewUnicorn
(
uc
.
ARCH_MIPS
,
uc
.
MODE_32
|
uc
.
MODE_BIG_ENDIAN
)
check
(
err
)
check
(
err
)
...
@@ -125,7 +124,7 @@ func GetHookedUnicorn(root string, ram map[uint32](uint32), slowMode bool, callb
...
@@ -125,7 +124,7 @@ func GetHookedUnicorn(root string, ram map[uint32](uint32), slowMode bool, callb
mu
.
RegWrite
(
uc
.
MIPS_REG_A3
,
0
)
mu
.
RegWrite
(
uc
.
MIPS_REG_A3
,
0
)
},
0
,
0
)
},
0
,
0
)
if
slowMode
{
if
callback
!=
nil
{
mu
.
HookAdd
(
uc
.
HOOK_MEM_WRITE
,
func
(
mu
uc
.
Unicorn
,
access
int
,
addr64
uint64
,
size
int
,
value
int64
)
{
mu
.
HookAdd
(
uc
.
HOOK_MEM_WRITE
,
func
(
mu
uc
.
Unicorn
,
access
int
,
addr64
uint64
,
size
int
,
value
int64
)
{
rt
:=
value
rt
:=
value
rs
:=
addr64
&
3
rs
:=
addr64
&
3
...
@@ -149,15 +148,8 @@ func GetHookedUnicorn(root string, ram map[uint32](uint32), slowMode bool, callb
...
@@ -149,15 +148,8 @@ func GetHookedUnicorn(root string, ram map[uint32](uint32), slowMode bool, callb
},
0
,
0x80000000
)
},
0
,
0x80000000
)
ministart
:=
time
.
Now
()
mu
.
HookAdd
(
uc
.
HOOK_CODE
,
func
(
mu
uc
.
Unicorn
,
addr
uint64
,
size
uint32
)
{
mu
.
HookAdd
(
uc
.
HOOK_CODE
,
func
(
mu
uc
.
Unicorn
,
addr
uint64
,
size
uint32
)
{
if
steps
%
1000000
==
0
&&
false
{
callback
(
steps
,
mu
,
ram
)
steps_per_sec
:=
float64
(
steps
)
*
1e9
/
float64
(
time
.
Now
()
.
Sub
(
ministart
)
.
Nanoseconds
())
fmt
.
Printf
(
"%10d pc: %x steps per s %f ram entries %d
\n
"
,
steps
,
addr
,
steps_per_sec
,
len
(
ram
))
}
if
callback
!=
nil
{
callback
(
steps
,
mu
,
ram
)
}
steps
+=
1
steps
+=
1
},
0
,
0x80000000
)
},
0
,
0x80000000
)
}
}
...
@@ -166,9 +158,9 @@ func GetHookedUnicorn(root string, ram map[uint32](uint32), slowMode bool, callb
...
@@ -166,9 +158,9 @@ func GetHookedUnicorn(root string, ram map[uint32](uint32), slowMode bool, callb
}
}
// reimplement simple.py in go
// reimplement simple.py in go
func
RunUnicorn
(
fn
string
,
ram
map
[
uint32
](
uint32
),
slowMode
bool
,
checkIO
bool
,
callback
func
(
int
,
uc
.
Unicorn
,
map
[
uint32
](
uint32
)))
{
func
RunUnicorn
(
fn
string
,
ram
map
[
uint32
](
uint32
),
checkIO
bool
,
callback
func
(
int
,
uc
.
Unicorn
,
map
[
uint32
](
uint32
)))
{
root
:=
"/tmp/eth/13284469"
root
:=
"/tmp/eth/13284469"
mu
:=
GetHookedUnicorn
(
root
,
ram
,
slowMode
,
callback
)
mu
:=
GetHookedUnicorn
(
root
,
ram
,
callback
)
// loop forever to match EVM
// loop forever to match EVM
//mu.MemMap(0x5ead0000, 0x1000)
//mu.MemMap(0x5ead0000, 0x1000)
...
...
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