Skip to content
Draft
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
17 changes: 4 additions & 13 deletions contracts/src/ProtocolAdapter.sol
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ contract ProtocolAdapter is
using RiscZeroUtils for Logic.VerifierInput;
using Logic for Logic.VerifierInput[];
using Delta for uint256[2];
using Compliance for Compliance.VerifierInput[];

RiscZeroVerifierRouter internal immutable _TRUSTED_RISC_ZERO_VERIFIER_ROUTER;
bytes4 internal immutable _RISC_ZERO_VERIFIER_SELECTOR;
Expand Down Expand Up @@ -135,7 +136,7 @@ contract ProtocolAdapter is
// Check the consumed resource.
// slither-disable-next-line reentrancy-benign
_processResourceLogicContext({
input: action.logicVerifierInputs.lookup(nf),
input: action.logicVerifierInputs[action.logicVerifierInputs.lookup(nf)],
logicRef: complianceVerifierInput.instance.consumed.logicRef,
actionTreeRoot: actionTreeRoot,
consumed: true
Expand All @@ -144,7 +145,7 @@ contract ProtocolAdapter is
// Check the created resource.
// slither-disable-next-line reentrancy-benign
_processResourceLogicContext({
input: action.logicVerifierInputs.lookup(cm),
input: action.logicVerifierInputs[action.logicVerifierInputs.lookup(cm)],
logicRef: complianceVerifierInput.instance.created.logicRef,
actionTreeRoot: actionTreeRoot,
consumed: false
Expand Down Expand Up @@ -366,16 +367,6 @@ contract ProtocolAdapter is
pure
returns (bytes32 root)
{
bytes32[] memory actionTreeTags = new bytes32[](complianceUnitCount * 2);

// The order in which the tags are added to the tree is provided by the compliance units.
for (uint256 j = 0; j < complianceUnitCount; ++j) {
Compliance.VerifierInput calldata complianceVerifierInput = action.complianceVerifierInputs[j];

actionTreeTags[2 * j] = complianceVerifierInput.instance.consumed.nullifier;
actionTreeTags[(2 * j) + 1] = complianceVerifierInput.instance.created.commitment;
}

root = actionTreeTags.computeRoot();
root = action.complianceVerifierInputs.computeActionTreeTags(complianceUnitCount).computeRoot();
}
}
19 changes: 19 additions & 0 deletions contracts/src/proving/Compliance.sol
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,23 @@ library Compliance {
/// @notice The compliance verifying key.
/// @dev The key is fixed as long as the compliance circuit binary is not changed.
bytes32 internal constant _VERIFYING_KEY = 0x706468196fd92568220f5271e843c608126f7a8f204205d42ceef1f2c69f91df;

/// @notice Computes the action tree root of an action constituted by all its nullifiers and commitments.
/// @param complianceVerifierInputs Compliance verifier inputs.
/// @param complianceUnitCount The number of compliance units in the action.
/// @return actionTreeTags The action tree tags corresponding to the compliance verifier inputs.
function computeActionTreeTags(
Compliance.VerifierInput[] calldata complianceVerifierInputs,
uint256 complianceUnitCount
) internal pure returns (bytes32[] memory actionTreeTags) {
actionTreeTags = new bytes32[](complianceUnitCount * 2);

// The order in which the tags are added to the tree is provided by the compliance units.
for (uint256 j = 0; j < complianceUnitCount; ++j) {
Compliance.VerifierInput calldata complianceVerifierInput = complianceVerifierInputs[j];

actionTreeTags[2 * j] = complianceVerifierInput.instance.consumed.nullifier;
actionTreeTags[(2 * j) + 1] = complianceVerifierInput.instance.created.commitment;
}
}
}
10 changes: 3 additions & 7 deletions contracts/src/proving/Logic.sol
Original file line number Diff line number Diff line change
Expand Up @@ -52,16 +52,12 @@ library Logic {
/// @notice Looks up a `VerifierInput` element from a list by its tag.
/// @param list The list of verifier inputs.
/// @param tag The tag to look up.
/// @return foundElement The found `VerifierInput` element.
function lookup(VerifierInput[] calldata list, bytes32 tag)
internal
pure
returns (VerifierInput calldata foundElement)
{
/// @return foundElementIdx The index of the found `VerifierInput` element.
function lookup(VerifierInput[] calldata list, bytes32 tag) internal pure returns (uint256 foundElementIdx) {
uint256 len = list.length;
for (uint256 i = 0; i < len; ++i) {
if (list[i].tag == tag) {
return foundElement = list[i];
return foundElementIdx = i;
}
}
revert TagNotFound(tag);
Expand Down
Loading
Loading