Skip to content

Commit f5096be

Browse files
committed
refactor: rename struct
1 parent 0573ec6 commit f5096be

File tree

6 files changed

+38
-35
lines changed

6 files changed

+38
-35
lines changed

contracts/src/ProtocolAdapter.sol

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ contract ProtocolAdapter is
3535
CommitmentTree,
3636
NullifierSet
3737
{
38-
using Delta for Delta.CurvePoint;
38+
using Delta for Delta.Point;
3939
using MerkleTree for bytes32[];
4040
using Logic for Logic.VerifierInput[];
4141
using Logic for Logic.VerifierInput;
@@ -61,7 +61,7 @@ contract ProtocolAdapter is
6161
bytes32[] tags;
6262
bytes32[] logicRefs;
6363
bytes32 latestCommitmentTreeRoot;
64-
Delta.CurvePoint transactionDelta;
64+
Delta.Point transactionDelta;
6565
uint256 tagCounter;
6666
/* Proof aggregation-related variables */
6767
bool isProofAggregated;
@@ -146,7 +146,7 @@ contract ProtocolAdapter is
146146
// Add the unit delta to the transaction delta.
147147
vars.transactionDelta = vars.transactionDelta
148148
.add(
149-
Delta.CurvePoint({
149+
Delta.Point({
150150
x: uint256(complianceVerifierInput.instance.unitDeltaX),
151151
y: uint256(complianceVerifierInput.instance.unitDeltaY)
152152
})

contracts/src/libs/proving/Delta.sol

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@ import {EfficientHashLib} from "@solady/utils/EfficientHashLib.sol";
1010
/// @notice A library containing methods of the delta proving system.
1111
/// @custom:security-contact [email protected]
1212
library Delta {
13-
using Delta for CurvePoint;
13+
using Delta for Point;
1414

1515
/// @notice An elliptic curve point representing a delta value.
1616
/// @param x The x component of the point.
1717
/// @param y The y component of the point.
18-
struct CurvePoint {
18+
struct Point {
1919
uint256 x;
2020
uint256 y;
2121
}
@@ -39,19 +39,19 @@ library Delta {
3939
error DeltaMismatch(address expected, address actual);
4040

4141
/// @notice Thrown when a provided point is not on the curve.
42-
error PointNotOnCurve(CurvePoint point);
42+
error PointNotOnCurve(Point point);
4343

4444
/// @notice Returns the elliptic curve point representing the zero delta.
4545
/// @return zeroDelta The zero delta.
46-
function zero() internal pure returns (CurvePoint memory zeroDelta) {
47-
zeroDelta = CurvePoint({x: 0, y: 0});
46+
function zero() internal pure returns (Point memory zeroDelta) {
47+
zeroDelta = Point({x: 0, y: 0});
4848
}
4949

5050
/// @notice Adds two elliptic curve points and returns the resulting value.
5151
/// @param p1 The first curve point.
5252
/// @param p2 The second curve point.
5353
/// @return sum The resulting curve point.
54-
function add(CurvePoint memory p1, CurvePoint memory p2) internal pure returns (CurvePoint memory sum) {
54+
function add(Point memory p1, Point memory p2) internal pure returns (Point memory sum) {
5555
if (!EllipticCurve.isOnCurve({_x: p2.x, _y: p2.y, _aa: _AA, _bb: _BB, _pp: _PP})) {
5656
revert PointNotOnCurve(p2);
5757
}
@@ -62,7 +62,7 @@ library Delta {
6262
/// @notice Converts an elliptic curve point to an Ethereum account address.
6363
/// @param delta The elliptic curve point.
6464
/// @return account The associated account.
65-
function toAccount(CurvePoint memory delta) internal pure returns (address account) {
65+
function toAccount(Point memory delta) internal pure returns (address account) {
6666
// Hash the public key with Keccak-256.
6767
bytes32 hashedKey = EfficientHashLib.hash(delta.x, delta.y);
6868

@@ -82,7 +82,7 @@ library Delta {
8282
/// @param proof The delta proof.
8383
/// @param instance The transaction delta.
8484
/// @param verifyingKey The Keccak-256 hash of all nullifiers and commitments as ordered in the compliance units.
85-
function verify(bytes memory proof, CurvePoint memory instance, bytes32 verifyingKey) internal pure {
85+
function verify(bytes memory proof, Point memory instance, bytes32 verifyingKey) internal pure {
8686
// Verify the delta proof using the ECDSA.recover API to obtain the address
8787
address recovered = ECDSA.recover({hash: verifyingKey, signature: proof});
8888

contracts/test/libs/DeltaGen.sol

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ library DeltaGen {
4949
/// @return instance The delta instance corresponding to the parameters
5050
function generateInstance(VmSafe vm, InstanceInputs memory deltaInputs)
5151
internal
52-
returns (Delta.CurvePoint memory instance)
52+
returns (Delta.Point memory instance)
5353
{
5454
deltaInputs.valueCommitmentRandomness = deltaInputs.valueCommitmentRandomness.modOrder();
5555
if (deltaInputs.valueCommitmentRandomness == 0) {
@@ -69,7 +69,7 @@ library DeltaGen {
6969
VmSafe.Wallet memory valueWallet = vm.createWallet(preDelta);
7070

7171
// Extract the transaction delta from the wallet
72-
instance = Delta.CurvePoint({x: valueWallet.publicKeyX, y: valueWallet.publicKeyY});
72+
instance = Delta.Point({x: valueWallet.publicKeyX, y: valueWallet.publicKeyY});
7373
}
7474

7575
/// @notice Generates a transaction delta proof by signing verifyingKey with

contracts/test/libs/EllipticCurve.t.sol

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,7 @@ contract EllipticCurvePropertiesTest is Test {
107107
EllipticCurve.ecAdd({_x1: x, _y1: y, _x2: invX, _y2: invY, _aa: Delta._AA, _pp: Delta._PP});
108108

109109
assertTrue(
110-
_isPointAtInfinity(Delta.CurvePoint(resultX, resultY)),
111-
"GROUP PROPERTY: P + (-P) must equal point at infinity"
110+
_isPointAtInfinity(Delta.Point(resultX, resultY)), "GROUP PROPERTY: P + (-P) must equal point at infinity"
112111
);
113112
}
114113

@@ -168,7 +167,7 @@ contract EllipticCurvePropertiesTest is Test {
168167
EllipticCurve.ecAdd({_x1: x1, _y1: y1, _x2: x2, _y2: y2, _aa: Delta._AA, _pp: Delta._PP});
169168

170169
// Result must be on curve or at infinity
171-
bool atInfinity = _isPointAtInfinity(Delta.CurvePoint(resultX, resultY));
170+
bool atInfinity = _isPointAtInfinity(Delta.Point(resultX, resultY));
172171
bool onCurve =
173172
EllipticCurve.isOnCurve({_x: resultX, _y: resultY, _aa: Delta._AA, _bb: Delta._BB, _pp: Delta._PP});
174173

@@ -188,7 +187,7 @@ contract EllipticCurvePropertiesTest is Test {
188187

189188
// P + (-P) should equal point at infinity
190189
assertTrue(
191-
_isPointAtInfinity(Delta.CurvePoint(rx, ry)),
190+
_isPointAtInfinity(Delta.Point(rx, ry)),
192191
"With REDUCED coordinates: (3,5) + (3,2) correctly gives point at infinity"
193192
);
194193
}
@@ -225,7 +224,7 @@ contract EllipticCurvePropertiesTest is Test {
225224
(uint256 rx, uint256 ry) =
226225
EllipticCurve.ecAdd({_x1: Delta._GX, _y1: Delta._GY, _x2: invX, _y2: invY, _aa: Delta._AA, _pp: Delta._PP});
227226

228-
assertTrue(_isPointAtInfinity(Delta.CurvePoint(rx, ry)), "G + (-G) should be point at infinity");
227+
assertTrue(_isPointAtInfinity(Delta.Point(rx, ry)), "G + (-G) should be point at infinity");
229228
}
230229

231230
/// @notice Concrete: (G + 2G) + 3G = G + (2G + 3G) = 6G
@@ -264,7 +263,7 @@ contract EllipticCurvePropertiesTest is Test {
264263
/// @notice Returns whether a point is at infinity or not..
265264
/// @param p The point to check.
266265
/// @return isAtInfinity Whether the point is at infinity or not.
267-
function _isPointAtInfinity(Delta.CurvePoint memory p) internal pure returns (bool isAtInfinity) {
266+
function _isPointAtInfinity(Delta.Point memory p) internal pure returns (bool isAtInfinity) {
268267
isAtInfinity = p.x == 0 && p.y == 0;
269268
}
270269
}

contracts/test/libs/TxGen.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ library TxGen {
5050
bytes32 cm = commitment(created);
5151

5252
// Construct the delta for consumption based on kind and quantity
53-
Delta.CurvePoint memory unitDelta = DeltaGen.generateInstance(
53+
Delta.Point memory unitDelta = DeltaGen.generateInstance(
5454
vm,
5555
DeltaGen.InstanceInputs({
5656
kind: kind(consumed), quantity: consumed.quantity, consumed: true, valueCommitmentRandomness: 1

contracts/test/proofs/DeltaProof.t.sol

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,14 @@ library DeltaFuzzing {
2020
}
2121

2222
/// @dev This function exposes `Delta.verify` for the fuzzer.
23-
function verify(bytes memory proof, Delta.CurvePoint memory instance, bytes32 verifyingKey) public pure {
23+
function verify(bytes memory proof, Delta.Point memory instance, bytes32 verifyingKey) public pure {
2424
Delta.verify({proof: proof, instance: instance, verifyingKey: verifyingKey});
2525
}
2626
}
2727

2828
contract DeltaProofTest is Test {
2929
using SignMagnitude for SignMagnitude.Number;
30-
using Delta for Delta.CurvePoint;
30+
using Delta for Delta.Point;
3131
using DeltaGen for DeltaGen.InstanceInputs[];
3232
using DeltaGen for DeltaGen.InstanceInputs;
3333
using DeltaGen for uint256;
@@ -52,7 +52,7 @@ contract DeltaProofTest is Test {
5252
DeltaGen.ProofInputs({valueCommitmentRandomness: valueCommitmentRandomness, verifyingKey: verifyingKey});
5353

5454
// Generate a delta instance from the above inputs
55-
Delta.CurvePoint memory instance = DeltaGen.generateInstance(vm, deltaInstanceInputs);
55+
Delta.Point memory instance = DeltaGen.generateInstance(vm, deltaInstanceInputs);
5656

5757
// Generate a delta proof from the above inputs
5858
bytes memory proof = DeltaGen.generateProof(vm, deltaProofInputs);
@@ -110,12 +110,12 @@ contract DeltaProofTest is Test {
110110
vm.assume(summedDeltaInputs.computePreDelta() != 0);
111111

112112
// Generate a delta proof and instance from the above tags and preimage
113-
Delta.CurvePoint memory instance1 = DeltaGen.generateInstance(vm, deltaInputs1);
114-
Delta.CurvePoint memory instance2 = DeltaGen.generateInstance(vm, deltaInputs2);
115-
Delta.CurvePoint memory expectedDelta = DeltaGen.generateInstance(vm, summedDeltaInputs);
113+
Delta.Point memory instance1 = DeltaGen.generateInstance(vm, deltaInputs1);
114+
Delta.Point memory instance2 = DeltaGen.generateInstance(vm, deltaInputs2);
115+
Delta.Point memory expectedDelta = DeltaGen.generateInstance(vm, summedDeltaInputs);
116116

117117
// Verify that the deltas add correctly
118-
Delta.CurvePoint memory computedDelta = Delta.add(instance1, instance2);
118+
Delta.Point memory computedDelta = Delta.add(instance1, instance2);
119119

120120
assertEq(computedDelta.x, expectedDelta.x);
121121
assertEq(computedDelta.y, expectedDelta.y);
@@ -140,7 +140,7 @@ contract DeltaProofTest is Test {
140140
});
141141

142142
// Generate a delta proof and instance from the above tags and preimage
143-
Delta.CurvePoint memory instance = DeltaGen.generateInstance(vm, deltaInstanceInputs);
143+
Delta.Point memory instance = DeltaGen.generateInstance(vm, deltaInstanceInputs);
144144
bytes memory proof = DeltaGen.generateProof(vm, deltaProofInputs);
145145
vm.expectPartialRevert(Delta.DeltaMismatch.selector);
146146
DeltaFuzzing.verify({proof: proof, instance: instance, verifyingKey: deltaProofInputs.verifyingKey});
@@ -165,7 +165,7 @@ contract DeltaProofTest is Test {
165165
DeltaGen.ProofInputs({valueCommitmentRandomness: valueCommitmentRandomness1, verifyingKey: verifyingKey})
166166
);
167167

168-
Delta.CurvePoint memory instanceRcv2;
168+
Delta.Point memory instanceRcv2;
169169
{
170170
DeltaGen.InstanceInputs memory deltaInputs2 = DeltaGen.InstanceInputs({
171171
kind: kind, quantity: 0, consumed: consumed, valueCommitmentRandomness: valueCommitmentRandomness2
@@ -195,7 +195,7 @@ contract DeltaProofTest is Test {
195195
DeltaGen.ProofInputs({valueCommitmentRandomness: valueCommitmentRandomness, verifyingKey: verifyingKey1})
196196
);
197197

198-
Delta.CurvePoint memory instance;
198+
Delta.Point memory instance;
199199
{
200200
DeltaGen.InstanceInputs memory deltaInputs2 = DeltaGen.InstanceInputs({
201201
kind: kind, quantity: 0, consumed: consumed, valueCommitmentRandomness: valueCommitmentRandomness
@@ -218,7 +218,7 @@ contract DeltaProofTest is Test {
218218
kind = bound(kind, 1, DeltaGen.SECP256K1_ORDER - 1);
219219
DeltaGen.InstanceInputs[] memory deltaInputs = _getBoundedDeltaInstances(kind, fuzzerInputs);
220220

221-
Delta.CurvePoint memory deltaAcc = Delta.zero();
221+
Delta.Point memory deltaAcc = Delta.zero();
222222

223223
// Make sure that the delta quantities balance out
224224
(
@@ -248,7 +248,7 @@ contract DeltaProofTest is Test {
248248
vm.assume(wrappedDeltaInputs[i].valueCommitmentRandomness != 0);
249249
vm.assume(wrappedDeltaInputs[i].computePreDelta() != 0);
250250

251-
Delta.CurvePoint memory instance = DeltaGen.generateInstance(vm, wrappedDeltaInputs[i]);
251+
Delta.Point memory instance = DeltaGen.generateInstance(vm, wrappedDeltaInputs[i]);
252252
deltaAcc = deltaAcc.add(instance);
253253
}
254254

@@ -270,7 +270,7 @@ contract DeltaProofTest is Test {
270270
kind = bound(kind, 1, DeltaGen.SECP256K1_ORDER - 1);
271271
DeltaGen.InstanceInputs[] memory deltaInputs = _getBoundedDeltaInstances(kind, fuzzerInputs);
272272

273-
Delta.CurvePoint memory deltaAcc = Delta.zero();
273+
Delta.Point memory deltaAcc = Delta.zero();
274274

275275
// Accumulate the total quantity and randomness commitment
276276
(
@@ -289,7 +289,7 @@ contract DeltaProofTest is Test {
289289
vm.assume(wrappedDeltaInputs[i].valueCommitmentRandomness != 0);
290290
vm.assume(wrappedDeltaInputs[i].computePreDelta() != 0);
291291

292-
Delta.CurvePoint memory instance = DeltaGen.generateInstance(vm, wrappedDeltaInputs[i]);
292+
Delta.Point memory instance = DeltaGen.generateInstance(vm, wrappedDeltaInputs[i]);
293293
deltaAcc = deltaAcc.add(instance);
294294
}
295295
// Compute the proof for the balanced transaction
@@ -307,7 +307,7 @@ contract DeltaProofTest is Test {
307307

308308
DeltaFuzzing.verify({
309309
proof: txn.deltaProof,
310-
instance: Delta.CurvePoint({
310+
instance: Delta.Point({
311311
x: uint256(txn.actions[0].complianceVerifierInputs[0].instance.unitDeltaX),
312312
y: uint256(txn.actions[0].complianceVerifierInputs[0].instance.unitDeltaY)
313313
}),
@@ -338,4 +338,8 @@ contract DeltaProofTest is Test {
338338
});
339339
}
340340
}
341+
342+
function _mul(Delta.Point memory p, uint256 k) internal pure returns (Delta.Point memory product) {
343+
(product.x, product.y) = EllipticCurve.ecMul({_k: k, _x: p.x, _y: p.y, _aa: Delta._AA, _pp: Delta._PP});
344+
}
341345
}

0 commit comments

Comments
 (0)