Skip to content

Commit

Permalink
Fix bug with byes
Browse files Browse the repository at this point in the history
  • Loading branch information
area committed Feb 15, 2020
1 parent 831c63c commit eb93fa1
Show file tree
Hide file tree
Showing 9 changed files with 295 additions and 33 deletions.
6 changes: 6 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,12 @@ jobs:
sed -i "s/000000000000000000000000000000deadbeef10/$(parity account new --chain ./parity-genesis.json --keys-path ./keys --password ./parityPassword)/g" ./parity-genesis.json
sed -i "s/000000000000000000000000000000deadbeef11/$(parity account new --chain ./parity-genesis.json --keys-path ./keys --password ./parityPassword)/g" ./parity-genesis.json
sed -i "s/000000000000000000000000000000deadbeef12/$(parity account new --chain ./parity-genesis.json --keys-path ./keys --password ./parityPassword)/g" ./parity-genesis.json
sed -i "s/000000000000000000000000000000deadbeef13/$(parity account new --chain ./parity-genesis.json --keys-path ./keys --password ./parityPassword)/g" ./parity-genesis.json
sed -i "s/000000000000000000000000000000deadbeef14/$(parity account new --chain ./parity-genesis.json --keys-path ./keys --password ./parityPassword)/g" ./parity-genesis.json
sed -i "s/000000000000000000000000000000deadbeef15/$(parity account new --chain ./parity-genesis.json --keys-path ./keys --password ./parityPassword)/g" ./parity-genesis.json
sed -i "s/000000000000000000000000000000deadbeef16/$(parity account new --chain ./parity-genesis.json --keys-path ./keys --password ./parityPassword)/g" ./parity-genesis.json
sed -i "s/000000000000000000000000000000deadbeef17/$(parity account new --chain ./parity-genesis.json --keys-path ./keys --password ./parityPassword)/g" ./parity-genesis.json
sed -i "s/000000000000000000000000000000deadbeef18/$(parity account new --chain ./parity-genesis.json --keys-path ./keys --password ./parityPassword)/g" ./parity-genesis.json
- run:
name: "Install lsof"
command: |
Expand Down
2 changes: 1 addition & 1 deletion .solcover.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ module.exports = {
network_id: 1999,
account_keys_path: "./ganache-accounts.json",
vmErrorsOnRPCResponse: false,
total_accounts: 12
total_accounts: 18
},
onCompileComplete: provisionTokenContracts
}
Expand Down
23 changes: 16 additions & 7 deletions contracts/ReputationMiningCycle.sol
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,15 @@ contract ReputationMiningCycle is ReputationMiningCycleStorage, PatriciaTreeProo
}

function challengeRoundComplete(uint256 round) public view returns (bool) {
return nHashesCompletedChallengeRound[round] == disputeRounds[round].length;
if (!submissionWindowClosed()) {
return false;
}
for (uint i = firstIncompleteRound; i <= round; i += 1) {
if (nHashesCompletedChallengeRound[i] != disputeRounds[i].length) {
return false;
}
}
return true;
}

function submitRootHash(bytes32 newHash, uint256 nNodes, bytes32 jrh, uint256 entryIndex) public
Expand Down Expand Up @@ -229,14 +237,15 @@ contract ReputationMiningCycle is ReputationMiningCycleStorage, PatriciaTreeProo
// this is the slot after the last entry, and so our opponentIdx will be the last entry
// We just move the opponent on, and nothing else happens.

