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
efabb4c7
Commit
efabb4c7
authored
Oct 06, 2021
by
George Hotz
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
print 4004 in evm syscall
parent
9b8181a2
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
20 additions
and
11 deletions
+20
-11
main.go
mipsevm/main.go
+2
-1
mipsevm.go
mipsevm/mipsevm.go
+9
-0
unicorn.go
mipsevm/unicorn.go
+9
-10
No files found.
mipsevm/main.go
View file @
efabb4c7
...
@@ -7,6 +7,7 @@ import (
...
@@ -7,6 +7,7 @@ import (
"log"
"log"
"os"
"os"
"strconv"
"strconv"
"strings"
"time"
"time"
)
)
...
@@ -50,7 +51,7 @@ func main() {
...
@@ -50,7 +51,7 @@ func main() {
steps
=
1000000
steps
=
1000000
}
}
if
len
(
os
.
Args
)
>
1
{
if
len
(
os
.
Args
)
>
1
{
if
os
.
Args
[
1
]
==
"../mipigeth/minigeth.bin"
{
if
strings
.
HasPrefix
(
os
.
Args
[
1
],
"../mipigeth/"
)
{
debug
,
_
:=
strconv
.
Atoi
(
os
.
Getenv
(
"DEBUG"
))
debug
,
_
:=
strconv
.
Atoi
(
os
.
Getenv
(
"DEBUG"
))
RunMinigeth
(
os
.
Args
[
1
],
steps
,
debug
)
RunMinigeth
(
os
.
Args
[
1
],
steps
,
debug
)
}
else
if
os
.
Args
[
1
]
==
"unicorn"
{
}
else
if
os
.
Args
[
1
]
==
"unicorn"
{
...
...
mipsevm/mipsevm.go
View file @
efabb4c7
...
@@ -84,6 +84,15 @@ func (s *StateDB) GetState(fakeaddr common.Address, hash common.Hash) common.Has
...
@@ -84,6 +84,15 @@ func (s *StateDB) GetState(fakeaddr common.Address, hash common.Hash) common.Has
if
ram
[
nret
]
==
0xC
{
if
ram
[
nret
]
==
0xC
{
syscall
:=
ram
[
0xc0000008
]
syscall
:=
ram
[
0xc0000008
]
os
.
Stderr
.
WriteString
(
fmt
.
Sprintf
(
"syscall %d at %x (step %d)
\n
"
,
syscall
,
nret
,
pcCount
))
os
.
Stderr
.
WriteString
(
fmt
.
Sprintf
(
"syscall %d at %x (step %d)
\n
"
,
syscall
,
nret
,
pcCount
))
if
syscall
==
4004
{
len
:=
int
(
ram
[
0xc0000018
])
buf
:=
make
([]
byte
,
len
+
3
)
for
i
:=
0
;
i
<
len
;
i
+=
4
{
binary
.
BigEndian
.
PutUint32
(
buf
[
i
:
i
+
4
],
ram
[
ram
[
0xc0000014
]
+
uint32
(
i
)])
}
WriteBytes
(
int
(
ram
[
0xc0000010
]),
buf
[
0
:
len
])
//fmt.Printf("%x %x %x\n", ram[0xc0000010], ram[0xc0000014], ram[0xc0000018])
}
}
}
if
(
pcCount
%
10000
)
==
0
{
if
(
pcCount
%
10000
)
==
0
{
steps_per_sec
:=
float64
(
pcCount
)
*
1e9
/
float64
(
time
.
Now
()
.
Sub
(
ministart
)
.
Nanoseconds
())
steps_per_sec
:=
float64
(
pcCount
)
*
1e9
/
float64
(
time
.
Now
()
.
Sub
(
ministart
)
.
Nanoseconds
())
...
...
mipsevm/unicorn.go
View file @
efabb4c7
...
@@ -22,8 +22,14 @@ func check(err error) {
...
@@ -22,8 +22,14 @@ func check(err error) {
var
steps
int
=
0
var
steps
int
=
0
var
heap_start
uint64
=
0
var
heap_start
uint64
=
0
func
RegRead
(
u
*
uc
.
Unicorn
,
reg
int
)
{
func
WriteBytes
(
fd
int
,
bytes
[]
byte
)
{
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
)))
}
}
// reimplement simple.py in go
// reimplement simple.py in go
...
@@ -51,14 +57,7 @@ func RunUnicorn(fn string, totalSteps int) {
...
@@ -51,14 +57,7 @@ func RunUnicorn(fn string, totalSteps int) {
buf
,
_
:=
mu
.
RegRead
(
uc
.
MIPS_REG_A1
)
buf
,
_
:=
mu
.
RegRead
(
uc
.
MIPS_REG_A1
)
count
,
_
:=
mu
.
RegRead
(
uc
.
MIPS_REG_A2
)
count
,
_
:=
mu
.
RegRead
(
uc
.
MIPS_REG_A2
)
bytes
,
_
:=
mu
.
MemRead
(
buf
,
count
)
bytes
,
_
:=
mu
.
MemRead
(
buf
,
count
)
WriteBytes
(
int
(
fd
),
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
{
}
else
if
syscall_no
==
4090
{
a0
,
_
:=
mu
.
RegRead
(
uc
.
MIPS_REG_A0
)
a0
,
_
:=
mu
.
RegRead
(
uc
.
MIPS_REG_A0
)
sz
,
_
:=
mu
.
RegRead
(
uc
.
MIPS_REG_A1
)
sz
,
_
:=
mu
.
RegRead
(
uc
.
MIPS_REG_A1
)
...
...
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