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
5b7fac08
Commit
5b7fac08
authored
Sep 25, 2021
by
George Hotz
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add halt
parent
ebded26a
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
29 additions
and
4 deletions
+29
-4
embedded_mips.go
minigeth/oracle/embedded_mips.go
+7
-0
run.py
risc/run.py
+22
-4
No files found.
minigeth/oracle/embedded_mips.go
View file @
5b7fac08
...
...
@@ -49,6 +49,11 @@ func Input(index int) common.Hash {
return
inputs
[
index
]
}
func
Halt
()
{
os
.
Stderr
.
WriteString
(
"THIS SHOULD BE PATCHED OUT
\n
"
)
os
.
Exit
(
0
)
}
func
Output
(
output
common
.
Hash
)
{
ret
:=
byteAt
(
0x30000800
,
0x20
)
copy
(
ret
,
output
.
Bytes
())
...
...
@@ -59,6 +64,8 @@ func Output(output common.Hash) {
fmt
.
Println
(
output
,
"!="
,
inputs
[
5
])
panic
(
"BAD transition :(("
)
}
Halt
()
}
func
Preimage
(
hash
common
.
Hash
)
[]
byte
{
...
...
risc/run.py
View file @
5b7fac08
...
...
@@ -207,10 +207,9 @@ def hook_interrupt(uc, intno, user_data):
print
(
"exit(
%
d) ran
%.2
f million instructions,
%
d binary searches"
%
(
a0
,
icount
/
1_000_000
,
math
.
ceil
(
math
.
log2
(
icount
))))
else
:
print
(
"exit(
%
d)"
%
a0
)
hexdump
(
uc
.
mem_read
(
0x30000800
,
0x20
))
sys
.
stdout
.
flush
()
sys
.
stderr
.
flush
()
os
.
_exit
(
a0
)
#
os._exit(a0)
elif
syscall_no
==
4090
:
a0
=
uc
.
reg_read
(
UC_MIPS_REG_A0
)
a1
=
uc
.
reg_read
(
UC_MIPS_REG_A1
)
...
...
@@ -236,7 +235,7 @@ def hook_interrupt(uc, intno, user_data):
print
(
"interrupt"
,
intno
,
hex
(
pc
))
if
intno
!=
17
:
raise
Exception
raise
unicorn
.
UcError
(
0
)
return
True
cnt
=
0
...
...
@@ -286,6 +285,7 @@ mu.mem_map(brk_start, 1024*1024*1024)
# input oracle
mu
.
mem_map
(
0x30000000
,
0x2000000
)
dat
=
open
(
"/tmp/eth/13284469"
,
"rb"
)
.
read
()
mu
.
mem_write
(
0x30000000
,
dat
)
...
...
@@ -335,19 +335,37 @@ for section in elffile.iter_sections():
print
(
nsym
,
symbol
.
name
)
# nop gcenable
mu
.
mem_write
(
symbol
[
'st_value'
],
b
"
\x03\xe0\x00\x08\x00\x00\x00\x00
"
)
if
symbol
.
name
==
"github.com/ethereum/go-ethereum/oracle.Halt"
:
#00400000: 2004dead ; <input:0> li $a0, 57005
# 00400004: 00042400 ; <input:1> sll $a0, $a0, 16
# 00400008: 00800008 ; <input:2> jr $a0
mu
.
mem_write
(
symbol
[
'st_value'
],
b
"
\x20\x04\xde\xad\x00\x04\x24\x00\x00\x80\x00\x08
"
)
except
Exception
:
#traceback.print_exc()
pass
#mu.hook_add(UC_HOOK_BLOCK, hook_code, user_data=mu)
died_well
=
False
def
hook_mem_invalid
(
uc
,
access
,
address
,
size
,
value
,
user_data
):
global
died_well
pc
=
uc
.
reg_read
(
UC_MIPS_REG_PC
)
if
pc
==
0xDEAD0000
:
died_well
=
True
print
(
"UNMAPPED MEMORY:"
,
access
,
hex
(
address
),
size
,
"at"
,
hex
(
pc
))
return
False
mu
.
hook_add
(
UC_HOOK_MEM_READ_UNMAPPED
|
UC_HOOK_MEM_WRITE_UNMAPPED
,
hook_mem_invalid
)
mu
.
hook_add
(
UC_HOOK_MEM_FETCH_UNMAPPED
,
hook_mem_invalid
)
mu
.
hook_add
(
UC_HOOK_INTR
,
hook_interrupt
)
#mu.hook_add(UC_HOOK_INSN, hook_interrupt, None, 1, 0, 0x0c000000)
mu
.
emu_start
(
entry
,
0
)
try
:
mu
.
emu_start
(
entry
,
0
)
except
unicorn
.
UcError
:
pass
hexdump
(
mu
.
mem_read
(
0x30000800
,
0x20
))
if
not
died_well
:
raise
Exception
(
"program exitted early"
)
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