if (round == 0) {
// If we're in round zero, require that no more submissions can be made
require(submissionWindowClosed(), "colony-reputation-mining-submission-window-still-open");
} else {
// Otherwise, ensure that the previous round is complete, and this entry wouldn't possibly get an opponent later on.
// In all cases, if the window is still open, the submission could still get an opponent
require(submissionWindowClosed(), "colony-reputation-mining-submission-window-still-open");
// If we are past the first round, check that all previous rounds are complete (i.e we won't get an opponent)
if (round > 0) {
require(challengeRoundComplete(round - 1), "colony-reputation-mining-previous-dispute-round-not-complete");
}

// All previous rounds are complete, so update variable to allow loop to short-circuit in future
// Note that this round is not necessarily complete - there could still be ongoing disputes in this round
firstIncompleteRound = round;

// Prevent us invalidating the final hash
require(disputeRounds[round].length > 1, "colony-reputation-mining-cannot-invalidate-final-hash");
Expand Down
2 changes: 2 additions & 0 deletions contracts/ReputationMiningCycleStorage.sol
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,6 @@ contract ReputationMiningCycleStorage is ReputationMiningCycleDataTypes, DSAuth

int256 constant MAX_INT128 = 2**127 - 1;
int256 constant MIN_INT128 = (2**127)*(-1);

uint256 firstIncompleteRound;
}
22 changes: 22 additions & 0 deletions helpers/test-helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -459,6 +459,28 @@ export async function advanceMiningCycleNoContest({ colonyNetwork, client, miner
await repCycle.confirmNewHash(0);
}

export async function accommodateChallengeAndInvalidateHashViaTimeout(colonyNetwork, test, client1) {
const repCycle = await getActiveRepCycle(colonyNetwork);
const [round1, idx1] = await client1.getMySubmissionRoundAndIndex();
// Make a submission from client1
const submission1before = await repCycle.getReputationHashSubmission(client1.minerAddress);

// Submit JRH for submission 1 if needed
// We only do this if client2 is defined so that we test JRH submission in rounds other than round 0.
if (submission1before.jrhNNodes === "0") {
await checkSuccessEthers(client1.confirmJustificationRootHash(), "Client1 was unable to confirmJustificationRootHash");
} else {
await checkSuccessEthers(client1.respondToBinarySearchForChallenge(), "Client 1 was unable to respondToBinarySearchForChallenge");
}

// Timeout the other client
await forwardTime(600, test);
const toInvalidateIdx = idx1.mod(2) === 1 ? idx1.sub(1) : idx1.add(1);

const accounts = await web3GetAccounts();
return repCycle.invalidateHash(round1, toInvalidateIdx, { from: accounts[5] });
}

export async function accommodateChallengeAndInvalidateHash(colonyNetwork, test, client1, client2, _errors) {
let toInvalidateIdx;
const repCycle = await getActiveRepCycle(colonyNetwork);
Expand Down
8 changes: 7 additions & 1 deletion parity-genesis.template.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,12 @@
"000000000000000000000000000000deadbeef09": { "balance": "1000000000000000000000" },
"000000000000000000000000000000deadbeef10": { "balance": "1000000000000000000000" },
"000000000000000000000000000000deadbeef11": { "balance": "1000000000000000000000" },
"000000000000000000000000000000deadbeef12": { "balance": "1000000000000000000000" }
"000000000000000000000000000000deadbeef12": { "balance": "1000000000000000000000" },
"000000000000000000000000000000deadbeef13": { "balance": "1000000000000000000000" },
"000000000000000000000000000000deadbeef14": { "balance": "1000000000000000000000" },
"000000000000000000000000000000deadbeef15": { "balance": "1000000000000000000000" },
"000000000000000000000000000000deadbeef16": { "balance": "1000000000000000000000" },
"000000000000000000000000000000deadbeef17": { "balance": "1000000000000000000000" },
"000000000000000000000000000000deadbeef18": { "balance": "1000000000000000000000" }
}
}
8 changes: 7 additions & 1 deletion scripts/resetParity.sh
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,10 @@ $SED -i "s/000000000000000000000000000000deadbeef08/$(parity account new --chain
$SED -i "s/000000000000000000000000000000deadbeef09/$(parity account new --chain ./parity-genesis.json --keys-path ./keys --password ./parityPassword)/g" ./parity-genesis.json
$SED -i "s/000000000000000000000000000000deadbeef10/$(parity account new --chain ./parity-genesis.json --keys-path ./keys --password ./parityPassword)/g" ./parity-genesis.json
$SED -i "s/000000000000000000000000000000deadbeef11/$(parity account new --chain ./parity-genesis.json --keys-path ./keys --password ./parityPassword)/g" ./parity-genesis.json
$SED -i "s/000000000000000000000000000000deadbeef12/$(parity --chain ./parity-genesis.json --keys-path ./keys account list | head -n1)/g" ./parity-genesis.json
$SED -i "s/000000000000000000000000000000deadbeef12/$(parity account new --chain ./parity-genesis.json --keys-path ./keys --password ./parityPassword)/g" ./parity-genesis.json
$SED -i "s/000000000000000000000000000000deadbeef13/$(parity account new --chain ./parity-genesis.json --keys-path ./keys --password ./parityPassword)/g" ./parity-genesis.json
$SED -i "s/000000000000000000000000000000deadbeef14/$(parity account new --chain ./parity-genesis.json --keys-path ./keys --password ./parityPassword)/g" ./parity-genesis.json
$SED -i "s/000000000000000000000000000000deadbeef15/$(parity account new --chain ./parity-genesis.json --keys-path ./keys --password ./parityPassword)/g" ./parity-genesis.json
$SED -i "s/000000000000000000000000000000deadbeef16/$(parity account new --chain ./parity-genesis.json --keys-path ./keys --password ./parityPassword)/g" ./parity-genesis.json
$SED -i "s/000000000000000000000000000000deadbeef17/$(parity account new --chain ./parity-genesis.json --keys-path ./keys --password ./parityPassword)/g" ./parity-genesis.json
$SED -i "s/000000000000000000000000000000deadbeef18/$(parity account new --chain ./parity-genesis.json --keys-path ./keys --password ./parityPassword)/g" ./parity-genesis.json
10 changes: 8 additions & 2 deletions scripts/start-blockchain-client.sh
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,13 @@ start_ganache() {
--account="0xe31c452e0631f67a629e88790d3119ea9505fae758b54976d2bf12bd8300ef4a, 100000000000000000000" \
--account="0x5e383d2f98ac821c555333e5bb6109ca41ae89d613cb84887a2bdb933623c4e3, 100000000000000000000" \
--account="0x33d2f6f6cc410c1d46d58f17efdd2b53a71527b27eaa7f2edcade351feb87425, 100000000000000000000" \
--account="0x32400a48ff16119c134eef44e2627502ce6e367bc4810be07642275a9db47bf7, 100000000000000000000" >/dev/null 2>&1
--account="0x32400a48ff16119c134eef44e2627502ce6e367bc4810be07642275a9db47bf7, 100000000000000000000" \
--account="0x2a0f58ae46261b4ec4b635bde4bfabb680245c2a3abff7f54945ae44f7629b1d, 100000000000000000000" \
--account="0x94fe165ae1db4f7d24fa5506ecbf083dcb934823600cb56e2a191722f0b40903, 100000000000000000000" \
--account="0xc93aad16dd4aca2fa61316f83307362306ad6b2fc3e4a91801ce9010be7d9b63, 100000000000000000000" \
--account="0x27f8f0be23a027196c7b8f4c98502b113e3fa1474fc10eda21ef3b5473c1b773, 100000000000000000000" \
--account="0xb6245e0d2b64a92c0e6359500231087278f499de46fdfa351d4f1e09faf95a47, 100000000000000000000" \
--account="0xfe6066af949ec3c2c88ac10f47907c6d4e200c37b28b5af49e7d0ffd5c301c5c, 100000000000000000000" >/dev/null 2>&1
}

start_parity() {
Expand All @@ -41,7 +47,7 @@ start_parity() {
exit 1;
else
parity --chain ./parity-genesis.json --author ${addresses[0]} \
--unlock ${addresses[0]},${addresses[1]},${addresses[2]},${addresses[3]},${addresses[4]},${addresses[5]},${addresses[6]},${addresses[7]},${addresses[8]},${addresses[9]},${addresses[10]},${addresses[11]} \
--unlock ${addresses[0]},${addresses[1]},${addresses[2]},${addresses[3]},${addresses[4]},${addresses[5]},${addresses[6]},${addresses[7]},${addresses[8]},${addresses[9]},${addresses[10]},${addresses[11]},${addresses[12]},${addresses[13]},${addresses[14]},${addresses[15]},${addresses[16]},${addresses[17]} \
--keys-path ./keys --geth --tx-gas-limit 0x6691B7 --gas-floor-target 0x6691B7 \
--reseal-on-txs all --reseal-min-period 0 \
--jsonrpc-interface all --jsonrpc-hosts all --jsonrpc-cors="http://localhost:3000" \
Expand Down
Loading

0 comments on commit eb93fa1

Please sign in to comment.