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
21f5e0fe
Commit
21f5e0fe
authored
Sep 25, 2021
by
George Hotz
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
working with oracle on pc
parent
caca8779
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
37 additions
and
25 deletions
+37
-25
Challenge.sol
contracts/Challenge.sol
+9
-9
fake_ethash.go
minigeth/consensus/ethash/fake_ethash.go
+1
-1
main.go
minigeth/main.go
+14
-14
prefetch.go
minigeth/oracle/prefetch.go
+13
-1
No files found.
contracts/Challenge.sol
View file @
21f5e0fe
...
...
@@ -83,22 +83,22 @@ contract Challenge {
// decode the blocks
Lib_RLPReader.RLPItem[] memory blockNp1 = Lib_RLPReader.readList(blockHeaderNp1);
bytes32 parentHash = Lib_RLPReader.readBytes32(blockNp1[0]);
require(blockhash(blockNumberN) == parentHash, "parent block hash somehow wrong");
bytes32 newroot = Lib_RLPReader.readBytes32(blockNp1[3]);
require(assertionRoot != newroot, "asserting that the real state is correct is not a challenge");
// input oracle info
bytes32 txhash = Lib_RLPReader.readBytes32(blockNp1[4]);
address coinbase = Lib_RLPReader.readAddress(blockNp1[2]);
bytes32 uncles = Lib_RLPReader.readBytes32(blockNp1[1]);
// load starting info into the input oracle
// we both agree at the beginning
// the first instruction executed in MIPS should be an access of startState
// parentblockhash, txhash, coinbase, unclehash, gaslimit
bytes32 startState = GlobalStartState;
startState = writeBytes32(startState, 0xD0000000, blockhash(blockNumberN));
startState = writeBytes32(startState, 0xD0000020, txhash);
startState = writeBytes32(startState, 0xD0000040, bytes32(uint256(coinbase)));
startState = writeBytes32(startState, 0xD0000060, uncles);
startState = writeBytes32(startState, 0xD0000000, parentHash);
startState = writeBytes32(startState, 0xD0000020, Lib_RLPReader.readBytes32(blockNp1[4]));
startState = writeBytes32(startState, 0xD0000040, bytes32(uint256(Lib_RLPReader.readAddress(blockNp1[2]))));
startState = writeBytes32(startState, 0xD0000060, Lib_RLPReader.readBytes32(blockNp1[1]));
startState = writeBytes32(startState, 0xD0000080, bytes32(Lib_RLPReader.readUint256(blockNp1[9])));
// 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
...
...
minigeth/consensus/ethash/fake_ethash.go
View file @
21f5e0fe
...
...
@@ -101,7 +101,7 @@ func (ethash *Ethash) Finalize(chain consensus.ChainHeaderReader, header *types.
// Accumulate any block and uncle rewards and commit the final state root
accumulateRewards
(
chain
.
Config
(),
state
,
header
,
uncles
)
header
.
Root
=
state
.
IntermediateRoot
(
chain
.
Config
()
.
IsEIP158
(
header
.
Number
))
//
fmt.Println("new Root", header.Root)
fmt
.
Println
(
"new Root"
,
header
.
Root
)
}
func
(
ethash
*
Ethash
)
FinalizeAndAssemble
(
chain
consensus
.
ChainHeaderReader
,
header
*
types
.
Header
,
state
*
state
.
StateDB
,
txs
[]
*
types
.
Transaction
,
uncles
[]
*
types
.
Header
,
receipts
[]
*
types
.
Receipt
)
(
*
types
.
Block
,
error
)
{
...
...
minigeth/main.go
View file @
21f5e0fe
...
...
@@ -7,6 +7,7 @@ import (
"os"
"strconv"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/consensus/misc"
"github.com/ethereum/go-ethereum/core"
"github.com/ethereum/go-ethereum/core/state"
...
...
@@ -41,17 +42,16 @@ func main() {
// read header
var
newheader
types
.
Header
// from parent
newheader
.
ParentHash
=
parent
.
Hash
()
newheader
.
TxHash
=
oracle
.
Input
(
1
)
newheader
.
Number
=
big
.
NewInt
(
0
)
.
Add
(
parent
.
Number
,
big
.
NewInt
(
1
))
newheader
.
BaseFee
=
misc
.
CalcBaseFee
(
params
.
MainnetChainConfig
,
&
parent
)
/*{
f, _ := os.Open(fmt.Sprintf("data/block_%d", blockNumber+1))
rlpheader := rlp.NewStream(f, 0)
rlpheader.Decode(&newheader)
f.Close()
fmt.Println("read new block")
}*/
// from input oracle
newheader
.
TxHash
=
oracle
.
Input
(
1
)
newheader
.
Coinbase
=
common
.
BigToAddress
(
oracle
.
Input
(
2
)
.
Big
())
newheader
.
UncleHash
=
oracle
.
Input
(
3
)
newheader
.
GasLimit
=
oracle
.
Input
(
4
)
.
Big
()
.
Uint64
()
bc
:=
core
.
NewBlockChain
()
database
:=
state
.
NewDatabase
(
parent
)
...
...
@@ -80,16 +80,16 @@ func main() {
if
newheader
.
TxHash
!=
block
.
Header
()
.
TxHash
{
panic
(
"wrong transactions for block"
)
}
if
newheader
.
UncleHash
!=
block
.
Header
()
.
UncleHash
{
panic
(
"wrong uncles for block"
)
}
_
,
_
,
_
,
err
:=
processor
.
Process
(
block
,
statedb
,
vmconfig
)
if
err
!=
nil
{
log
.
Fatal
(
err
)
}
newroot
:=
statedb
.
IntermediateRoot
(
bc
.
Config
()
.
IsEIP158
(
newheader
.
Number
))
fmt
.
Println
(
"process done with hash"
,
parent
.
Root
,
"->"
,
block
.
Header
()
.
Root
,
"real"
,
newheader
.
Root
)
if
block
.
Header
()
.
Root
==
newheader
.
Root
{
fmt
.
Println
(
"good transition"
)
}
else
{
panic
(
"BAD transition :(("
)
}
fmt
.
Println
(
"process done with hash"
,
parent
.
Root
,
"->"
,
newroot
)
oracle
.
Output
(
newroot
)
}
minigeth/oracle/prefetch.go
View file @
21f5e0fe
...
...
@@ -159,12 +159,22 @@ func PrefetchCode(blockNumber *big.Int, addrHash common.Hash) {
preimages
[
hash
]
=
ret
}
var
inputs
[
4
]
common
.
Hash
var
inputs
[
5
]
common
.
Hash
var
realoutput
common
.
Hash
func
Input
(
index
int
)
common
.
Hash
{
return
inputs
[
index
]
}
func
Output
(
output
common
.
Hash
)
{
if
output
==
realoutput
{
fmt
.
Println
(
"good transition"
)
}
else
{
fmt
.
Println
(
output
,
"!="
,
realoutput
)
panic
(
"BAD transition :(("
)
}
}
func
PrefetchBlock
(
blockNumber
*
big
.
Int
,
startBlock
bool
,
hasher
types
.
TrieHasher
)
{
r
:=
jsonreq
{
Jsonrpc
:
"2.0"
,
Method
:
"eth_getBlockByNumber"
,
Id
:
1
}
r
.
Params
=
make
([]
interface
{},
2
)
...
...
@@ -200,6 +210,8 @@ func PrefetchBlock(blockNumber *big.Int, startBlock bool, hasher types.TrieHashe
inputs
[
1
]
=
blockHeader
.
TxHash
inputs
[
2
]
=
blockHeader
.
Coinbase
.
Hash
()
inputs
[
3
]
=
blockHeader
.
UncleHash
inputs
[
4
]
=
common
.
BigToHash
(
big
.
NewInt
(
int64
(
blockHeader
.
GasLimit
)))
realoutput
=
blockHeader
.
Root
txs
:=
make
([]
*
types
.
Transaction
,
len
(
jr
.
Result
.
Transactions
))
for
i
:=
0
;
i
<
len
(
jr
.
Result
.
Transactions
);
i
++
{
...
...
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