Skip to content

Commit d889b1e

Browse files
committed
Remove Extra Computable Components
1 parent 0bd2a08 commit d889b1e

File tree

3 files changed

+14
-37
lines changed

3 files changed

+14
-37
lines changed

contracts/src/ProtocolAdapter.sol

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -356,23 +356,23 @@ contract ProtocolAdapter is IProtocolAdapter, ReentrancyGuardTransient, Commitme
356356
bytes32 fetchedKind = IForwarder(call.untrustedForwarder).calldataCarrierResourceKind();
357357

358358
// Check kind correspondence
359-
if (resource.kind_() != fetchedKind) {
360-
revert CalldataCarrierKindMismatch({expected: fetchedKind, actual: resource.kind_()});
359+
if (resource.kind() != fetchedKind) {
360+
revert CalldataCarrierKindMismatch({expected: fetchedKind, actual: resource.kind()});
361361
}
362362

363363
// Check tag correspondence
364364
if (!consumed) {
365365
// If created, just commit the plaintext and check agains the tag
366-
if (resource.commitment_() != input.tag) {
367-
revert CalldataCarrierTagMismatch({actual: input.tag, expected: resource.commitment_()});
366+
if (resource.commitment() != input.tag) {
367+
revert CalldataCarrierTagMismatch({actual: input.tag, expected: resource.commitment()});
368368
}
369369
} else if (
370370
// If consumed, we expect the nullifier key to be present in the resource payload as well
371-
resource.nullifier_(bytes32(input.appData.resourcePayload[1].blob)) != input.tag
371+
resource.nullifier(bytes32(input.appData.resourcePayload[1].blob)) != input.tag
372372
) {
373373
revert CalldataCarrierTagMismatch({
374374
actual: input.tag,
375-
expected: resource.nullifier_(abi.decode(input.appData.resourcePayload[1].blob, (bytes32)))
375+
expected: resource.nullifier(abi.decode(input.appData.resourcePayload[1].blob, (bytes32)))
376376
});
377377
}
378378
}

contracts/src/libs/ComputableComponents.sol

Lines changed: 3 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -11,46 +11,23 @@ library ComputableComponents {
1111
/// @notice Computes the resource commitment.
1212
/// @param resource The resource object.
1313
/// @return cm The computed commitment.
14-
function commitment(Resource calldata resource) internal pure returns (bytes32 cm) {
14+
function commitment(Resource memory resource) internal pure returns (bytes32 cm) {
1515
cm = sha256(abi.encode(resource));
1616
}
1717

18-
/// @notice Computes the resource commitment.
19-
/// @param resource The resource object.
20-
/// @return cm The computed commitment.
21-
function commitment_(Resource memory resource) internal pure returns (bytes32 cm) {
22-
cm = sha256(abi.encode(resource));
23-
}
24-
25-
/// @notice Computes the resource nullifier given a nullifier key.
26-
/// @param resource The resource object.
27-
/// @param nullifierKey The nullifier key.
28-
/// @return nf The computed nullifier.
29-
/// @dev This methods does not check that the nullifier key commitment matches the nullifier key.
30-
function nullifier(Resource calldata resource, bytes32 nullifierKey) internal pure returns (bytes32 nf) {
31-
nf = sha256(abi.encode(resource, nullifierKey));
32-
}
33-
3418
/// @notice Computes the resource nullifier given a nullifier key.
3519
/// @param resource The resource object.
3620
/// @param nullifierKey The nullifier key.
3721
/// @return nf The computed nullifier.
3822
/// @dev This methods does not check that the nullifier key commitment matches the nullifier key.
39-
function nullifier_(Resource memory resource, bytes32 nullifierKey) internal pure returns (bytes32 nf) {
23+
function nullifier(Resource memory resource, bytes32 nullifierKey) internal pure returns (bytes32 nf) {
4024
nf = sha256(abi.encode(resource, nullifierKey));
4125
}
4226

4327
/// @notice Computes the resource kind.
4428
/// @param resource The resource object.
4529
/// @return k The computed kind.
46-
function kind(Resource calldata resource) internal pure returns (bytes32 k) {
47-
k = sha256(abi.encode(resource.logicRef, resource.labelRef));
48-
}
49-
50-
/// @notice Computes the resource kind.
51-
/// @param resource The resource object.
52-
/// @return k The computed kind.
53-
function kind_(Resource memory resource) internal pure returns (bytes32 k) {
30+
function kind(Resource memory resource) internal pure returns (bytes32 k) {
5431
k = sha256(abi.encode(resource.logicRef, resource.labelRef));
5532
}
5633

contracts/test/examples/TxGen.sol

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ library TxGen {
4343
Resource memory consumed,
4444
Resource memory created
4545
) internal view returns (Compliance.VerifierInput memory unit) {
46-
bytes32 nf = consumed.nullifier_({nullifierKey: 0});
47-
bytes32 cm = created.commitment_();
46+
bytes32 nf = consumed.nullifier({nullifierKey: 0});
47+
bytes32 cm = created.commitment();
4848

4949
bytes32 unitDeltaX;
5050
bytes32 unitDeltaY;
@@ -81,7 +81,7 @@ library TxGen {
8181
Logic.AppData memory appData
8282
) internal view returns (Logic.VerifierInput memory input) {
8383
input = Logic.VerifierInput({
84-
tag: isConsumed ? resource.nullifier_({nullifierKey: 0}) : resource.commitment_(),
84+
tag: isConsumed ? resource.nullifier({nullifierKey: 0}) : resource.commitment(),
8585
verifyingKey: resource.logicRef,
8686
appData: appData,
8787
proof: abi.encodePacked(uint32(0))
@@ -111,8 +111,8 @@ library TxGen {
111111
for (uint256 i = 0; i < nCUs; ++i) {
112112
uint256 index = (i * 2);
113113

114-
actionTreeTags[index] = consumed[i].resource.nullifier_({nullifierKey: 0});
115-
actionTreeTags[index + 1] = created[i].resource.commitment_();
114+
actionTreeTags[index] = consumed[i].resource.nullifier({nullifierKey: 0});
115+
actionTreeTags[index + 1] = created[i].resource.commitment();
116116
}
117117

118118
bytes32 actionTreeRoot = MerkleTree.computeRoot(actionTreeTags, 4);

0 commit comments

Comments
 (0)