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
19580c2f
Commit
19580c2f
authored
Oct 31, 2021
by
George Hotz
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
challenge test, will fail until i put in the trie nodes
parent
2c47146a
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
44 additions
and
18 deletions
+44
-18
Challenge.sol
contracts/Challenge.sol
+21
-16
challenge_test.js
test/challenge_test.js
+23
-2
No files found.
contracts/Challenge.sol
View file @
19580c2f
...
...
@@ -2,6 +2,7 @@
pragma solidity ^0.7.3;
import "./lib/Lib_RLPReader.sol";
import "hardhat/console.sol";
interface IMIPS {
function Step(bytes32 stateHash) external returns (bytes32);
...
...
@@ -75,24 +76,28 @@ contract Challenge {
function InitiateChallenge(uint blockNumberN, bytes calldata blockHeaderNp1,
bytes32 assertionRoot, bytes32 finalSystemState, uint256 stepCount) external returns (uint256) {
require(blockhash(blockNumberN+1) == keccak256(blockHeaderNp1), "end block hash wrong");
bytes32 computedBlockHash = keccak256(blockHeaderNp1);
require(blockhash(blockNumberN+1) == computedBlockHash, "end block hash wrong");
// 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");
// load starting info into the input oracle
// we both agree at the beginning
bytes32 txhash = Lib_RLPReader.readBytes32(blockNp1[4]);
bytes32 coinbase = bytes32(uint256(Lib_RLPReader.readAddress(blockNp1[2])));
bytes32 unclehash = Lib_RLPReader.readBytes32(blockNp1[1]);
bytes32 gaslimit = bytes32(Lib_RLPReader.readUint256(blockNp1[9]));
bytes32 time = bytes32(Lib_RLPReader.readUint256(blockNp1[11]));
bytes32 inputHash = keccak256(abi.encodePacked(parentHash, txhash, coinbase, unclehash, gaslimit, time));
bytes32 inputHash;
{
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");
// load starting info into the input oracle
// we both agree at the beginning
bytes32 txhash = Lib_RLPReader.readBytes32(blockNp1[4]);
bytes32 coinbase = bytes32(uint256(Lib_RLPReader.readAddress(blockNp1[2])));
bytes32 unclehash = Lib_RLPReader.readBytes32(blockNp1[1]);
bytes32 gaslimit = bytes32(Lib_RLPReader.readUint256(blockNp1[9]));
bytes32 time = bytes32(Lib_RLPReader.readUint256(blockNp1[11]));
inputHash = keccak256(abi.encodePacked(parentHash, txhash, coinbase, unclehash, gaslimit, time));
}
bytes32 startState = GlobalStartState;
startState = mem.WriteBytes32(startState, 0xB0000000, inputHash);
...
...
test/challenge_test.js
View file @
19580c2f
const
{
expect
}
=
require
(
"
chai
"
);
// golden minigeth.bin hash
const
goldenRoot
=
"
0x9c15aa86416a3a9d3b15188fc9f9be59626c1f83a33e5d63b58ca1bf0f8cef71
"
describe
(
"
Challenge contract
"
,
function
()
{
beforeEach
(
async
function
()
{
// this mips can be reused for other challenges
...
...
@@ -7,10 +10,28 @@ describe("Challenge contract", function () {
const
m
=
await
MIPS
.
deploy
()
const
Challenge
=
await
ethers
.
getContractFactory
(
"
Challenge
"
)
// golden minigeth.bin hash
c
=
await
Challenge
.
deploy
(
m
.
address
,
"
0x9c15aa86416a3a9d3b15188fc9f9be59626c1f83a33e5d63b58ca1bf0f8cef71
"
)
c
=
await
Challenge
.
deploy
(
m
.
address
,
goldenRoot
)
})
it
(
"
challenge contract deploys
"
,
async
function
()
{
console
.
log
(
"
Challenge deployed at
"
,
c
.
address
)
})
it
(
"
initiate challenge
"
,
async
function
()
{
// TODO: is there a better way to get the "HardhatNetworkProvider"?
const
hardhat
=
network
.
provider
.
_wrapped
.
_wrapped
.
_wrapped
.
_wrapped
.
_wrapped
const
blockchain
=
hardhat
.
_node
.
_blockchain
// get data
const
blockNumberN
=
(
await
ethers
.
provider
.
getBlockNumber
())
-
1
;
const
blockNp1
=
blockchain
.
_data
.
_blocksByNumber
.
get
(
blockNumberN
+
1
)
const
blockNp1Rlp
=
blockNp1
.
header
.
serialize
()
const
assertionRoot
=
"
0x1337133713371337133713371337133713371337133713371337133713371337
"
// TODO: compute a valid one of these
const
finalSystemState
=
"
0x1337133713371337133713371337133713371337133713371337133713371337
"
await
c
.
InitiateChallenge
(
blockNumberN
,
blockNp1Rlp
,
assertionRoot
,
finalSystemState
,
1
)
//const blockHeaderNp1 = getBlockRlp(await ethers.provider.getBlock(blockNumberN+1));
//console.log(blockNumberN, blockHeaderNp1);
})
})
\ No newline at end of file
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