Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PRT contracts unit tests #110

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions prt/contracts/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,4 @@ docs/
# Coverage
report
lcov.info

# Test
test/uarch-log
lcov.info.pruned
9 changes: 7 additions & 2 deletions prt/contracts/coverage.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
#!/bin/bash
#!/usr/bin/env bash
set -euo pipefail

# requires lcov - sudo apt-get install lcov
forge coverage --report lcov
genhtml -o report --branch-coverage lcov.info
# removes irrelevance from coverage report
lcov --remove ./lcov.info '*script*' '*step*' '*test*' -o ./lcov.info.pruned
genhtml -o report --branch-coverage lcov.info.pruned
4 changes: 2 additions & 2 deletions prt/contracts/src/CanonicalConstants.sol
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,13 @@ library ArbitrationConstants {

/// @return log2step gap of each leaf in the tournament[level]
function log2step(uint64 level) internal pure returns (uint64) {
uint64[LEVELS] memory arr = [uint64(44), uint64(28), uint64(0)];
uint64[LEVELS] memory arr = [uint64(44), uint64(27), uint64(0)];
return arr[level];
}

/// @return height of the tournament[level] tree which is calculated by subtracting the log2step[level] from the log2step[level - 1]
function height(uint64 level) internal pure returns (uint64) {
uint64[LEVELS] memory arr = [uint64(48), uint64(16), uint64(28)];
uint64[LEVELS] memory arr = [uint64(48), uint64(17), uint64(27)];
return arr[level];
}
}
10 changes: 0 additions & 10 deletions prt/contracts/src/tournament/abstracts/NonLeafTournament.sol
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,6 @@ abstract contract NonLeafTournament is Tournament {
//
event newInnerTournament(Match.IdHash indexed, NonRootTournament);

//
// Modifiers
//
modifier onlyInnerTournament() {
Match.IdHash matchIdHash =
matchIdFromInnerTournaments[NonRootTournament(msg.sender)];
matches[matchIdHash].requireExist();
_;
}

//
// Constructor
//
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,11 @@ contract MultiLevelTournamentFactory is IMultiLevelTournamentFactory {
maxAllowance = _disputeParameters.timeConstants.maxAllowance;
log2step0 = _disputeParameters.commitmentStructures[0].log2step;
height0 = _disputeParameters.commitmentStructures[0].height;
commitmentStructures = _disputeParameters.commitmentStructures;
for (uint64 i = 0; i < levels; i++) {
commitmentStructures.push(
_disputeParameters.commitmentStructures[i]
);
}
}

function instantiate(Machine.Hash _initialHash, IDataProvider _provider)
Expand Down
17 changes: 13 additions & 4 deletions prt/contracts/src/tournament/libs/Commitment.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ import "../../CanonicalConstants.sol";
import "../../Tree.sol";
import "../../Machine.sol";

// import "./Merkle.sol";

library Commitment {
using Tree for Tree.Node;
using Commitment for Tree.Node;

error CommitmentMismatch(Tree.Node received, Tree.Node expected);

function requireState(
Tree.Node commitment,
uint64 treeHeight,
Expand All @@ -23,20 +23,29 @@ library Commitment {
Tree.Node expectedCommitment =
getRoot(Machine.Hash.unwrap(state), treeHeight, position, hashProof);

require(commitment.eq(expectedCommitment), "commitment state mismatch");
require(
commitment.eq(expectedCommitment),
CommitmentMismatch(commitment, expectedCommitment)
);
}

function isEven(uint256 x) private pure returns (bool) {
return x % 2 == 0;
}

error LengthMismatch(uint64 treeHeight, uint64 siblingsLength);

function getRoot(
bytes32 leaf,
uint64 treeHeight,
uint256 position,
bytes32[] calldata siblings
) internal pure returns (Tree.Node) {
assert(treeHeight == siblings.length);
uint64 siblingsLength = uint64(siblings.length);
require(
treeHeight == siblingsLength,
LengthMismatch(treeHeight, siblingsLength)
);

for (uint256 i = 0; i < treeHeight; i++) {
if (isEven(position >> i)) {
Expand Down
51 changes: 0 additions & 51 deletions prt/contracts/src/tournament/libs/Merkle.sol

This file was deleted.

Loading
Loading