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
8d6d41c2
Commit
8d6d41c2
authored
Oct 04, 2021
by
George Hotz
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add tracer, make ram uint32
parent
0b3a5180
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
36 additions
and
13 deletions
+36
-13
main.go
mipsevm/main.go
+12
-10
simple.py
risc/simple.py
+24
-3
No files found.
mipsevm/main.go
View file @
8d6d41c2
...
...
@@ -96,7 +96,9 @@ type jsoncontract struct {
var
pcCount
int
=
0
var
debug
int
=
0
var
ram
map
[
uint64
](
uint32
)
// TODO: why is ram uint64 -> uint32 and not uint32 -> uint32
var
ram
map
[
uint32
](
uint32
)
func
opStaticCall
(
pc
*
uint64
,
interpreter
*
vm
.
EVMInterpreter
,
scope
*
vm
.
ScopeContext
)
([]
byte
,
error
)
{
// Pop gas. The actual gas is in interpreter.evm.callGasTemp.
...
...
@@ -114,7 +116,7 @@ func opStaticCall(pc *uint64, interpreter *vm.EVMInterpreter, scope *vm.ScopeCon
args
:=
scope
.
Memory
.
GetPtr
(
int64
(
inOffset
.
Uint64
()),
int64
(
inSize
.
Uint64
()))
if
args
[
0
]
==
98
{
// read
addr
:=
common
.
BytesToHash
(
args
[
4
:
])
.
Big
()
.
Uint64
(
)
addr
:=
uint32
(
common
.
BytesToHash
(
args
[
4
:
])
.
Big
()
.
Uint64
()
)
nret
:=
ram
[
addr
]
//scope.Memory.GetPtr(int64(inOffset.Uint64()), int64(inSize.Uint64()))
...
...
@@ -124,17 +126,17 @@ func opStaticCall(pc *uint64, interpreter *vm.EVMInterpreter, scope *vm.ScopeCon
fmt
.
Println
(
"HOOKED READ! "
,
fmt
.
Sprintf
(
"%x = %x"
,
addr
,
nret
))
}
if
addr
==
0xc0000080
&&
debug
>=
1
{
fmt
.
Printf
(
"%7d
: PC %x
\n
"
,
pcCount
,
nret
)
fmt
.
Printf
(
"%7d
%8X %08X
\n
"
,
pcCount
,
nret
,
ram
[
nret
]
)
pcCount
+=
1
}
scope
.
Memory
.
Set
(
retOffset
.
Uint64
(),
retSize
.
Uint64
(),
ret
)
}
else
if
args
[
0
]
==
184
{
addr
:=
common
.
BytesToHash
(
args
[
0x24
:
0x44
])
.
Big
()
.
Uint64
(
)
dat
:=
common
.
BytesToHash
(
args
[
0x44
:
0x64
])
.
Big
()
.
Uint64
(
)
addr
:=
uint32
(
common
.
BytesToHash
(
args
[
0x24
:
0x44
])
.
Big
()
.
Uint64
()
)
dat
:=
uint32
(
common
.
BytesToHash
(
args
[
0x44
:
0x64
])
.
Big
()
.
Uint64
()
)
if
debug
>=
2
{
fmt
.
Println
(
"HOOKED WRITE! "
,
fmt
.
Sprintf
(
"%x = %x"
,
addr
,
dat
))
}
ram
[
addr
]
=
uint32
(
dat
)
ram
[
addr
]
=
dat
// pass through stateRoot
scope
.
Memory
.
Set
(
retOffset
.
Uint64
(),
retSize
.
Uint64
(),
args
[
0x4
:
0x24
])
...
...
@@ -147,10 +149,10 @@ func opStaticCall(pc *uint64, interpreter *vm.EVMInterpreter, scope *vm.ScopeCon
}
func
runMinigeth
(
fn
string
,
interpreter
*
vm
.
EVMInterpreter
,
bytecode
[]
byte
)
{
ram
=
make
(
map
[
uint
64
](
uint32
))
ram
=
make
(
map
[
uint
32
](
uint32
))
dat
,
_
:=
ioutil
.
ReadFile
(
fn
)
for
i
:=
0
;
i
<
len
(
dat
);
i
+=
4
{
ram
[
uint
64
(
i
)]
=
uint32
(
dat
[
i
])
<<
24
|
ram
[
uint
32
(
i
)]
=
uint32
(
dat
[
i
])
<<
24
|
uint32
(
dat
[
i
+
1
])
<<
16
|
uint32
(
dat
[
i
+
2
])
<<
8
|
uint32
(
dat
[
i
+
3
])
<<
0
...
...
@@ -180,12 +182,12 @@ func runMinigeth(fn string, interpreter *vm.EVMInterpreter, bytecode []byte) {
}
func
runTest
(
fn
string
,
steps
int
,
interpreter
*
vm
.
EVMInterpreter
,
bytecode
[]
byte
,
gas
uint64
)
uint32
{
ram
=
make
(
map
[
uint
64
](
uint32
))
ram
=
make
(
map
[
uint
32
](
uint32
))
ram
[
0xC000007C
]
=
0xDEAD0000
//fmt.Println("starting", fn)
dat
,
_
:=
ioutil
.
ReadFile
(
fn
)
for
i
:=
0
;
i
<
len
(
dat
);
i
+=
4
{
ram
[
uint
64
(
i
)]
=
uint32
(
dat
[
i
])
<<
24
|
ram
[
uint
32
(
i
)]
=
uint32
(
dat
[
i
])
<<
24
|
uint32
(
dat
[
i
+
1
])
<<
16
|
uint32
(
dat
[
i
+
2
])
<<
8
|
uint32
(
dat
[
i
+
3
])
<<
0
...
...
risc/simple.py
View file @
8d6d41c2
...
...
@@ -65,8 +65,9 @@ mu.mem_write(0, dat)
# oracle @ 0x30000000
# brk @ 0x40000000
mu
.
mem_map
(
heap_start
,
0x60000000
)
inputs
=
open
(
"/tmp/eth/"
+
sys
.
argv
[
1
],
"rb"
)
.
read
()
mu
.
mem_write
(
0x30000000
,
inputs
)
if
len
(
sys
.
argv
)
>
1
:
inputs
=
open
(
"/tmp/eth/"
+
sys
.
argv
[
1
],
"rb"
)
.
read
()
mu
.
mem_write
(
0x30000000
,
inputs
)
def
hook_mem_invalid
(
uc
,
access
,
address
,
size
,
value
,
user_data
):
global
has_input_oracle
...
...
@@ -77,6 +78,26 @@ def hook_mem_invalid(uc, access, address, size, value, user_data):
os
.
_exit
(
0
)
print
(
"UNMAPPED MEMORY:"
,
access
,
hex
(
address
),
size
,
"at"
,
hex
(
pc
))
return
False
mu
.
hook_add
(
UC_HOOK_MEM_FETCH_UNMAPPED
,
hook_mem_invalid
)
# tracer
STEP_COUNT
=
10000
step
=
0
def
hook_code_simple
(
uc
,
address
,
size
,
user_data
):
global
step
pc
=
uc
.
reg_read
(
UC_MIPS_REG_PC
)
assert
address
==
pc
assert
size
==
4
inst
=
struct
.
unpack
(
">I"
,
uc
.
mem_read
(
pc
,
4
))[
0
]
regs
=
[]
for
i
in
range
(
2
,
10
):
regs
.
append
(
uc
.
reg_read
(
i
))
rr
=
' '
.
join
([
"
%08
X"
%
x
for
x
in
regs
])
print
(
"
%7
d
%8
X
%08
X : "
%
(
step
,
pc
,
inst
)
+
rr
)
step
+=
1
if
step
>
STEP_COUNT
:
os
.
_exit
(
0
)
mu
.
hook_add
(
UC_HOOK_CODE
,
hook_code_simple
)
mu
.
emu_start
(
0
,
-
1
)
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