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
4a3565f5
Commit
4a3565f5
authored
Oct 04, 2021
by
George Hotz
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix minor issue in shift ops
parent
8d6d41c2
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
41 additions
and
11 deletions
+41
-11
MIPS.sol
contracts/MIPS.sol
+3
-3
evm.sh
mipsevm/evm.sh
+2
-1
main.go
mipsevm/main.go
+6
-3
simple.py
risc/simple.py
+30
-4
No files found.
contracts/MIPS.sol
View file @
4a3565f5
...
...
@@ -94,7 +94,7 @@ contract MIPS {
}
// TODO: test ll and sc
function stepNextPC(bytes32 stateHash, uint32 pc, uint64 nextPC)
public
view returns (bytes32) {
function stepNextPC(bytes32 stateHash, uint32 pc, uint64 nextPC)
internal
view returns (bytes32) {
uint32 insn = m.ReadMemory(stateHash, pc);
uint32 opcode = insn >> 26; // 6-bits
uint32 func = insn & 0x3f; // 6-bits
...
...
@@ -264,8 +264,8 @@ contract MIPS {
if (func == 0x00) { return rt << shamt; // sll
} else if (func == 0x02) { return rt >> shamt; // srl
} else if (func == 0x03) { return SE(rt >> shamt, 32-shamt); // sra
} else if (func == 0x04) { return rt <<
rs
; // sllv
} else if (func == 0x06) { return rt >>
rs
; // srlv
} else if (func == 0x04) { return rt <<
(rs&0x1F)
; // sllv
} else if (func == 0x06) { return rt >>
(rs&0x1F)
; // srlv
} else if (func == 0x07) { return SE(rt >> rs, 32-rs); // srav
} else if (func >= 0x08 && func < 0x20) { return rs; // jr/jalr/div + others
// 0x10-0x13 = mfhi, mthi, mflo, mtlo
...
...
mipsevm/evm.sh
View file @
4a3565f5
#!/bin/bash -e
(
cd
../
&&
npx hardhat compile
)
&&
go build
&&
./mipsevm
$1
(
cd
../
&&
npx hardhat compile
>
/dev/null
)
go build
&&
./mipsevm
$1
mipsevm/main.go
View file @
4a3565f5
...
...
@@ -126,7 +126,10 @@ 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 %8X %08X
\n
"
,
pcCount
,
nret
,
ram
[
nret
])
fmt
.
Printf
(
"%7d %8X %08X : %08X %08X %08X %08X %08X %08X %08X %08X
\n
"
,
pcCount
,
nret
,
ram
[
nret
],
ram
[
0xc0000008
],
ram
[
0xc000000c
],
ram
[
0xc0000010
],
ram
[
0xc0000014
],
ram
[
0xc0000018
],
ram
[
0xc000001c
],
ram
[
0xc0000020
],
ram
[
0xc0000024
])
pcCount
+=
1
}
scope
.
Memory
.
Set
(
retOffset
.
Uint64
(),
retSize
.
Uint64
(),
ret
)
...
...
@@ -158,7 +161,7 @@ func runMinigeth(fn string, interpreter *vm.EVMInterpreter, bytecode []byte) {
uint32
(
dat
[
i
+
3
])
<<
0
}
steps
:=
10000
0
steps
:=
10000
gas
:=
10000
*
uint64
(
steps
)
// 0xdb7df598
...
...
@@ -216,7 +219,7 @@ func runTest(fn string, steps int, interpreter *vm.EVMInterpreter, bytecode []by
}
func
main
()
{
fmt
.
Println
(
"hello"
)
//
fmt.Println("hello")
/*var parent types.Header
database := state.NewDatabase(parent)
...
...
risc/simple.py
View file @
4a3565f5
...
...
@@ -3,9 +3,12 @@ import os
import
sys
import
binascii
import
struct
from
termcolor
import
colored
from
unicorn
import
*
from
unicorn.mips_const
import
*
mu
=
Uc
(
UC_ARCH_MIPS
,
UC_MODE_32
+
UC_MODE_BIG_ENDIAN
)
from
capstone
import
*
md
=
Cs
(
CS_ARCH_MIPS
,
CS_MODE_32
+
CS_MODE_BIG_ENDIAN
)
# heap (256 MB) @ 0x20000000
heap_start
=
0x20000000
# 0x20000000-0x30000000
...
...
@@ -80,24 +83,47 @@ def hook_mem_invalid(uc, access, address, size, value, user_data):
return
False
mu
.
hook_add
(
UC_HOOK_MEM_FETCH_UNMAPPED
,
hook_mem_invalid
)
gt
=
open
(
"/tmp/gethtrace"
)
.
read
()
.
split
(
"
\n
"
)
# tracer
STEP_COUNT
=
10000
step
=
0
is_bds
=
False
def
hook_code_simple
(
uc
,
address
,
size
,
user_data
):
global
step
global
step
,
is_bds
if
is_bds
:
is_bds
=
False
return
pc
=
uc
.
reg_read
(
UC_MIPS_REG_PC
)
assert
address
==
pc
assert
size
==
4
# check for BDS
dat
=
next
(
md
.
disasm
(
uc
.
mem_read
(
address
,
size
),
address
))
if
dat
.
insn_name
()
in
[
'jr'
,
'j'
,
'beqz'
,
'jal'
,
'bnez'
,
'b'
]:
is_bds
=
True
inst
=
struct
.
unpack
(
">I"
,
uc
.
mem_read
(
pc
,
4
))[
0
]
regs
=
[]
for
i
in
range
(
2
,
10
):
# starting at V0
for
i
in
range
(
4
,
12
):
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
)
ss
=
"
%7
d
%8
X
%08
X : "
%
(
step
,
pc
,
inst
)
+
rr
if
ss
!=
gt
[
step
]:
print
(
colored
(
ss
,
'green'
))
print
(
colored
(
gt
[
step
],
'red'
))
os
.
_exit
(
0
)
else
:
print
(
ss
)
print
(
dat
)
step
+=
1
if
step
>
STEP_COUNT
:
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