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
a9d4fc11
Commit
a9d4fc11
authored
Sep 25, 2021
by
George Hotz
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
input and output oracle work
parent
8f3a0989
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
39 additions
and
21 deletions
+39
-21
CHALLENGE
CHALLENGE
+1
-1
Challenge.sol
contracts/Challenge.sol
+6
-6
main.go
minigeth/main.go
+1
-0
embedded_mips.go
minigeth/oracle/embedded_mips.go
+20
-10
run.py
risc/run.py
+11
-4
No files found.
CHALLENGE
View file @
a9d4fc11
...
@@ -24,7 +24,7 @@ PreimageOracle -- key value store
...
@@ -24,7 +24,7 @@ PreimageOracle -- key value store
returns
returns
$v0 = preimage[$t7...$t0] >> ($a0 * 32)
$v0 = preimage[$t7...$t0] >> ($a0 * 32)
Program returns a hash in
[$t7...$t0]
and exits(jump to 0xDEAD0000) with the hash in the state
Program returns a hash in
mem(0x30000800)
and exits(jump to 0xDEAD0000) with the hash in the state
Challenge Flow:
Challenge Flow:
C is challenger, D is defender
C is challenger, D is defender
...
...
contracts/Challenge.sol
View file @
a9d4fc11
...
@@ -94,16 +94,16 @@ contract Challenge {
...
@@ -94,16 +94,16 @@ contract Challenge {
// the first instruction executed in MIPS should be an access of startState
// the first instruction executed in MIPS should be an access of startState
// parentblockhash, txhash, coinbase, unclehash, gaslimit
// parentblockhash, txhash, coinbase, unclehash, gaslimit
bytes32 startState = GlobalStartState;
bytes32 startState = GlobalStartState;
startState = writeBytes32(startState, 0x
D
0000000, parentHash);
startState = writeBytes32(startState, 0x
3
0000000, parentHash);
startState = writeBytes32(startState, 0x
D
0000020, Lib_RLPReader.readBytes32(blockNp1[4]));
startState = writeBytes32(startState, 0x
3
0000020, Lib_RLPReader.readBytes32(blockNp1[4]));
startState = writeBytes32(startState, 0x
D
0000040, bytes32(uint256(Lib_RLPReader.readAddress(blockNp1[2]))));
startState = writeBytes32(startState, 0x
3
0000040, bytes32(uint256(Lib_RLPReader.readAddress(blockNp1[2]))));
startState = writeBytes32(startState, 0x
D
0000060, Lib_RLPReader.readBytes32(blockNp1[1]));
startState = writeBytes32(startState, 0x
3
0000060, Lib_RLPReader.readBytes32(blockNp1[1]));
startState = writeBytes32(startState, 0x
D
0000080, bytes32(Lib_RLPReader.readUint256(blockNp1[9])));
startState = writeBytes32(startState, 0x
3
0000080, bytes32(Lib_RLPReader.readUint256(blockNp1[9])));
// confirm the finalSystemHash asserts the state you claim (in $t0-$t7) and the machine is stopped
// confirm the finalSystemHash asserts the state you claim (in $t0-$t7) and the machine is stopped
// you must load these proofs into MIPS before calling this
// you must load these proofs into MIPS before calling this
// we disagree at the end
// we disagree at the end
require(mips.ReadBytes32(finalSystemState, 0x
C000002
0) == assertionRoot, "you are claiming a different state root in machine");
require(mips.ReadBytes32(finalSystemState, 0x
3000080
0) == assertionRoot, "you are claiming a different state root in machine");
require(mips.ReadMemory(finalSystemState, 0xC0000080) == 0xDEAD0000, "machine is not stopped in final state (PC == 0xDEAD0000)");
require(mips.ReadMemory(finalSystemState, 0xC0000080) == 0xDEAD0000, "machine is not stopped in final state (PC == 0xDEAD0000)");
return newChallengeTrusted(startState, finalSystemState, stepCount);
return newChallengeTrusted(startState, finalSystemState, stepCount);
...
...
minigeth/main.go
View file @
a9d4fc11
...
@@ -39,6 +39,7 @@ func main() {
...
@@ -39,6 +39,7 @@ func main() {
oracle
.
PrefetchBlock
(
big
.
NewInt
(
int64
(
blockNumber
)),
true
,
nil
)
oracle
.
PrefetchBlock
(
big
.
NewInt
(
int64
(
blockNumber
)),
true
,
nil
)
oracle
.
PrefetchBlock
(
big
.
NewInt
(
int64
(
blockNumber
)
+
1
),
false
,
pkwtrie
)
oracle
.
PrefetchBlock
(
big
.
NewInt
(
int64
(
blockNumber
)
+
1
),
false
,
pkwtrie
)
hash
,
err
:=
pkwtrie
.
Commit
()
hash
,
err
:=
pkwtrie
.
Commit
()
check
(
err
)
fmt
.
Println
(
"commited transactions"
,
hash
,
err
)
fmt
.
Println
(
"commited transactions"
,
hash
,
err
)
}
}
...
...
minigeth/oracle/embedded_mips.go
View file @
a9d4fc11
...
@@ -8,7 +8,8 @@ import (
...
@@ -8,7 +8,8 @@ import (
"io/ioutil"
"io/ioutil"
"math/big"
"math/big"
"os"
"os"
"strconv"
"reflect"
"unsafe"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/core/types"
...
@@ -19,31 +20,40 @@ var preimages = make(map[common.Hash][]byte)
...
@@ -19,31 +20,40 @@ var preimages = make(map[common.Hash][]byte)
var
inputs
[
6
]
common
.
Hash
var
inputs
[
6
]
common
.
Hash
var
inputsLoaded
bool
=
false
var
inputsLoaded
bool
=
false
func
byteAt
(
addr
uint64
,
length
int
)
[]
byte
{
var
ret
[]
byte
bh
:=
(
*
reflect
.
SliceHeader
)(
unsafe
.
Pointer
(
&
ret
))
bh
.
Data
=
uintptr
(
addr
)
bh
.
Len
=
length
bh
.
Cap
=
length
return
ret
}
func
Input
(
index
int
)
common
.
Hash
{
func
Input
(
index
int
)
common
.
Hash
{
if
index
<
0
||
index
>
5
{
if
index
<
0
||
index
>
5
{
panic
(
"bad input index"
)
panic
(
"bad input index"
)
}
}
if
!
inputsLoaded
{
if
!
inputsLoaded
{
blockNumber
,
_
:=
strconv
.
Atoi
(
os
.
Args
[
1
])
// before this isn't run on chain (confirm this isn't cached)
f
,
err
:=
os
.
Open
(
fmt
.
Sprintf
(
"/tmp/eth/%d"
,
blockNumber
))
// does this interact with the GC?
if
err
!=
nil
{
ret
:=
byteAt
(
0x30000000
,
len
(
inputs
)
*
0x20
)
panic
(
"missing inputs"
)
}
os
.
Stderr
.
WriteString
(
"********* on chain starts here *********
\n
"
)
defer
f
.
Close
()
ret
,
err
:=
ioutil
.
ReadAll
(
f
)
for
i
:=
0
;
i
<
len
(
inputs
);
i
++
{
for
i
:=
0
;
i
<
len
(
inputs
);
i
++
{
inputs
[
i
]
=
common
.
BytesToHash
(
ret
[
i
*
0x20
:
i
*
0x20
+
0x20
])
inputs
[
i
]
=
common
.
BytesToHash
(
ret
[
i
*
0x20
:
i
*
0x20
+
0x20
])
//fmt.Println(i, inputs[i])
}
}
inputsLoaded
=
true
inputsLoaded
=
true
// before this isn't run on chain (confirm this isn't cached)
os
.
Stderr
.
WriteString
(
"********* on chain starts here *********
\n
"
)
}
}
return
inputs
[
index
]
return
inputs
[
index
]
}
}
func
Output
(
output
common
.
Hash
)
{
func
Output
(
output
common
.
Hash
)
{
ret
:=
byteAt
(
0x30000800
,
0x20
)
copy
(
ret
,
output
.
Bytes
())
if
output
==
inputs
[
5
]
{
if
output
==
inputs
[
5
]
{
fmt
.
Println
(
"good transition"
)
fmt
.
Println
(
"good transition"
)
}
else
{
}
else
{
...
...
risc/run.py
View file @
a9d4fc11
...
@@ -25,6 +25,7 @@ regs = ["at", "v0", "v1", "a0", "a1", "a2", "a3"]
...
@@ -25,6 +25,7 @@ regs = ["at", "v0", "v1", "a0", "a1", "a2", "a3"]
SIZE
=
16
*
1024
*
1024
SIZE
=
16
*
1024
*
1024
heap_start
=
0x20000000
# 0x20000000-0x30000000
heap_start
=
0x20000000
# 0x20000000-0x30000000
# input oracle @ 0x30000000
brk_start
=
0x40000000
# 0x40000000-0x80000000
brk_start
=
0x40000000
# 0x40000000-0x80000000
# hmm, very slow
# hmm, very slow
...
@@ -188,6 +189,7 @@ def hook_interrupt(uc, intno, user_data):
...
@@ -188,6 +189,7 @@ def hook_interrupt(uc, intno, user_data):
print
(
"exit(
%
d) ran
%.2
f million instructions,
%
d binary searches"
%
(
a0
,
icount
/
1_000_000
,
math
.
ceil
(
math
.
log2
(
icount
))))
print
(
"exit(
%
d) ran
%.2
f million instructions,
%
d binary searches"
%
(
a0
,
icount
/
1_000_000
,
math
.
ceil
(
math
.
log2
(
icount
))))
else
:
else
:
print
(
"exit(
%
d)"
%
a0
)
print
(
"exit(
%
d)"
%
a0
)
hexdump
(
uc
.
mem_read
(
0x30000800
,
0x20
))
sys
.
stdout
.
flush
()
sys
.
stdout
.
flush
()
sys
.
stderr
.
flush
()
sys
.
stderr
.
flush
()
os
.
_exit
(
a0
)
os
.
_exit
(
a0
)
...
@@ -264,6 +266,11 @@ mu.mem_map(heap_start, 256*1024*1024)
...
@@ -264,6 +266,11 @@ mu.mem_map(heap_start, 256*1024*1024)
# brk (1024 MB) @ 0x40000000
# brk (1024 MB) @ 0x40000000
mu
.
mem_map
(
brk_start
,
1024
*
1024
*
1024
)
mu
.
mem_map
(
brk_start
,
1024
*
1024
*
1024
)
# input oracle
mu
.
mem_map
(
0x30000000
,
4096
)
dat
=
open
(
"/tmp/eth/13284469"
,
"rb"
)
.
read
()
mu
.
mem_write
(
0x30000000
,
dat
)
# regs at 0xC0000000 in merkle
# regs at 0xC0000000 in merkle
elffile
=
ELFFile
(
elf
)
elffile
=
ELFFile
(
elf
)
...
@@ -279,14 +286,14 @@ mu.reg_write(UC_MIPS_REG_SP, SIZE-0x2000)
...
@@ -279,14 +286,14 @@ mu.reg_write(UC_MIPS_REG_SP, SIZE-0x2000)
# http://articles.manugarg.com/aboutelfauxiliaryvectors.html
# http://articles.manugarg.com/aboutelfauxiliaryvectors.html
_AT_PAGESZ
=
6
_AT_PAGESZ
=
6
mu
.
mem_write
(
SIZE
-
0x2000
,
struct
.
pack
(
">IIIIIIII
I
"
,
mu
.
mem_write
(
SIZE
-
0x2000
,
struct
.
pack
(
">IIIIIIII"
,
2
,
# argc
1
,
# argc
SIZE
-
0x1000
,
SIZE
-
0x800
,
0
,
# argv
SIZE
-
0x1000
,
0
,
# argv
SIZE
-
0x400
,
0
,
# envp
SIZE
-
0x400
,
0
,
# envp
_AT_PAGESZ
,
0x1000
,
0
))
# auxv
_AT_PAGESZ
,
0x1000
,
0
))
# auxv
# block
# block
mu
.
mem_write
(
SIZE
-
0x800
,
b
"13284469
\x00
"
)
#
mu.mem_write(SIZE-0x800, b"13284469\x00")
#mu.mem_write(SIZE-0x800, b"13284469\x00")
#mu.mem_write(SIZE-0x800, b"13284469\x00")
mu
.
mem_write
(
SIZE
-
0x400
,
b
"GOGC=off
\x00
"
)
mu
.
mem_write
(
SIZE
-
0x400
,
b
"GOGC=off
\x00
"
)
...
...
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