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
36ce0212
Commit
36ce0212
authored
Oct 06, 2021
by
George Hotz
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
unicorn running without a working oracle
parent
afa5f1fb
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
40 additions
and
7 deletions
+40
-7
embedded_mips.go
minigeth/oracle/embedded_mips.go
+4
-3
unicorn.go
mipsevm/unicorn.go
+36
-4
No files found.
minigeth/oracle/embedded_mips.go
View file @
36ce0212
...
...
@@ -11,6 +11,7 @@ import (
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/crypto"
)
var
preimages
=
make
(
map
[
common
.
Hash
][]
byte
)
...
...
@@ -78,11 +79,11 @@ func Preimage(hash common.Hash) []byte {
size
:=
(
int
(
rawSize
[
0
])
<<
24
)
|
(
int
(
rawSize
[
1
])
<<
16
)
|
(
int
(
rawSize
[
2
])
<<
8
)
|
int
(
rawSize
[
3
])
ret
:=
common
.
CopyBytes
(
byteAt
(
0x31000004
,
size
))
// this is 20% of the exec instructions
/*
realhash := crypto.Keccak256Hash(ret)
// this is 20% of the exec instructions
, this speedup is always an option
realhash
:=
crypto
.
Keccak256Hash
(
ret
)
if
realhash
!=
hash
{
panic
(
"preimage has wrong hash"
)
}
*/
}
preimages
[
hash
]
=
ret
return
ret
...
...
mipsevm/unicorn.go
View file @
36ce0212
...
...
@@ -4,6 +4,8 @@ import (
"fmt"
"io/ioutil"
"log"
"os"
"time"
uc
"github.com/unicorn-engine/unicorn/bindings/go/unicorn"
)
...
...
@@ -15,6 +17,11 @@ func check(err error) {
}
var
steps
int
=
0
var
heap_start
uint64
=
0
func
RegRead
(
u
*
uc
.
Unicorn
,
reg
int
)
{
}
func
RunUnicorn
(
fn
string
)
{
mu
,
err
:=
uc
.
NewUnicorn
(
uc
.
ARCH_MIPS
,
uc
.
MODE_32
|
uc
.
MODE_BIG_ENDIAN
)
...
...
@@ -22,15 +29,40 @@ func RunUnicorn(fn string) {
mu
.
HookAdd
(
uc
.
HOOK_INTR
,
func
(
mu
uc
.
Unicorn
,
intno
uint32
)
{
if
intno
!=
17
{
log
.
Fatal
(
"invalid interrupt "
,
intno
)
log
.
Fatal
(
"invalid interrupt "
,
intno
,
" at step "
,
steps
)
}
syscall_no
,
_
:=
mu
.
RegRead
(
uc
.
MIPS_REG_V0
)
fmt
.
Println
(
"syscall"
,
syscall_no
)
v0
:=
uint64
(
0
)
if
syscall_no
==
4004
{
buf
,
_
:=
mu
.
RegRead
(
uc
.
MIPS_REG_A1
)
count
,
_
:=
mu
.
RegRead
(
uc
.
MIPS_REG_A2
)
bytes
,
_
:=
mu
.
MemRead
(
buf
,
count
)
os
.
Stderr
.
Write
(
bytes
)
}
else
if
syscall_no
==
4090
{
a0
,
_
:=
mu
.
RegRead
(
uc
.
MIPS_REG_A0
)
sz
,
_
:=
mu
.
RegRead
(
uc
.
MIPS_REG_A1
)
if
a0
==
0
{
v0
=
0x20000000
+
heap_start
heap_start
+=
sz
}
else
{
v0
=
a0
}
}
else
if
syscall_no
==
4045
{
v0
=
0x40000000
}
else
if
syscall_no
==
4120
{
v0
=
1
}
else
{
fmt
.
Println
(
"syscall"
,
syscall_no
)
}
mu
.
RegWrite
(
uc
.
MIPS_REG_V0
,
v0
)
mu
.
RegWrite
(
uc
.
MIPS_REG_A3
,
0
)
},
1
,
0
)
ministart
:=
time
.
Now
()
mu
.
HookAdd
(
uc
.
HOOK_CODE
,
func
(
mu
uc
.
Unicorn
,
addr
uint64
,
size
uint32
)
{
if
steps
%
10000
==
0
{
fmt
.
Printf
(
"%6d Code: 0x%x, 0x%x
\n
"
,
steps
,
addr
,
size
)
if
steps
%
100000
==
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
)
...
...
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