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
c8665251
Commit
c8665251
authored
Oct 04, 2021
by
George Hotz
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add profiling
parent
6447e7c7
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
37 additions
and
20 deletions
+37
-20
.gitignore
mipsevm/.gitignore
+1
-0
main.go
mipsevm/main.go
+22
-17
minigeth_test.go
mipsevm/minigeth_test.go
+10
-0
mipsevm.test
mipsevm/mipsevm.test
+0
-0
simple.py
risc/simple.py
+4
-3
No files found.
mipsevm/.gitignore
View file @
c8665251
mipsevm
mipsevm
*.prof
mipsevm/main.go
View file @
c8665251
...
@@ -94,6 +94,7 @@ type jsoncontract struct {
...
@@ -94,6 +94,7 @@ type jsoncontract struct {
//var ram []byte
//var ram []byte
//var regs [4096]byte
//var regs [4096]byte
var
ministart
time
.
Time
var
pcCount
int
=
0
var
pcCount
int
=
0
var
debug
int
=
0
var
debug
int
=
0
...
@@ -141,7 +142,8 @@ func opStaticCall(pc *uint64, interpreter *vm.EVMInterpreter, scope *vm.ScopeCon
...
@@ -141,7 +142,8 @@ func opStaticCall(pc *uint64, interpreter *vm.EVMInterpreter, scope *vm.ScopeCon
}*/
}*/
}
}
if
(
pcCount
%
10000
)
==
0
{
if
(
pcCount
%
10000
)
==
0
{
os
.
Stderr
.
WriteString
(
fmt
.
Sprintf
(
"step %d
\n
"
,
pcCount
))
steps_per_sec
:=
float64
(
pcCount
)
*
1e9
/
float64
(
time
.
Now
()
.
Sub
(
ministart
)
.
Nanoseconds
())
os
.
Stderr
.
WriteString
(
fmt
.
Sprintf
(
"step %7d steps per s %f
\n
"
,
pcCount
,
steps_per_sec
))
}
}
pcCount
+=
1
pcCount
+=
1
}
}
...
@@ -164,7 +166,7 @@ func opStaticCall(pc *uint64, interpreter *vm.EVMInterpreter, scope *vm.ScopeCon
...
@@ -164,7 +166,7 @@ func opStaticCall(pc *uint64, interpreter *vm.EVMInterpreter, scope *vm.ScopeCon
return
common
.
Hash
{}
.
Bytes
(),
nil
return
common
.
Hash
{}
.
Bytes
(),
nil
}
}
func
runMinigeth
(
fn
string
,
interpreter
*
vm
.
EVMInterpreter
,
bytecode
[]
byte
)
{
func
RunMinigeth
(
fn
string
,
interpreter
*
vm
.
EVMInterpreter
,
bytecode
[]
byte
,
steps
int
)
{
ram
=
make
(
map
[
uint32
](
uint32
))
ram
=
make
(
map
[
uint32
](
uint32
))
dat
,
_
:=
ioutil
.
ReadFile
(
fn
)
dat
,
_
:=
ioutil
.
ReadFile
(
fn
)
for
i
:=
0
;
i
<
len
(
dat
);
i
+=
4
{
for
i
:=
0
;
i
<
len
(
dat
);
i
+=
4
{
...
@@ -174,7 +176,6 @@ func runMinigeth(fn string, interpreter *vm.EVMInterpreter, bytecode []byte) {
...
@@ -174,7 +176,6 @@ func runMinigeth(fn string, interpreter *vm.EVMInterpreter, bytecode []byte) {
uint32
(
dat
[
i
+
3
])
<<
0
uint32
(
dat
[
i
+
3
])
<<
0
}
}
steps
:=
10000000
gas
:=
10000
*
uint64
(
steps
)
gas
:=
10000
*
uint64
(
steps
)
// 0xdb7df598
// 0xdb7df598
...
@@ -184,7 +185,8 @@ func runMinigeth(fn string, interpreter *vm.EVMInterpreter, bytecode []byte) {
...
@@ -184,7 +185,8 @@ func runMinigeth(fn string, interpreter *vm.EVMInterpreter, bytecode []byte) {
input
=
append
(
input
,
common
.
BigToHash
(
common
.
Big0
)
.
Bytes
()
...
)
input
=
append
(
input
,
common
.
BigToHash
(
common
.
Big0
)
.
Bytes
()
...
)
input
=
append
(
input
,
common
.
BigToHash
(
big
.
NewInt
(
int64
(
steps
)))
.
Bytes
()
...
)
input
=
append
(
input
,
common
.
BigToHash
(
big
.
NewInt
(
int64
(
steps
)))
.
Bytes
()
...
)
debug
=
1
ministart
=
time
.
Now
()
debug
=
0
for
i
:=
0
;
i
<
1
;
i
++
{
for
i
:=
0
;
i
<
1
;
i
++
{
contract
:=
vm
.
NewContract
(
vm
.
AccountRef
(
from
),
vm
.
AccountRef
(
to
),
common
.
Big0
,
gas
)
contract
:=
vm
.
NewContract
(
vm
.
AccountRef
(
from
),
vm
.
AccountRef
(
to
),
common
.
Big0
,
gas
)
contract
.
SetCallCode
(
&
to
,
crypto
.
Keccak256Hash
(
bytecode
),
bytecode
)
contract
.
SetCallCode
(
&
to
,
crypto
.
Keccak256Hash
(
bytecode
),
bytecode
)
...
@@ -231,18 +233,12 @@ func runTest(fn string, steps int, interpreter *vm.EVMInterpreter, bytecode []by
...
@@ -231,18 +233,12 @@ func runTest(fn string, steps int, interpreter *vm.EVMInterpreter, bytecode []by
return
ram
[
0xbffffff4
]
&
ram
[
0xbffffff8
]
return
ram
[
0xbffffff4
]
&
ram
[
0xbffffff8
]
}
}
func
main
()
{
func
GetInterpreterAndBytecode
()
(
*
vm
.
EVMInterpreter
,
[]
byte
)
{
//fmt.Println("hello")
/*var parent types.Header
database := state.NewDatabase(parent)
statedb, _ := state.New(parent.Root, database, nil)*/
var
jj
jsoncontract
var
jj
jsoncontract
mipsjson
,
_
:=
ioutil
.
ReadFile
(
"../artifacts/contracts/MIPS.sol/MIPS.json"
)
mipsjson
,
_
:=
ioutil
.
ReadFile
(
"../artifacts/contracts/MIPS.sol/MIPS.json"
)
json
.
NewDecoder
(
bytes
.
NewReader
(
mipsjson
))
.
Decode
(
&
jj
)
json
.
NewDecoder
(
bytes
.
NewReader
(
mipsjson
))
.
Decode
(
&
jj
)
bytecode
:=
common
.
Hex2Bytes
(
jj
.
DeployedBytecode
[
2
:
])
bytecode
:=
common
.
Hex2Bytes
(
jj
.
DeployedBytecode
[
2
:
])
//fmt.Println(bytecode, jj.Bytecode)
statedb
:=
&
StateDB
{
Bytecode
:
bytecode
}
statedb
:=
&
StateDB
{
Bytecode
:
bytecode
}
var
header
types
.
Header
var
header
types
.
Header
...
@@ -257,13 +253,20 @@ func main() {
...
@@ -257,13 +253,20 @@ func main() {
tracer
:=
Tracer
{}
tracer
:=
Tracer
{}
config
.
Tracer
=
&
tracer
config
.
Tracer
=
&
tracer
evm
:=
vm
.
NewEVM
(
blockContext
,
txContext
,
statedb
,
params
.
MainnetChainConfig
,
config
)
evm
:=
vm
.
NewEVM
(
blockContext
,
txContext
,
statedb
,
params
.
MainnetChainConfig
,
config
)
//fmt.Println(evm)
/*ret, gas, err := evm.Call(vm.AccountRef(from), to, []byte{}, 20000000, common.Big0)
fmt.Println(ret, gas, err)*/
interpreter
:=
vm
.
NewEVMInterpreter
(
evm
,
config
)
interpreter
:=
vm
.
NewEVMInterpreter
(
evm
,
config
)
interpreter
.
GetCfg
()
.
JumpTable
[
vm
.
STATICCALL
]
.
SetExecute
(
opStaticCall
)
interpreter
.
GetCfg
()
.
JumpTable
[
vm
.
STATICCALL
]
.
SetExecute
(
opStaticCall
)
return
interpreter
,
bytecode
}
func
main
()
{
//fmt.Println("hello")
/*var parent types.Header
database := state.NewDatabase(parent)
statedb, _ := state.New(parent.Root, database, nil)*/
//fmt.Println(bytecode, jj.Bytecode)
/*input := []byte{0x69, 0x37, 0x33, 0x72} // Step(bytes32)
/*input := []byte{0x69, 0x37, 0x33, 0x72} // Step(bytes32)
input = append(input, common.Hash{}.Bytes()...)*/
input = append(input, common.Hash{}.Bytes()...)*/
...
@@ -274,12 +277,14 @@ func main() {
...
@@ -274,12 +277,14 @@ func main() {
//steps := 1000000
//steps := 1000000
//debug = true
//debug = true
interpreter
,
bytecode
:=
GetInterpreterAndBytecode
()
if
len
(
os
.
Args
)
>
1
{
if
len
(
os
.
Args
)
>
1
{
if
os
.
Args
[
1
]
==
"/tmp/minigeth.bin"
{
if
os
.
Args
[
1
]
==
"/tmp/minigeth.bin"
{
/*debug = 1
/*debug = 1
steps := 1000000
steps := 1000000
runTest(os.Args[1], steps, interpreter, bytecode, uint64(steps)*10000)*/
runTest(os.Args[1], steps, interpreter, bytecode, uint64(steps)*10000)*/
runMinigeth
(
os
.
Args
[
1
],
interpreter
,
bytecode
)
RunMinigeth
(
os
.
Args
[
1
],
interpreter
,
bytecode
,
10000000
)
}
else
{
}
else
{
debug
=
2
debug
=
2
runTest
(
os
.
Args
[
1
],
20
,
interpreter
,
bytecode
,
1000000
)
runTest
(
os
.
Args
[
1
],
20
,
interpreter
,
bytecode
,
1000000
)
...
...
mipsevm/minigeth_test.go
0 → 100644
View file @
c8665251
package
main
import
(
"testing"
)
func
TestProfileMinigeth
(
t
*
testing
.
T
)
{
interpreter
,
bytecode
:=
GetInterpreterAndBytecode
()
RunMinigeth
(
"/tmp/minigeth.bin"
,
interpreter
,
bytecode
,
100000
)
}
mipsevm/mipsevm.test
0 → 100755
View file @
c8665251
File added
risc/simple.py
View file @
c8665251
...
@@ -92,7 +92,7 @@ def hook_mem_invalid(uc, access, address, size, value, user_data):
...
@@ -92,7 +92,7 @@ def hook_mem_invalid(uc, access, address, size, value, user_data):
return
False
return
False
mu
.
hook_add
(
UC_HOOK_MEM_FETCH_UNMAPPED
,
hook_mem_invalid
)
mu
.
hook_add
(
UC_HOOK_MEM_FETCH_UNMAPPED
,
hook_mem_invalid
)
gt
=
open
(
"/tmp/gethtrace"
)
.
read
()
.
split
(
"
\n
"
)
gt
f
=
open
(
"/tmp/gethtrace10
"
)
# tracer
# tracer
step
=
0
step
=
0
...
@@ -120,9 +120,10 @@ def hook_code_simple(uc, address, size, user_data):
...
@@ -120,9 +120,10 @@ def hook_code_simple(uc, address, size, user_data):
rr
=
' '
.
join
([
"
%08
X"
%
x
for
x
in
regs
])
rr
=
' '
.
join
([
"
%08
X"
%
x
for
x
in
regs
])
ss
=
"
%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
]:
sgt
=
gtf
.
readline
()
.
strip
(
"
\n
"
)
if
ss
!=
sgt
:
print
(
colored
(
ss
,
'green'
))
print
(
colored
(
ss
,
'green'
))
print
(
colored
(
gt
[
step
]
,
'red'
))
print
(
colored
(
sgt
,
'red'
))
os
.
_exit
(
0
)
os
.
_exit
(
0
)
else
:
else
:
print
(
ss
)
print
(
ss
)
...
...
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