Commit 8c2b0368 authored by Nicolas "Norswap" Laurent's avatar Nicolas "Norswap" Laurent Committed by norswap

merge InitChallenge with newChallengeTrusted

parent acd3fa6f
...@@ -46,11 +46,17 @@ contract Challenge { ...@@ -46,11 +46,17 @@ contract Challenge {
} }
struct Chal { struct Chal {
// Left bound of the binary search: challenger & defender agree on all steps <= L.
uint256 L; uint256 L;
// Right bound of the binary search: challenger & defender disagree on all steps >= R.
uint256 R; uint256 R;
// Maps step numbers to asserted state hashes for the challenger.
mapping(uint256 => bytes32) assertedState; mapping(uint256 => bytes32) assertedState;
// Maps step numbers to asserted state hashes for the defender.
mapping(uint256 => bytes32) defendedState; mapping(uint256 => bytes32) defendedState;
// Address of the challenger.
address payable challenger; address payable challenger;
// Block number preceding the challenged block.
uint256 blockNumberN; uint256 blockNumberN;
} }
...@@ -155,33 +161,18 @@ contract Challenge { ...@@ -155,33 +161,18 @@ contract Challenge {
require(mem.ReadBytes32(finalSystemState, 0x30000804) == assertionRoot, require(mem.ReadBytes32(finalSystemState, 0x30000804) == assertionRoot,
"the final MIPS machine state asserts a different state root than your challenge"); "the final MIPS machine state asserts a different state root than your challenge");
return newChallengeTrusted(blockNumberN, startState, finalSystemState, stepCount); uint256 challengeId = lastChallengeId++;
}
function newChallengeTrusted(
uint256 blockNumberN, bytes32 startState, bytes32 finalSystemState, uint256 stepCount)
internal
returns (uint256)
{
uint256 challengeId = lastChallengeId;
Chal storage c = challenges[challengeId]; Chal storage c = challenges[challengeId];
lastChallengeId += 1;
// the challenger arrives // A NEW CHALLENGER APPEARS
c.challenger = msg.sender; c.challenger = msg.sender;
// the state is set
c.blockNumberN = blockNumberN; c.blockNumberN = blockNumberN;
// NOTE: if they disagree on the start, 0->1 will fail
c.assertedState[0] = startState; c.assertedState[0] = startState;
c.defendedState[0] = startState; c.defendedState[0] = startState;
c.assertedState[stepCount] = finalSystemState; c.assertedState[stepCount] = finalSystemState;
// init the binary search
c.L = 0; c.L = 0;
c.R = stepCount; c.R = stepCount;
// find me later
emit ChallengeCreate(challengeId); emit ChallengeCreate(challengeId);
return challengeId; return challengeId;
} }
......
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