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

uncapitalize variable & function names in Challenge.sol

parent e218c6b0
...@@ -36,13 +36,13 @@ contract Challenge { ...@@ -36,13 +36,13 @@ contract Challenge {
IMIPSMemory immutable mem; IMIPSMemory immutable mem;
// State hash of the fault proof program's initial MIPS state. // State hash of the fault proof program's initial MIPS state.
bytes32 immutable GlobalStartState; bytes32 immutable globalStartState;
constructor(IMIPS imips, bytes32 globalStartState) { constructor(IMIPS _mips, bytes32 _globalStartState) {
owner = msg.sender; owner = msg.sender;
mips = imips; mips = _mips;
mem = imips.m(); mem = _mips.m();
GlobalStartState = globalStartState; globalStartState = _globalStartState;
} }
struct ChallengeData { struct ChallengeData {
...@@ -79,7 +79,7 @@ contract Challenge { ...@@ -79,7 +79,7 @@ contract Challenge {
event ChallengeCreated(uint256 challengeId); event ChallengeCreated(uint256 challengeId);
// helper function to determine what nodes we need // helper function to determine what nodes we need
function CallWithTrieNodes(address target, bytes calldata dat, bytes[] calldata nodes) public { function callWithTrieNodes(address target, bytes calldata dat, bytes[] calldata nodes) public {
for (uint i = 0; i < nodes.length; i++) { for (uint i = 0; i < nodes.length; i++) {
mem.AddTrieNode(nodes[i]); mem.AddTrieNode(nodes[i]);
} }
...@@ -108,7 +108,7 @@ contract Challenge { ...@@ -108,7 +108,7 @@ contract Challenge {
/// @param stepCount The number of steps (MIPS instructions) taken to execute the fault proof /// @param stepCount The number of steps (MIPS instructions) taken to execute the fault proof
/// program. /// program.
/// @return The challenge identifier /// @return The challenge identifier
function InitiateChallenge( function initiateChallenge(
uint blockNumberN, bytes calldata blockHeaderNp1, bytes32 assertionRoot, uint blockNumberN, bytes calldata blockHeaderNp1, bytes32 assertionRoot,
bytes32 finalSystemState, uint256 stepCount) bytes32 finalSystemState, uint256 stepCount)
external external
...@@ -150,7 +150,7 @@ contract Challenge { ...@@ -150,7 +150,7 @@ contract Challenge {
} }
// Write input hash at predefined memory address. // Write input hash at predefined memory address.
bytes32 startState = GlobalStartState; bytes32 startState = globalStartState;
startState = mem.WriteBytes32(startState, 0x30000000, inputHash); startState = mem.WriteBytes32(startState, 0x30000000, inputHash);
// Confirm that `finalSystemState` asserts the state you claim and that the machine is stopped. // Confirm that `finalSystemState` asserts the state you claim and that the machine is stopped.
...@@ -198,7 +198,7 @@ contract Challenge { ...@@ -198,7 +198,7 @@ contract Challenge {
return c.assertedState[stepNumber]; return c.assertedState[stepNumber];
} }
function ProposeState(uint256 challengeId, bytes32 riscState) external { function proposeState(uint256 challengeId, bytes32 riscState) external {
ChallengeData storage c = challenges[challengeId]; ChallengeData storage c = challenges[challengeId];
require(c.challenger != address(0), "invalid challenge"); require(c.challenger != address(0), "invalid challenge");
require(c.challenger == msg.sender, "must be challenger"); require(c.challenger == msg.sender, "must be challenger");
...@@ -209,7 +209,7 @@ contract Challenge { ...@@ -209,7 +209,7 @@ contract Challenge {
c.assertedState[stepNumber] = riscState; c.assertedState[stepNumber] = riscState;
} }
function RespondState(uint256 challengeId, bytes32 riscState) external { function respondState(uint256 challengeId, bytes32 riscState) external {
ChallengeData storage c = challenges[challengeId]; ChallengeData storage c = challenges[challengeId];
require(c.challenger != address(0), "invalid challenge"); require(c.challenger != address(0), "invalid challenge");
require(owner == msg.sender, "must be owner"); require(owner == msg.sender, "must be owner");
...@@ -237,7 +237,7 @@ contract Challenge { ...@@ -237,7 +237,7 @@ contract Challenge {
event ChallengerLoses(uint256 challengeId); event ChallengerLoses(uint256 challengeId);
event ChallengerLosesByDefault(uint256 challengeId); event ChallengerLosesByDefault(uint256 challengeId);
function ConfirmStateTransition(uint256 challengeId) external { function confirmStateTransition(uint256 challengeId) external {
ChallengeData storage c = challenges[challengeId]; ChallengeData storage c = challenges[challengeId];
require(c.challenger != address(0), "invalid challenge"); require(c.challenger != address(0), "invalid challenge");
//require(c.challenger == msg.sender, "must be challenger"); //require(c.challenger == msg.sender, "must be challenger");
...@@ -253,7 +253,7 @@ contract Challenge { ...@@ -253,7 +253,7 @@ contract Challenge {
emit ChallengerWins(challengeId); emit ChallengerWins(challengeId);
} }
function DenyStateTransition(uint256 challengeId) external { function denyStateTransition(uint256 challengeId) external {
ChallengeData storage c = challenges[challengeId]; ChallengeData storage c = challenges[challengeId];
require(c.challenger != address(0), "invalid challenge"); require(c.challenger != address(0), "invalid challenge");
//require(owner == msg.sender, "must be owner"); //require(owner == msg.sender, "must be owner");
......
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
# #
# (The input hash is automatically validated against the blockhash, so note that # (The input hash is automatically validated against the blockhash, so note that
# in this demo the challenger has to provide the correct (`BLOCK`) input hash to # in this demo the challenger has to provide the correct (`BLOCK`) input hash to
# the `InitiateChallenge` function of `Challenge.sol`, but will execute as # the `initiateChallenge` function of `Challenge.sol`, but will execute as
# though the input hash was the one derived from `WRONG_BLOCK`.) # though the input hash was the one derived from `WRONG_BLOCK`.)
# #
# Because the challenger uses the wrong inputs, it will assert a post-state # Because the challenger uses the wrong inputs, it will assert a post-state
......
...@@ -18,11 +18,11 @@ async function main() { ...@@ -18,11 +18,11 @@ async function main() {
let cdat let cdat
if (isChallenger) { if (isChallenger) {
// challenger declare victory // challenger declare victory
cdat = c.interface.encodeFunctionData("ConfirmStateTransition", [challengeId]) cdat = c.interface.encodeFunctionData("confirmStateTransition", [challengeId])
} else { } else {
// defender declare victory // defender declare victory
// note: not always possible // note: not always possible
cdat = c.interface.encodeFunctionData("DenyStateTransition", [challengeId]) cdat = c.interface.encodeFunctionData("denyStateTransition", [challengeId])
} }
let startTrie = getTrieAtStep(blockNumberN, step) let startTrie = getTrieAtStep(blockNumberN, step)
...@@ -36,9 +36,9 @@ async function main() { ...@@ -36,9 +36,9 @@ async function main() {
let ret let ret
if (isChallenger) { if (isChallenger) {
ret = await c.ConfirmStateTransition(challengeId) ret = await c.confirmStateTransition(challengeId)
} else { } else {
ret = await c.DenyStateTransition(challengeId) ret = await c.denyStateTransition(challengeId)
} }
let receipt = await ret.wait() let receipt = await ret.wait()
......
...@@ -32,14 +32,14 @@ async function main() { ...@@ -32,14 +32,14 @@ async function main() {
const finalSystemState = finalTrie['root'] const finalSystemState = finalTrie['root']
let args = [blockNumberN, blockNp1Rlp, assertionRoot, finalSystemState, finalTrie['step']] let args = [blockNumberN, blockNp1Rlp, assertionRoot, finalSystemState, finalTrie['step']]
let cdat = c.interface.encodeFunctionData("InitiateChallenge", args) let cdat = c.interface.encodeFunctionData("initiateChallenge", args)
let nodes = await getTrieNodesForCall(c, c.address, cdat, preimages) let nodes = await getTrieNodesForCall(c, c.address, cdat, preimages)
// run "on chain" // run "on chain"
for (n of nodes) { for (n of nodes) {
await mm.AddTrieNode(n) await mm.AddTrieNode(n)
} }
let ret = await c.InitiateChallenge(...args) let ret = await c.initiateChallenge(...args)
let receipt = await ret.wait() let receipt = await ret.wait()
// ChallengeCreated event // ChallengeCreated event
let challengeId = receipt.events[0].args['challengeId'].toNumber() let challengeId = receipt.events[0].args['challengeId'].toNumber()
......
...@@ -71,8 +71,8 @@ async function getTrieNodesForCall(c, caddress, cdat, preimages) { ...@@ -71,8 +71,8 @@ async function getTrieNodesForCall(c, caddress, cdat, preimages) {
while (1) { while (1) {
try { try {
// TODO: make this eth call? // TODO: make this eth call?
// needs something like InitiateChallengeWithTrieNodesj // needs something like initiateChallengeWithTrieNodesj
let calldata = c.interface.encodeFunctionData("CallWithTrieNodes", [caddress, cdat, nodes]) let calldata = c.interface.encodeFunctionData("callWithTrieNodes", [caddress, cdat, nodes])
ret = await ethers.provider.call({ ret = await ethers.provider.call({
to:c.address, to:c.address,
data:calldata data:calldata
......
...@@ -30,9 +30,9 @@ async function main() { ...@@ -30,9 +30,9 @@ async function main() {
let ret let ret
if (isProposing) { if (isProposing) {
ret = await c.ProposeState(challengeId, root) ret = await c.proposeState(challengeId, root)
} else { } else {
ret = await c.RespondState(challengeId, root) ret = await c.respondState(challengeId, root)
} }
let receipt = await ret.wait() let receipt = await ret.wait()
console.log("done", receipt.blockNumber) console.log("done", receipt.blockNumber)
......
...@@ -31,14 +31,14 @@ describe("Challenge contract", function () { ...@@ -31,14 +31,14 @@ describe("Challenge contract", function () {
const finalSystemState = finalTrie['root'] const finalSystemState = finalTrie['root']
let args = [blockNumberN, blockNp1Rlp, assertionRoot, finalSystemState, finalTrie['step']] let args = [blockNumberN, blockNp1Rlp, assertionRoot, finalSystemState, finalTrie['step']]
let cdat = c.interface.encodeFunctionData("InitiateChallenge", args) let cdat = c.interface.encodeFunctionData("initiateChallenge", args)
let nodes = await getTrieNodesForCall(c, c.address, cdat, preimages) let nodes = await getTrieNodesForCall(c, c.address, cdat, preimages)
// run "on chain" // run "on chain"
for (n of nodes) { for (n of nodes) {
await mm.AddTrieNode(n) await mm.AddTrieNode(n)
} }
let ret = await c.InitiateChallenge(...args) let ret = await c.initiateChallenge(...args)
let receipt = await ret.wait() let receipt = await ret.wait()
// ChallengeCreated event // ChallengeCreated event
let challengeId = receipt.events[0].args['challengeId'].toNumber() let challengeId = receipt.events[0].args['challengeId'].toNumber()
......
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