Commit 6d1ca43f authored by George Hotz's avatar George Hotz

fix the blockhash issue by forking at block

parent b5d884fb
......@@ -47,31 +47,32 @@ npx hardhat run scripts/deploy.js
## Full Challenge / Response
```
# testing on hardhat (forked mainnet)
npx hardhat node --fork https://mainnet.infura.io/v3/9aa3d95b3bc440fa88ea12eaa4456161
# testing on hardhat (forked mainnet, a few blocks ahead of challenge)
npx hardhat node --fork https://mainnet.infura.io/v3/9aa3d95b3bc440fa88ea12eaa4456161 --fork-block-number 13284495
# challenger is pretending the block 10 transition is the transition for 1171895
# challenger is pretending the block 13284491 transition is the transition for 13284469
# this will conflict at the first step
rm -rf /tmp/cannon/*
mipsevm/mipsevm
npx hardhat run scripts/deploy.js --network hosthat
minigeth/go-ethereum 1171895 && mipsevm/mipsevm 1171895
minigeth/go-ethereum 10 && mipsevm/mipsevm 10
BLOCK=1171895 npx hardhat run scripts/challenge.js --network hosthat
# compute the MIPS checkpoints
minigeth/go-ethereum 13284491 && mipsevm/mipsevm 13284491
minigeth/go-ethereum 13284469 && mipsevm/mipsevm 13284469
BLOCK=13284469 npx hardhat run scripts/challenge.js --network hosthat
# do binary search
for i in {1..23}
do
ID=0 BLOCK=10 CHALLENGER=1 npx hardhat run scripts/respond.js --network hosthat
ID=0 BLOCK=1171895 npx hardhat run scripts/respond.js --network hosthat
ID=0 BLOCK=13284491 CHALLENGER=1 npx hardhat run scripts/respond.js --network hosthat
ID=0 BLOCK=13284469 npx hardhat run scripts/respond.js --network hosthat
done
# assert as challenger (fails)
ID=0 BLOCK=10 CHALLENGER=1 npx hardhat run scripts/assert.js --network hosthat
ID=0 BLOCK=13284491 CHALLENGER=1 npx hardhat run scripts/assert.js --network hosthat
# assert as defender (passes)
ID=0 BLOCK=1171895 npx hardhat run scripts/assert.js --network hosthat
ID=0 BLOCK=13284469 npx hardhat run scripts/assert.js --network hosthat
```
## State Oracle API
......
......@@ -105,18 +105,17 @@ contract Challenge {
bytes32 blockNumberNHash = blockhash(blockNumberN);
bytes32 blockNumberNp1Hash = blockhash(blockNumberN+1);
// TODO: this is only removed for testing. zero security without it
/*if (blockNumberNHash == bytes32(0) || blockNumberNp1Hash == bytes32(0)) {
if (blockNumberNHash == bytes32(0) || blockNumberNp1Hash == bytes32(0)) {
revert("block number too old to challenge");
}
require(blockNumberNp1Hash == computedBlockHash, "end block hash wrong");*/
require(blockNumberNp1Hash == computedBlockHash, "end block hash wrong");
// decode the blocks
bytes32 inputHash;
{
Lib_RLPReader.RLPItem[] memory blockNp1 = Lib_RLPReader.readList(blockHeaderNp1);
bytes32 parentHash = Lib_RLPReader.readBytes32(blockNp1[0]);
//require(blockNumberNHash == parentHash, "parent block hash somehow wrong");
require(blockNumberNHash == 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");
......
......@@ -58,7 +58,6 @@ func main() {
mu.RegWrite(uc.MIPS_REG_PC, 0x5ead0004)
}
}
// TODO: is this where the plus 1 goes?
lastStep = step + 1
})
......
......@@ -21,9 +21,9 @@ async function main() {
/*const assertionRoot = "0x1111111111111111111111111111111111111111111111111111111111111111"
let finalTrie = JSON.parse(fs.readFileSync("/tmp/cannon/0_"+blockNumberN.toString()+"/checkpoint_final.json"))*/
// we are submitting the (wrong) transition for block 10 as the attacker
const assertionRoot = "0x03f930c087b70f3385db68fe6bf128719e2d9a4b0a133e53b32db2fa25d345fd"
let finalTrie = JSON.parse(fs.readFileSync("/tmp/cannon/0_10/checkpoint_final.json"))
// we are submitting the (wrong) transition for block 13284469 as the attacker
const assertionRoot = "0xb0b8fc0cf929b8b7a1a31059e1dfb321e78ff0dfe5912d5c615beaf37ec608e7"
let finalTrie = JSON.parse(fs.readFileSync("/tmp/cannon/0_13284491/checkpoint_final.json"))
let preimages = Object.assign({}, startTrie['preimages'], finalTrie['preimages']);
const finalSystemState = finalTrie['root']
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment