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
71a65cba
Commit
71a65cba
authored
Oct 06, 2021
by
George Hotz
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
colored print
parent
e43c4d25
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
68 additions
and
20 deletions
+68
-20
go.mod
mipsevm/go.mod
+4
-1
go.sum
mipsevm/go.sum
+11
-0
main.go
mipsevm/main.go
+9
-6
mipsevm.go
mipsevm/mipsevm.go
+1
-1
unicorn.go
mipsevm/unicorn.go
+43
-12
No files found.
mipsevm/go.mod
View file @
71a65cba
...
...
@@ -7,8 +7,11 @@ replace github.com/ethereum/go-ethereum => ../minigeth
require (
github.com/btcsuite/btcd v0.22.0-beta // indirect
github.com/ethereum/go-ethereum v1.10.8 // indirect
github.com/fatih/color v1.13.0 // indirect
github.com/holiman/uint256 v1.2.0 // indirect
github.com/mattn/go-colorable v0.1.9 // indirect
github.com/mattn/go-isatty v0.0.14 // indirect
github.com/unicorn-engine/unicorn v0.0.0-20211005173419-3fadb5aa5aad // indirect
golang.org/x/crypto v0.0.0-20210817164053-32db794688a5 // indirect
golang.org/x/sys v0.0.0-202106
15035016-665e8c7367d1
// indirect
golang.org/x/sys v0.0.0-202106
30005230-0f9fa26af87c
// indirect
)
mipsevm/go.sum
View file @
71a65cba
...
...
@@ -16,6 +16,8 @@ github.com/davecgh/go-spew v0.0.0-20171005155431-ecdeabc65495/go.mod h1:J7Y8YcW2
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/decred/dcrd/lru v1.0.0/go.mod h1:mxKOwFd7lFjN2GZYsiz/ecgqR6kkYAl+0pz0tEMk218=
github.com/fatih/color v1.13.0 h1:8LOYc1KYPPmyKMuN8QV2DNRWNbLo6LZ0iLs8+mlH53w=
github.com/fatih/color v1.13.0/go.mod h1:kLAiJbzzSOZDVNGyDpeOxJ47H46qBXwg5ILebYFFOfk=
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
github.com/holiman/uint256 v1.2.0 h1:gpSYcPLWGv4sG43I2mVLiDZCNDh/EpGjSk8tmtxitHM=
...
...
@@ -25,6 +27,11 @@ github.com/jessevdk/go-flags v0.0.0-20141203071132-1679536dcc89/go.mod h1:4FA24M
github.com/jessevdk/go-flags v1.4.0/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI=
github.com/jrick/logrotate v1.0.0/go.mod h1:LNinyqDIJnpAur+b8yyulnQw/wDuN1+BYKlTRt3OuAQ=
github.com/kkdai/bstream v0.0.0-20161212061736-f391b8402d23/go.mod h1:J+Gs4SYgM6CZQHDETBtE9HaSEkGmuNXF86RwHhHUvq4=
github.com/mattn/go-colorable v0.1.9 h1:sqDoxXbdeALODt0DAeJCVp38ps9ZogZEAXjus69YV3U=
github.com/mattn/go-colorable v0.1.9/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc=
github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU=
github.com/mattn/go-isatty v0.0.14 h1:yVuAays6BHfxijgZPzw+3Zlu5yQgKGP2/hcQbHb7S9Y=
github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94=
github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
github.com/onsi/ginkgo v1.7.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
github.com/onsi/gomega v1.4.1/go.mod h1:C1qb7wdrVGGVU+Z6iS04AVkA3Q65CEZX59MT0QO5uiA=
...
...
@@ -44,8 +51,12 @@ golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJ
golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1 h1:SrN+KX8Art/Sf4HNj6Zcz06G7VEz+7w9tdXTPOZ7+l4=
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c h1:F1jZWGFhYfh0Ci55sIpILtKKK8p3i2/krTr0H1rg74I=
golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys=
...
...
mipsevm/main.go
View file @
71a65cba
...
...
@@ -13,7 +13,10 @@ import (
func
LoadMappedFile
(
fn
string
,
ram
map
[
uint32
](
uint32
),
base
uint32
)
{
dat
,
_
:=
ioutil
.
ReadFile
(
fn
)
for
i
:=
0
;
i
<
len
(
dat
);
i
+=
4
{
ram
[
base
+
uint32
(
i
)]
=
binary
.
BigEndian
.
Uint32
(
dat
[
i
:
i
+
4
])
value
:=
binary
.
BigEndian
.
Uint32
(
dat
[
i
:
i
+
4
])
if
value
!=
0
{
ram
[
base
+
uint32
(
i
)]
=
value
}
}
}
...
...
@@ -42,16 +45,16 @@ func runTest(fn string, steps int, debug int) (uint32, uint64) {
}
func
main
()
{
steps
,
_
:=
strconv
.
Atoi
(
os
.
Getenv
(
"STEPS"
))
if
steps
==
0
{
steps
=
1000000
}
if
len
(
os
.
Args
)
>
1
{
if
os
.
Args
[
1
]
==
"../mipigeth/minigeth.bin"
{
debug
,
_
:=
strconv
.
Atoi
(
os
.
Getenv
(
"DEBUG"
))
steps
,
_
:=
strconv
.
Atoi
(
os
.
Getenv
(
"STEPS"
))
if
steps
==
0
{
steps
=
100000
}
RunMinigeth
(
os
.
Args
[
1
],
steps
,
debug
)
}
else
if
os
.
Args
[
1
]
==
"unicorn"
{
RunUnicorn
(
os
.
Args
[
2
])
RunUnicorn
(
os
.
Args
[
2
]
,
steps
)
}
else
{
runTest
(
os
.
Args
[
1
],
20
,
2
)
}
...
...
mipsevm/mipsevm.go
View file @
71a65cba
...
...
@@ -87,7 +87,7 @@ func (s *StateDB) GetState(fakeaddr common.Address, hash common.Hash) common.Has
}
if
(
pcCount
%
10000
)
==
0
{
steps_per_sec
:=
float64
(
pcCount
)
*
1e9
/
float64
(
time
.
Now
()
.
Sub
(
ministart
)
.
Nanoseconds
())
os
.
Stderr
.
WriteString
(
fmt
.
Sprintf
(
"
step %7d steps per s %f ram entries %d
\n
"
,
pcCount
,
steps_per_sec
,
len
(
ram
)))
os
.
Stderr
.
WriteString
(
fmt
.
Sprintf
(
"
%10d pc: %x steps per s %f ram entries %d
\n
"
,
pcCount
,
nret
&
0x7FFFFFFF
,
steps_per_sec
,
len
(
ram
)))
}
pcCount
+=
1
seenWrite
=
false
...
...
mipsevm/unicorn.go
View file @
71a65cba
...
...
@@ -9,6 +9,7 @@ import (
"time"
"github.com/ethereum/go-ethereum/common"
"github.com/fatih/color"
uc
"github.com/unicorn-engine/unicorn/bindings/go/unicorn"
)
...
...
@@ -26,7 +27,7 @@ func RegRead(u *uc.Unicorn, reg int) {
}
// reimplement simple.py in go
func
RunUnicorn
(
fn
string
)
{
func
RunUnicorn
(
fn
string
,
totalSteps
int
)
{
mu
,
err
:=
uc
.
NewUnicorn
(
uc
.
ARCH_MIPS
,
uc
.
MODE_32
|
uc
.
MODE_BIG_ENDIAN
)
check
(
err
)
...
...
@@ -46,10 +47,18 @@ func RunUnicorn(fn string) {
mu
.
MemWrite
(
0x31000000
,
tmp
)
mu
.
MemWrite
(
0x31000004
,
value
)
}
else
if
syscall_no
==
4004
{
fd
,
_
:=
mu
.
RegRead
(
uc
.
MIPS_REG_A0
)
buf
,
_
:=
mu
.
RegRead
(
uc
.
MIPS_REG_A1
)
count
,
_
:=
mu
.
RegRead
(
uc
.
MIPS_REG_A2
)
bytes
,
_
:=
mu
.
MemRead
(
buf
,
count
)
os
.
Stderr
.
Write
(
bytes
)
printer
:=
color
.
New
(
color
.
FgWhite
)
.
SprintFunc
()
if
fd
==
1
{
printer
=
color
.
New
(
color
.
FgGreen
)
.
SprintFunc
()
}
else
if
fd
==
2
{
printer
=
color
.
New
(
color
.
FgRed
)
.
SprintFunc
()
}
os
.
Stderr
.
WriteString
(
printer
(
string
(
bytes
)))
}
else
if
syscall_no
==
4090
{
a0
,
_
:=
mu
.
RegRead
(
uc
.
MIPS_REG_A0
)
sz
,
_
:=
mu
.
RegRead
(
uc
.
MIPS_REG_A1
)
...
...
@@ -68,16 +77,34 @@ func RunUnicorn(fn string) {
}
mu
.
RegWrite
(
uc
.
MIPS_REG_V0
,
v0
)
mu
.
RegWrite
(
uc
.
MIPS_REG_A3
,
0
)
},
1
,
0
)
},
0
,
0
)
ministart
:=
time
.
Now
()
mu
.
HookAdd
(
uc
.
HOOK_CODE
,
func
(
mu
uc
.
Unicorn
,
addr
uint64
,
size
uint32
)
{
if
steps
%
1000000
==
0
{
steps_per_sec
:=
float64
(
steps
)
*
1e9
/
float64
(
time
.
Now
()
.
Sub
(
ministart
)
.
Nanoseconds
())
fmt
.
Printf
(
"%6d Code: 0x%x, 0x%x steps per s %f
\n
"
,
steps
,
addr
,
size
,
steps_per_sec
)
}
steps
+=
1
},
1
,
0
)
slowMode
:=
true
ram
:=
make
(
map
[
uint32
](
uint32
))
if
slowMode
{
mu
.
HookAdd
(
uc
.
HOOK_MEM_WRITE
,
func
(
mu
uc
.
Unicorn
,
access
int
,
addr
uint64
,
size
int
,
value
int64
)
{
//fmt.Printf("%X(%d) = %x\n", addr, size, value)
// TODO: fix unaligned access
if
value
==
0
{
delete
(
ram
,
uint32
(
addr
))
}
else
{
ram
[
uint32
(
addr
)]
=
uint32
(
value
)
}
},
0
,
0x80000000
)
ministart
:=
time
.
Now
()
mu
.
HookAdd
(
uc
.
HOOK_CODE
,
func
(
mu
uc
.
Unicorn
,
addr
uint64
,
size
uint32
)
{
if
steps
%
1000000
==
0
{
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
))
}
steps
+=
1
if
totalSteps
==
steps
{
os
.
Exit
(
0
)
}
},
0
,
0x80000000
)
}
check
(
mu
.
MemMap
(
0
,
0x80000000
))
...
...
@@ -86,9 +113,13 @@ func RunUnicorn(fn string) {
mu
.
MemWrite
(
0
,
dat
)
// inputs
inputs
,
_
:=
ioutil
.
ReadFile
(
fmt
.
Sprintf
(
"/tmp/eth/%d"
,
13284469
))
inputFile
:=
fmt
.
Sprintf
(
"/tmp/eth/%d"
,
13284469
)
inputs
,
_
:=
ioutil
.
ReadFile
(
inputFile
)
mu
.
MemWrite
(
0x30000000
,
inputs
)
LoadMappedFile
(
fn
,
ram
,
0
)
LoadMappedFile
(
inputFile
,
ram
,
0x30000000
)
mu
.
Start
(
0
,
0xdead0000
)
}
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