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
961ba684
Commit
961ba684
authored
Oct 31, 2021
by
George Hotz
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
move the oracle back to 0x3000...
parent
760bdf77
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
29 additions
and
27 deletions
+29
-27
Challenge.sol
contracts/Challenge.sol
+3
-3
MIPSMemory.sol
contracts/MIPSMemory.sol
+4
-4
embedded_mips.go
minigeth/oracle/embedded_mips.go
+7
-7
minigeth.bin
mipigo/golden/minigeth.bin
+0
-0
compare_unievm_test.go
mipsevm/compare_unievm_test.go
+1
-1
main.go
mipsevm/main.go
+4
-3
run_unicorn.go
mipsevm/run_unicorn.go
+9
-9
challenge_test.js
test/challenge_test.js
+1
-0
No files found.
contracts/Challenge.sol
View file @
961ba684
...
...
@@ -100,13 +100,13 @@ contract Challenge {
}
bytes32 startState = GlobalStartState;
startState = mem.WriteBytes32(startState, 0x
B
0000000, inputHash);
startState = mem.WriteBytes32(startState, 0x
3
0000000, inputHash);
// confirm the finalSystemHash asserts the state you claim and the machine is stopped
// you must load these trie nodes into MIPSMemory before calling this
require(mem.ReadMemory(finalSystemState, 0xC0000080) == 0x5EAD0000, "machine is not stopped in final state (PC == 0x5EAD0000)");
require(mem.ReadMemory(finalSystemState, 0x
B
0000800) == 0x1337f00d, "state is not outputted");
require(mem.ReadBytes32(finalSystemState, 0x
B
0000804) == assertionRoot, "you are claiming a different state root in machine");
require(mem.ReadMemory(finalSystemState, 0x
3
0000800) == 0x1337f00d, "state is not outputted");
require(mem.ReadBytes32(finalSystemState, 0x
3
0000804) == assertionRoot, "you are claiming a different state root in machine");
return newChallengeTrusted(startState, finalSystemState, stepCount);
}
...
...
contracts/MIPSMemory.sol
View file @
961ba684
...
...
@@ -108,12 +108,12 @@ contract MIPSMemory {
}
// MMIO preimage oracle
if (addr >= 0x
B1000000 && addr < 0xB
2000000) {
bytes32 pihash = ReadBytes32(stateHash, 0x
B
0001000);
if (addr == 0x
B
1000000) {
if (addr >= 0x
31000000 && addr < 0x3
2000000) {
bytes32 pihash = ReadBytes32(stateHash, 0x
3
0001000);
if (addr == 0x
3
1000000) {
return uint32(preimage[pihash].length);
}
uint offset = addr-0x
B
1000004;
uint offset = addr-0x
3
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 @
961ba684
...
...
@@ -26,7 +26,7 @@ func byteAt(addr uint64, length int) []byte {
}
func
InputHash
()
common
.
Hash
{
ret
:=
byteAt
(
0x
B
0000000
,
0x20
)
ret
:=
byteAt
(
0x
3
0000000
,
0x20
)
os
.
Stderr
.
WriteString
(
"********* on chain starts here *********
\n
"
)
return
common
.
BytesToHash
(
ret
)
}
...
...
@@ -38,11 +38,11 @@ func Halt() {
}
func
Output
(
output
common
.
Hash
,
receipts
common
.
Hash
)
{
ret
:=
byteAt
(
0x
B
0000804
,
0x20
)
ret
:=
byteAt
(
0x
3
0000804
,
0x20
)
copy
(
ret
,
output
.
Bytes
())
rret
:=
byteAt
(
0x
B
0000824
,
0x20
)
rret
:=
byteAt
(
0x
3
0000824
,
0x20
)
copy
(
rret
,
receipts
.
Bytes
())
magic
:=
byteAt
(
0x
B
0000800
,
4
)
magic
:=
byteAt
(
0x
3
0000800
,
4
)
copy
(
magic
,
[]
byte
{
0x13
,
0x37
,
0xf0
,
0x0d
})
Halt
()
}
...
...
@@ -51,7 +51,7 @@ func Preimage(hash common.Hash) []byte {
val
,
ok
:=
preimages
[
hash
]
if
!
ok
{
// load in hash
preImageHash
:=
byteAt
(
0x
B
0001000
,
0x20
)
preImageHash
:=
byteAt
(
0x
3
0001000
,
0x20
)
copy
(
preImageHash
,
hash
.
Bytes
())
// used in unicorn emulator to trigger the load
...
...
@@ -59,9 +59,9 @@ func Preimage(hash common.Hash) []byte {
os
.
Getpid
()
// ready
rawSize
:=
common
.
CopyBytes
(
byteAt
(
0x
B
1000000
,
4
))
rawSize
:=
common
.
CopyBytes
(
byteAt
(
0x
3
1000000
,
4
))
size
:=
(
int
(
rawSize
[
0
])
<<
24
)
|
(
int
(
rawSize
[
1
])
<<
16
)
|
(
int
(
rawSize
[
2
])
<<
8
)
|
int
(
rawSize
[
3
])
ret
:=
common
.
CopyBytes
(
byteAt
(
0x
B
1000004
,
size
))
ret
:=
common
.
CopyBytes
(
byteAt
(
0x
3
1000004
,
size
))
// this is 20% of the exec instructions, this speedup is always an option
realhash
:=
crypto
.
Keccak256Hash
(
ret
)
...
...
mipigo/golden/minigeth.bin
deleted
100644 → 0
View file @
760bdf77
File deleted
mipsevm/compare_unievm_test.go
View file @
961ba684
...
...
@@ -35,7 +35,7 @@ func TestCompareUnicornEvm(t *testing.T) {
evmram
:=
make
(
map
[
uint32
](
uint32
))
LoadMappedFile
(
fn
,
evmram
,
0
)
inputFile
:=
fmt
.
Sprintf
(
"/tmp/eth/%d"
,
13284469
)
LoadMappedFile
(
inputFile
,
evmram
,
0x
B
0000000
)
LoadMappedFile
(
inputFile
,
evmram
,
0x
3
0000000
)
// init registers to 0 in evm
for
i
:=
uint32
(
0xC0000000
);
i
<
0xC0000000
+
36
*
4
;
i
+=
4
{
WriteRam
(
evmram
,
i
,
0
)
...
...
mipsevm/main.go
View file @
961ba684
...
...
@@ -23,7 +23,7 @@ func main() {
lastStep
:=
0
mu
:=
GetHookedUnicorn
(
root
,
ram
,
func
(
step
int
,
mu
uc
.
Unicorn
,
ram
map
[
uint32
](
uint32
))
{
// this can be raised to 10,000,000 if the files are too large
if
step
%
1000000
==
0
{
if
step
%
1000000
0
==
0
{
SyncRegs
(
mu
,
ram
)
WriteCheckpoint
(
ram
,
root
,
step
)
}
...
...
@@ -31,9 +31,10 @@ func main() {
})
ZeroRegisters
(
ram
)
LoadMappedFileUnicorn
(
mu
,
"../mipigo/golden/minigeth.bin"
,
ram
,
0
)
// not ready for golden yet
LoadMappedFileUnicorn
(
mu
,
"../mipigo/minigeth.bin"
,
ram
,
0
)
WriteCheckpoint
(
ram
,
root
,
-
1
)
LoadMappedFileUnicorn
(
mu
,
fmt
.
Sprintf
(
"%s/input"
,
root
),
ram
,
0x
B
0000000
)
LoadMappedFileUnicorn
(
mu
,
fmt
.
Sprintf
(
"%s/input"
,
root
),
ram
,
0x
3
0000000
)
mu
.
Start
(
0
,
0x5ead0004
)
SyncRegs
(
mu
,
ram
)
...
...
mipsevm/run_unicorn.go
View file @
961ba684
...
...
@@ -80,20 +80,20 @@ func GetHookedUnicorn(root string, ram map[uint32](uint32), callback func(int, u
syscall_no
,
_
:=
mu
.
RegRead
(
uc
.
MIPS_REG_V0
)
v0
:=
uint64
(
0
)
if
syscall_no
==
4020
{
oracle_hash
,
_
:=
mu
.
MemRead
(
0x
B
0001000
,
0x20
)
oracle_hash
,
_
:=
mu
.
MemRead
(
0x
3
0001000
,
0x20
)
hash
:=
common
.
BytesToHash
(
oracle_hash
)
key
:=
fmt
.
Sprintf
(
"%s/%s"
,
root
,
hash
)
value
,
_
:=
ioutil
.
ReadFile
(
key
)
tmp
:=
[]
byte
{
0
,
0
,
0
,
0
}
binary
.
BigEndian
.
PutUint32
(
tmp
,
uint32
(
len
(
value
)))
mu
.
MemWrite
(
0x
B
1000000
,
tmp
)
mu
.
MemWrite
(
0x
B
1000004
,
value
)
mu
.
MemWrite
(
0x
3
1000000
,
tmp
)
mu
.
MemWrite
(
0x
3
1000004
,
value
)
WriteRam
(
ram
,
0x
B
1000000
,
uint32
(
len
(
value
)))
WriteRam
(
ram
,
0x
3
1000000
,
uint32
(
len
(
value
)))
value
=
append
(
value
,
0
,
0
,
0
)
for
i
:=
uint32
(
0
);
i
<
ram
[
0x
B
1000000
];
i
+=
4
{
WriteRam
(
ram
,
0x
B
1000004
+
i
,
binary
.
BigEndian
.
Uint32
(
value
[
i
:
i
+
4
]))
for
i
:=
uint32
(
0
);
i
<
ram
[
0x
3
1000000
];
i
+=
4
{
WriteRam
(
ram
,
0x
3
1000004
+
i
,
binary
.
BigEndian
.
Uint32
(
value
[
i
:
i
+
4
]))
}
}
else
if
syscall_no
==
4004
{
fd
,
_
:=
mu
.
RegRead
(
uc
.
MIPS_REG_A0
)
...
...
@@ -179,12 +179,12 @@ func RunUnicorn(fn string, ram map[uint32](uint32), checkIO bool, callback func(
// inputs
inputs
,
_
:=
ioutil
.
ReadFile
(
fmt
.
Sprintf
(
"%s/input"
,
root
))
mu
.
MemWrite
(
0x
B
0000000
,
inputs
[
0
:
0xc0
])
mu
.
MemWrite
(
0x
3
0000000
,
inputs
[
0
:
0xc0
])
// load into ram
LoadData
(
dat
,
ram
,
0
)
if
checkIO
{
LoadData
(
inputs
[
0
:
0xc0
],
ram
,
0x
B
0000000
)
LoadData
(
inputs
[
0
:
0xc0
],
ram
,
0x
3
0000000
)
}
mu
.
Start
(
0
,
0x5ead0004
)
...
...
@@ -192,7 +192,7 @@ func RunUnicorn(fn string, ram map[uint32](uint32), checkIO bool, callback func(
if
checkIO
{
outputs
,
_
:=
ioutil
.
ReadFile
(
fmt
.
Sprintf
(
"%s/output"
,
root
))
real
:=
append
([]
byte
{
0x13
,
0x37
,
0xf0
,
0x0d
},
outputs
...
)
output
,
_
:=
mu
.
MemRead
(
0x
B
0000800
,
0x44
)
output
,
_
:=
mu
.
MemRead
(
0x
3
0000800
,
0x44
)
if
bytes
.
Compare
(
real
,
output
)
!=
0
{
log
.
Fatal
(
"mismatch output"
)
}
else
{
...
...
test/challenge_test.js
View file @
961ba684
...
...
@@ -37,6 +37,7 @@ describe("Challenge contract", function () {
while
(
1
)
{
try
{
await
c
.
InitiateChallenge
(
blockNumberN
,
blockNp1Rlp
,
assertionRoot
,
finalSystemState
,
1
)
break
}
catch
(
e
)
{
const
missing
=
e
.
toString
().
split
(
"
'
"
)[
1
]
if
(
missing
.
length
==
64
)
{
...
...
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