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
c22b2fdc
Commit
c22b2fdc
authored
Oct 12, 2021
by
George Hotz
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
move the oracle from 0x3 -> 0xB
parent
6f95e202
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
35 additions
and
34 deletions
+35
-34
MIPSMemory.sol
contracts/MIPSMemory.sol
+4
-4
embedded_mips.go
minigeth/oracle/embedded_mips.go
+7
-7
run.py
mipigo/run.py
+12
-11
compare_test.go
mipsevm/compare_test.go
+3
-3
main.go
mipsevm/main.go
+1
-1
unicorn.go
mipsevm/unicorn.go
+8
-8
No files found.
contracts/MIPSMemory.sol
View file @
c22b2fdc
...
...
@@ -105,12 +105,12 @@ contract MIPSMemory {
}
// MMIO preimage oracle
if (addr >= 0x
31000000 && addr < 0x3
2000000) {
bytes32 pihash = ReadBytes32(stateHash, 0x
3
0001000);
if (addr == 0x
3
1000000) {
if (addr >= 0x
B1000000 && addr < 0xB
2000000) {
bytes32 pihash = ReadBytes32(stateHash, 0x
B
0001000);
if (addr == 0x
B
1000000) {
return uint32(preimage[pihash].length);
}
uint offset = addr-0x
3
1000004;
uint offset = addr-0x
B
1000004;
uint8 a0 = uint8(preimage[pihash][offset]);
uint8 a1 = uint8(preimage[pihash][offset+1]);
uint8 a2 = uint8(preimage[pihash][offset+2]);
...
...
minigeth/oracle/embedded_mips.go
View file @
c22b2fdc
...
...
@@ -36,7 +36,7 @@ func Input(index int) common.Hash {
if
!
inputsLoaded
{
// before this isn't run on chain (confirm this isn't cached)
// does this interact with the GC?
ret
:=
byteAt
(
0x
3
0000000
,
len
(
inputs
)
*
0x20
)
ret
:=
byteAt
(
0x
B
0000000
,
len
(
inputs
)
*
0x20
)
os
.
Stderr
.
WriteString
(
"********* on chain starts here *********
\n
"
)
...
...
@@ -57,11 +57,11 @@ func Halt() {
}
func
Output
(
output
common
.
Hash
,
receipts
common
.
Hash
)
{
ret
:=
byteAt
(
0x
3
0000804
,
0x20
)
ret
:=
byteAt
(
0x
B
0000804
,
0x20
)
copy
(
ret
,
output
.
Bytes
())
rret
:=
byteAt
(
0x
3
0000824
,
0x20
)
rret
:=
byteAt
(
0x
B
0000824
,
0x20
)
copy
(
rret
,
receipts
.
Bytes
())
magic
:=
byteAt
(
0x
3
0000800
,
4
)
magic
:=
byteAt
(
0x
B
0000800
,
4
)
copy
(
magic
,
[]
byte
{
0x13
,
0x37
,
0xf0
,
0x0d
})
Halt
()
}
...
...
@@ -70,7 +70,7 @@ func Preimage(hash common.Hash) []byte {
val
,
ok
:=
preimages
[
hash
]
if
!
ok
{
// load in hash
preImageHash
:=
byteAt
(
0x
3
0001000
,
0x20
)
preImageHash
:=
byteAt
(
0x
B
0001000
,
0x20
)
copy
(
preImageHash
,
hash
.
Bytes
())
// used in unicorn emulator to trigger the load
...
...
@@ -78,9 +78,9 @@ func Preimage(hash common.Hash) []byte {
os
.
Getpid
()
// ready
rawSize
:=
common
.
CopyBytes
(
byteAt
(
0x
3
1000000
,
4
))
rawSize
:=
common
.
CopyBytes
(
byteAt
(
0x
B
1000000
,
4
))
size
:=
(
int
(
rawSize
[
0
])
<<
24
)
|
(
int
(
rawSize
[
1
])
<<
16
)
|
(
int
(
rawSize
[
2
])
<<
8
)
|
int
(
rawSize
[
3
])
ret
:=
common
.
CopyBytes
(
byteAt
(
0x
3
1000004
,
size
))
ret
:=
common
.
CopyBytes
(
byteAt
(
0x
B
1000004
,
size
))
// this is 20% of the exec instructions, this speedup is always an option
realhash
:=
crypto
.
Keccak256Hash
(
ret
)
...
...
mipigo/run.py
View file @
c22b2fdc
...
...
@@ -27,10 +27,10 @@ mregs = [UC_MIPS_REG_AT, UC_MIPS_REG_V0, UC_MIPS_REG_V1, UC_MIPS_REG_A0, UC_MIPS
regs
=
[
"at"
,
"v0"
,
"v1"
,
"a0"
,
"a1"
,
"a2"
,
"a3"
]
heap_start
=
0x20000000
# 0x20000000-0x30000000
# input oracle @ 0x
3
0000000
# output oracle @ 0x
3
0000800
# preimage oracle (write) @ 0x
3
0001000
# preimage oracle (read) @ 0x
31000000-0x3
2000000 (16 MB)
# input oracle @ 0x
B
0000000
# output oracle @ 0x
B
0000800
# preimage oracle (write) @ 0x
B
0001000
# preimage oracle (read) @ 0x
B1000000-0xB
2000000 (16 MB)
brk_start
=
0x40000000
# 0x40000000-0x80000000
stack_start
=
0x7FFFF000
...
...
@@ -99,11 +99,11 @@ def hook_interrupt(uc, intno, user_data):
uc
.
reg_write
(
UC_MIPS_REG_A3
,
0
)
if
syscall_no
==
4020
:
oracle_hash
=
binascii
.
hexlify
(
uc
.
mem_read
(
0x
3
0001000
,
0x20
))
.
decode
(
'utf-8'
)
oracle_hash
=
binascii
.
hexlify
(
uc
.
mem_read
(
0x
B
0001000
,
0x20
))
.
decode
(
'utf-8'
)
dat
=
open
(
"/tmp/eth/0x"
+
oracle_hash
,
"rb"
)
.
read
()
#print("oracle:", oracle_hash, len(dat))
uc
.
mem_write
(
0x
3
1000000
,
struct
.
pack
(
">I"
,
len
(
dat
)))
uc
.
mem_write
(
0x
3
1000004
,
dat
)
uc
.
mem_write
(
0x
B
1000000
,
struct
.
pack
(
">I"
,
len
(
dat
)))
uc
.
mem_write
(
0x
B
1000004
,
dat
)
return
True
if
syscall_no
==
4004
:
...
...
@@ -262,13 +262,13 @@ mu.mem_map(heap_start, 256*1024*1024)
mu
.
mem_map
(
brk_start
,
1024
*
1024
*
1024
)
# input oracle
mu
.
mem_map
(
0x
3
0000000
,
0x2000000
)
mu
.
mem_map
(
0x
B
0000000
,
0x2000000
)
if
len
(
sys
.
argv
)
>
1
:
inputs
=
open
(
"/tmp/eth/"
+
sys
.
argv
[
1
],
"rb"
)
.
read
()
else
:
inputs
=
open
(
"/tmp/eth/13284469"
,
"rb"
)
.
read
()
mu
.
mem_write
(
0x
3
0000000
,
inputs
)
mu
.
mem_write
(
0x
B
0000000
,
inputs
)
_
,
r
=
load_minigeth
(
mu
)
...
...
@@ -290,16 +290,17 @@ try:
mu
.
emu_start
(
0
,
0x5EAD0000
)
died_well
=
True
except
unicorn
.
UcError
:
traceback
.
print_exc
()
pass
if
not
died_well
:
raise
Exception
(
"program exitted early"
)
magic
=
struct
.
unpack
(
">I"
,
mu
.
mem_read
(
0x
3
0000800
,
4
))[
0
]
magic
=
struct
.
unpack
(
">I"
,
mu
.
mem_read
(
0x
B
0000800
,
4
))[
0
]
assert
magic
==
0x1337f00d
real_hash
=
binascii
.
hexlify
(
inputs
[
-
0x40
:
-
0x20
])
compare_hash
=
binascii
.
hexlify
(
mu
.
mem_read
(
0x
3
0000804
,
0x20
))
compare_hash
=
binascii
.
hexlify
(
mu
.
mem_read
(
0x
B
0000804
,
0x20
))
print
(
"compare"
,
real_hash
,
"to computed"
,
compare_hash
)
if
real_hash
!=
compare_hash
:
...
...
mipsevm/compare_test.go
View file @
c22b2fdc
...
...
@@ -20,8 +20,8 @@ func RegSerialize(ram map[uint32](uint32)) []uint32 {
var
done
sync
.
Mutex
func
TestCompare
(
t
*
testing
.
T
)
{
//fn := "../mipigo
/test.bin"
fn
:=
"../mipigo/minigeth.bin"
fn
:=
"../mipigo/test
/test.bin"
//
fn := "../mipigo/minigeth.bin"
steps
:=
1000000000
//steps := 1165
...
...
@@ -34,7 +34,7 @@ func TestCompare(t *testing.T) {
ram
:=
make
(
map
[
uint32
](
uint32
))
LoadMappedFile
(
fn
,
ram
,
0
)
inputFile
:=
fmt
.
Sprintf
(
"/tmp/eth/%d"
,
13284469
)
LoadMappedFile
(
inputFile
,
ram
,
0x
3
0000000
)
LoadMappedFile
(
inputFile
,
ram
,
0x
B
0000000
)
go
RunWithRam
(
ram
,
steps
,
0
,
func
(
step
int
,
ram
map
[
uint32
](
uint32
))
{
//fmt.Printf("%d evm %x\n", step, ram[0xc0000080])
...
...
mipsevm/main.go
View file @
c22b2fdc
...
...
@@ -28,7 +28,7 @@ func LoadMappedFile(fn string, ram map[uint32](uint32), base uint32) {
func
RunMinigeth
(
fn
string
,
steps
int
,
debug
int
)
{
ram
:=
make
(
map
[
uint32
](
uint32
))
LoadMappedFile
(
fn
,
ram
,
0
)
LoadMappedFile
(
fmt
.
Sprintf
(
"/tmp/eth/%d"
,
13284469
),
ram
,
0x
3
0000000
)
LoadMappedFile
(
fmt
.
Sprintf
(
"/tmp/eth/%d"
,
13284469
),
ram
,
0x
B
0000000
)
RunWithRam
(
ram
,
steps
,
debug
,
nil
)
}
...
...
mipsevm/unicorn.go
View file @
c22b2fdc
...
...
@@ -76,20 +76,20 @@ func RunUnicorn(fn string, ram map[uint32](uint32), totalSteps int, callback fun
syscall_no
,
_
:=
mu
.
RegRead
(
uc
.
MIPS_REG_V0
)
v0
:=
uint64
(
0
)
if
syscall_no
==
4020
{
oracle_hash
,
_
:=
mu
.
MemRead
(
0x
3
0001000
,
0x20
)
oracle_hash
,
_
:=
mu
.
MemRead
(
0x
B
0001000
,
0x20
)
hash
:=
common
.
BytesToHash
(
oracle_hash
)
key
:=
fmt
.
Sprintf
(
"/tmp/eth/%s"
,
hash
)
value
,
_
:=
ioutil
.
ReadFile
(
key
)
tmp
:=
[]
byte
{
0
,
0
,
0
,
0
}
binary
.
BigEndian
.
PutUint32
(
tmp
,
uint32
(
len
(
value
)))
mu
.
MemWrite
(
0x
3
1000000
,
tmp
)
mu
.
MemWrite
(
0x
3
1000004
,
value
)
mu
.
MemWrite
(
0x
B
1000000
,
tmp
)
mu
.
MemWrite
(
0x
B
1000004
,
value
)
WriteRam
(
ram
,
0x
3
1000000
,
uint32
(
len
(
value
)))
WriteRam
(
ram
,
0x
B
1000000
,
uint32
(
len
(
value
)))
value
=
append
(
value
,
0
,
0
,
0
)
for
i
:=
uint32
(
0
);
i
<
ram
[
0x
3
1000000
];
i
+=
4
{
WriteRam
(
ram
,
0x
3
1000004
+
i
,
binary
.
BigEndian
.
Uint32
(
value
[
i
:
i
+
4
]))
for
i
:=
uint32
(
0
);
i
<
ram
[
0x
B
1000000
];
i
+=
4
{
WriteRam
(
ram
,
0x
B
1000004
+
i
,
binary
.
BigEndian
.
Uint32
(
value
[
i
:
i
+
4
]))
}
}
else
if
syscall_no
==
4004
{
fd
,
_
:=
mu
.
RegRead
(
uc
.
MIPS_REG_A0
)
...
...
@@ -177,10 +177,10 @@ func RunUnicorn(fn string, ram map[uint32](uint32), totalSteps int, callback fun
// inputs
inputFile
:=
fmt
.
Sprintf
(
"/tmp/eth/%d"
,
13284469
)
inputs
,
_
:=
ioutil
.
ReadFile
(
inputFile
)
mu
.
MemWrite
(
0x
3
0000000
,
inputs
)
mu
.
MemWrite
(
0x
B
0000000
,
inputs
)
LoadMappedFile
(
fn
,
ram
,
0
)
LoadMappedFile
(
inputFile
,
ram
,
0x
3
0000000
)
LoadMappedFile
(
inputFile
,
ram
,
0x
B
0000000
)
mu
.
Start
(
0
,
0x5ead0004
)
}
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