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

Bold merge merkle comments #244

Merged
merged 10 commits into from
Sep 12, 2024
Merged
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
2 changes: 1 addition & 1 deletion slither.db.json

Large diffs are not rendered by default.

21 changes: 11 additions & 10 deletions src/challengeV2/libraries/EdgeChallengeManagerLib.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
pragma solidity ^0.8.17;

import "./UintUtilsLib.sol";
import "./MerkleTreeLib.sol";
import "./MerkleTreeAccumulatorLib.sol";
import "./ChallengeEdgeLib.sol";
import "../../osp/IOneStepProofEntry.sol";
import "../../rollup/AssertionState.sol";
Expand Down Expand Up @@ -315,7 +315,7 @@ library EdgeChallengeManagerLib {
// if the start and end states are consistent with the claim edge
// this guarantees that the edge we're creating is a 'continuation' of the claim edge, it is
// a commitment to the states that between start and end states of the claim
MerkleTreeLib.verifyInclusionProof(
MerkleTreeAccumulatorLib.verifyInclusionProof(
claimEdge.startHistoryRoot,
startState,
claimEdge.startHeight,
Expand All @@ -328,7 +328,7 @@ library EdgeChallengeManagerLib {
// and later ensuring that the end state is part of the history commitment of the new edge ensures
// that the end history root of the new edge will be different for different claim ids, and therefore
// the edge ids will be different
MerkleTreeLib.verifyInclusionProof(
MerkleTreeAccumulatorLib.verifyInclusionProof(
claimEdge.endHistoryRoot, endState, claimEdge.endHeight, claimEndInclusionProof
);

Expand Down Expand Up @@ -363,8 +363,9 @@ library EdgeChallengeManagerLib {
) private pure returns (bytes32) {
// since zero layer edges have a start height of zero, we know that they are a size
// one tree containing only the start state. We can then compute the history root directly
bytes32 startHistoryRoot =
MerkleTreeLib.root(MerkleTreeLib.appendLeaf(new bytes32[](0), proofData.startState));
bytes32 startHistoryRoot = MerkleTreeAccumulatorLib.root(
MerkleTreeAccumulatorLib.appendLeaf(new bytes32[](0), proofData.startState)
);

// all end heights are expected to be a power of 2, the specific power is defined by the
// edge challenge manager itself
Expand All @@ -384,7 +385,7 @@ library EdgeChallengeManagerLib {
// We then ensure that that same end state is part of the end history root we're creating
// This ensures continuity of states between levels - the state is present in both this
// level and the one below
MerkleTreeLib.verifyInclusionProof(
MerkleTreeAccumulatorLib.verifyInclusionProof(
args.endHistoryRoot, proofData.endState, args.endHeight, proofData.inclusionProof
);

Expand All @@ -396,7 +397,7 @@ library EdgeChallengeManagerLib {
}
(bytes32[] memory preExpansion, bytes32[] memory preProof) =
abi.decode(args.prefixProof, (bytes32[], bytes32[]));
MerkleTreeLib.verifyPrefixProof(
MerkleTreeAccumulatorLib.verifyPrefixProof(
startHistoryRoot, 1, args.endHistoryRoot, args.endHeight + 1, preExpansion, preProof
);

Expand Down Expand Up @@ -682,7 +683,7 @@ library EdgeChallengeManagerLib {
{
(bytes32[] memory preExpansion, bytes32[] memory proof) =
abi.decode(prefixProof, (bytes32[], bytes32[]));
MerkleTreeLib.verifyPrefixProof(
MerkleTreeAccumulatorLib.verifyPrefixProof(
bisectionHistoryRoot,
middleHeight + 1,
ce.endHistoryRoot,
Expand Down Expand Up @@ -898,7 +899,7 @@ library EdgeChallengeManagerLib {
}

// the state in the onestep data must be committed to by the startHistoryRoot
MerkleTreeLib.verifyInclusionProof(
MerkleTreeAccumulatorLib.verifyInclusionProof(
store.edges[edgeId].startHistoryRoot,
oneStepData.beforeHash,
machineStep,
Expand All @@ -911,7 +912,7 @@ library EdgeChallengeManagerLib {
);

// check that the after state was indeed committed to by the endHistoryRoot
MerkleTreeLib.verifyInclusionProof(
MerkleTreeAccumulatorLib.verifyInclusionProof(
store.edges[edgeId].endHistoryRoot,
afterHash,
machineStep + 1,
Expand Down

Large diffs are not rendered by default.

14 changes: 7 additions & 7 deletions src/mocks/MerkleTreeAccess.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
//
pragma solidity ^0.8.17;

import "../challengeV2/libraries/MerkleTreeLib.sol";
import "../challengeV2/libraries/MerkleTreeAccumulatorLib.sol";
import "../challengeV2/libraries/UintUtilsLib.sol";

contract MerkleTreeAccess {
Expand All @@ -23,29 +23,29 @@ contract MerkleTreeAccess {
function root(
bytes32[] memory me
) external pure returns (bytes32) {
return MerkleTreeLib.root(me);
return MerkleTreeAccumulatorLib.root(me);
}

function appendCompleteSubTree(
bytes32[] memory me,
uint256 level,
bytes32 subtreeRoot
) external pure returns (bytes32[] memory) {
return MerkleTreeLib.appendCompleteSubTree(me, level, subtreeRoot);
return MerkleTreeAccumulatorLib.appendCompleteSubTree(me, level, subtreeRoot);
}

function appendLeaf(
bytes32[] memory me,
bytes32 leaf
) external pure returns (bytes32[] memory) {
return MerkleTreeLib.appendLeaf(me, leaf);
return MerkleTreeAccumulatorLib.appendLeaf(me, leaf);
}

function maximumAppendBetween(
uint256 startSize,
uint256 endSize
) external pure returns (uint256) {
return MerkleTreeLib.maximumAppendBetween(startSize, endSize);
return MerkleTreeAccumulatorLib.maximumAppendBetween(startSize, endSize);
}

function verifyPrefixProof(
Expand All @@ -56,7 +56,7 @@ contract MerkleTreeAccess {
bytes32[] memory preExpansion,
bytes32[] memory proof
) external pure {
return MerkleTreeLib.verifyPrefixProof(
return MerkleTreeAccumulatorLib.verifyPrefixProof(
preRoot, preSize, postRoot, postSize, preExpansion, proof
);
}
Expand All @@ -67,6 +67,6 @@ contract MerkleTreeAccess {
uint256 index,
bytes32[] memory proof
) external pure {
MerkleTreeLib.verifyInclusionProof(rootHash, leaf, index, proof);
MerkleTreeAccumulatorLib.verifyInclusionProof(rootHash, leaf, index, proof);
}
}
8 changes: 4 additions & 4 deletions test/Rollup.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -736,7 +736,7 @@ contract RollupTest is Test {
bytes32 h0 = osp.getMachineHash(beforeState.toExecutionState());
bytes32 h1 = osp.getMachineHash(afterState.toExecutionState());
randomStates1 = fillStatesInBetween(h0, h1, LAYERZERO_BLOCKEDGE_HEIGHT + 1);
afterState.endHistoryRoot = MerkleTreeLib.root(
afterState.endHistoryRoot = MerkleTreeAccumulatorLib.root(
ProofUtils.expansionFromLeaves(randomStates1, 0, LAYERZERO_BLOCKEDGE_HEIGHT + 1)
);
}
Expand Down Expand Up @@ -783,7 +783,7 @@ contract RollupTest is Test {
bytes32 h0 = osp.getMachineHash(beforeState.toExecutionState());
bytes32 h1 = osp.getMachineHash(afterState2.toExecutionState());
randomStates2 = fillStatesInBetween(h0, h1, LAYERZERO_BLOCKEDGE_HEIGHT + 1);
afterState2.endHistoryRoot = MerkleTreeLib.root(
afterState2.endHistoryRoot = MerkleTreeAccumulatorLib.root(
ProofUtils.expansionFromLeaves(randomStates2, 0, LAYERZERO_BLOCKEDGE_HEIGHT + 1)
);
}
Expand Down Expand Up @@ -1002,7 +1002,7 @@ contract RollupTest is Test {
data.assertionHash2
) = testSuccessCreateSecondChild();

bytes32 root = MerkleTreeLib.root(
bytes32 root = MerkleTreeAccumulatorLib.root(
ProofUtils.expansionFromLeaves(randomStates1, 0, LAYERZERO_BLOCKEDGE_HEIGHT + 1)
);

Expand Down Expand Up @@ -1036,7 +1036,7 @@ contract RollupTest is Test {
require(data.genesisInboxCount == 1, "A");
require(data.newInboxCount == 2, "B");

bytes32 root = MerkleTreeLib.root(
bytes32 root = MerkleTreeAccumulatorLib.root(
ProofUtils.expansionFromLeaves(randomStates2, 0, LAYERZERO_BLOCKEDGE_HEIGHT + 1)
);

Expand Down
Loading
Loading