Skip to content

Commit 2860844

Browse files
authored
Merge pull request #105 from hyperledger-labs/withdraw-event
Add UTXOWithdraw event
2 parents 3557311 + e0f6013 commit 2860844

16 files changed

+73
-42
lines changed

solidity/contracts/lib/interfaces/izeto_base.sol

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,11 @@ pragma solidity ^0.8.20;
1717

1818
interface IZetoBase {
1919
event UTXOMint(uint256[] outputs, address indexed submitter, bytes data);
20+
event UTXOWithdraw(
21+
uint256 amount,
22+
uint256[] inputs,
23+
uint256 output,
24+
address indexed submitter,
25+
bytes data
26+
);
2027
}

solidity/contracts/lib/verifier_check_hashes_value.sol

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -43,14 +43,17 @@ contract Groth16Verifier_CheckHashesValue {
4343
uint256 constant deltay2 = 8495653923123431417604973247489272438418190587263600148770280649306958101930;
4444

4545

46-
uint256 constant IC0x = 7451946452627654831087368244416850811848640051585835431774006564787696394579;
47-
uint256 constant IC0y = 3335938186741695161920937664249081252546904250712465973121885140080729804559;
46+
uint256 constant IC0x = 17792762022125287046321768098607171320071618631211367966788587488825455404458;
47+
uint256 constant IC0y = 11155528019403985287117957011181683282276980330791900414761420530701336492839;
4848

49-
uint256 constant IC1x = 4825167184845404163337490360685409593368334234867416547655377178016060612776;
50-
uint256 constant IC1y = 20216917433859335199329194148245717058149862581677751710529776924054717858789;
49+
uint256 constant IC1x = 6717605603646218844646921196814073522173739325926307699116887265970061883098;
50+
uint256 constant IC1y = 516153472147520123255754218210841627924243470206670179828454953236590121912;
5151

52-
uint256 constant IC2x = 15958914812085923571729409913935907268381565403173614269925036163982984629903;
53-
uint256 constant IC2y = 12537821265017874170836131082487633026846634600904134063136842002739226714069;
52+
uint256 constant IC2x = 8087731838810758210112265887449747110390409349987938026778639089761261395232;
53+
uint256 constant IC2y = 19857276812072296411781253738593366602790857251698964067504889225833057563826;
54+
55+
uint256 constant IC3x = 473105502461913999202734899658281137764286492931790885921074401072316990093;
56+
uint256 constant IC3y = 19795449967604900309902005580999588375004713323386672270649013487860620808493;
5457

5558

5659
// Memory data
@@ -59,7 +62,7 @@ contract Groth16Verifier_CheckHashesValue {
5962

6063
uint16 constant pLastMem = 896;
6164

62-
function verifyProof(uint[2] calldata _pA, uint[2][2] calldata _pB, uint[2] calldata _pC, uint[2] calldata _pubSignals) public view returns (bool) {
65+
function verifyProof(uint[2] calldata _pA, uint[2][2] calldata _pB, uint[2] calldata _pC, uint[3] calldata _pubSignals) public view returns (bool) {
6366
assembly {
6467
function checkField(v) {
6568
if iszero(lt(v, r)) {
@@ -107,6 +110,8 @@ contract Groth16Verifier_CheckHashesValue {
107110

108111
g1_mulAccC(_pVk, IC2x, IC2y, calldataload(add(pubSignals, 32)))
109112

113+
g1_mulAccC(_pVk, IC3x, IC3y, calldataload(add(pubSignals, 64)))
114+
110115

111116
// -A
112117
mstore(_pPairing, calldataload(pA))
@@ -164,6 +169,10 @@ contract Groth16Verifier_CheckHashesValue {
164169

165170
checkField(calldataload(add(_pubSignals, 32)))
166171

172+
checkField(calldataload(add(_pubSignals, 64)))
173+
174+
checkField(calldataload(add(_pubSignals, 96)))
175+
167176

168177
// Validate all evaluations
169178
let isValid := checkPairing(_pA, _pB, _pC, _pubSignals, pMem)

solidity/contracts/zeto_anon.sol

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -156,14 +156,7 @@ contract Zeto_Anon is IZeto, ZetoBase, ZetoFungibleWithdraw, UUPSUpgradeable {
156156
}
157157

158158
processInputsAndOutputs(inputs, outputs);
159-
160-
uint256[] memory inputArray = new uint256[](inputs.length);
161-
uint256[] memory outputArray = new uint256[](outputs.length);
162-
for (uint256 i = 0; i < inputs.length; ++i) {
163-
inputArray[i] = inputs[i];
164-
outputArray[i] = outputs[i];
165-
}
166-
emit UTXOTransfer(inputArray, outputArray, msg.sender, data);
159+
emit UTXOTransfer(inputs, outputs, msg.sender, data);
167160

168161
return true;
169162
}
@@ -182,7 +175,8 @@ contract Zeto_Anon is IZeto, ZetoBase, ZetoFungibleWithdraw, UUPSUpgradeable {
182175
uint256 amount,
183176
uint256[] memory inputs,
184177
uint256 output,
185-
Commonlib.Proof calldata proof
178+
Commonlib.Proof calldata proof,
179+
bytes calldata data
186180
) public {
187181
// Check and pad inputs and outputs based on the max size
188182
uint256[] memory outputs = new uint256[](inputs.length);
@@ -191,6 +185,7 @@ contract Zeto_Anon is IZeto, ZetoBase, ZetoFungibleWithdraw, UUPSUpgradeable {
191185
validateTransactionProposal(inputs, outputs, proof);
192186
_withdraw(amount, inputs, output, proof);
193187
processInputsAndOutputs(inputs, outputs);
188+
emit UTXOWithdraw(amount, inputs, output, msg.sender, data);
194189
}
195190

196191
function mint(

solidity/contracts/zeto_anon_enc.sol

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,8 @@ contract Zeto_AnonEnc is
220220
uint256 amount,
221221
uint256[] memory inputs,
222222
uint256 output,
223-
Commonlib.Proof calldata proof
223+
Commonlib.Proof calldata proof,
224+
bytes calldata data
224225
) public {
225226
uint256[] memory outputs = new uint256[](inputs.length);
226227
outputs[0] = output;
@@ -229,6 +230,7 @@ contract Zeto_AnonEnc is
229230
validateTransactionProposal(inputs, outputs, proof);
230231
_withdraw(amount, inputs, output, proof);
231232
processInputsAndOutputs(inputs, outputs);
233+
emit UTXOWithdraw(amount, inputs, output, msg.sender, data);
232234
}
233235

234236
function mint(

solidity/contracts/zeto_anon_enc_nullifier.sol

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,8 @@ contract Zeto_AnonEncNullifier is
236236
uint256[] memory nullifiers,
237237
uint256 output,
238238
uint256 root,
239-
Commonlib.Proof calldata proof
239+
Commonlib.Proof calldata proof,
240+
bytes calldata data
240241
) public {
241242
uint256[] memory outputs = new uint256[](nullifiers.length);
242243
outputs[0] = output;
@@ -249,6 +250,7 @@ contract Zeto_AnonEncNullifier is
249250
validateTransactionProposal(nullifiers, outputs, root);
250251
_withdrawWithNullifiers(amount, nullifiers, output, root, proof);
251252
processInputsAndOutputs(nullifiers, outputs);
253+
emit UTXOWithdraw(amount, nullifiers, output, msg.sender, data);
252254
}
253255

254256
function mint(

solidity/contracts/zeto_anon_enc_nullifier_kyc.sol

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,8 @@ contract Zeto_AnonEncNullifierKyc is
251251
uint256[] memory nullifiers,
252252
uint256 output,
253253
uint256 root,
254-
Commonlib.Proof calldata proof
254+
Commonlib.Proof calldata proof,
255+
bytes calldata data
255256
) public {
256257
uint256[] memory outputs = new uint256[](nullifiers.length);
257258
outputs[0] = output;
@@ -264,6 +265,7 @@ contract Zeto_AnonEncNullifierKyc is
264265
validateTransactionProposal(nullifiers, outputs, root);
265266
_withdrawWithNullifiers(amount, nullifiers, output, root, proof);
266267
processInputsAndOutputs(nullifiers, outputs);
268+
emit UTXOWithdraw(amount, nullifiers, output, msg.sender, data);
267269
}
268270

269271
function mint(

solidity/contracts/zeto_anon_enc_nullifier_non_repudiation.sol

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,8 @@ contract Zeto_AnonEncNullifierNonRepudiation is
287287
uint256[] memory nullifiers,
288288
uint256 output,
289289
uint256 root,
290-
Commonlib.Proof calldata proof
290+
Commonlib.Proof calldata proof,
291+
bytes calldata data
291292
) public {
292293
uint256[] memory outputs = new uint256[](nullifiers.length);
293294
outputs[0] = output;
@@ -300,6 +301,7 @@ contract Zeto_AnonEncNullifierNonRepudiation is
300301
validateTransactionProposal(nullifiers, outputs, root);
301302
_withdrawWithNullifiers(amount, nullifiers, output, root, proof);
302303
processInputsAndOutputs(nullifiers, outputs);
304+
emit UTXOWithdraw(amount, nullifiers, output, msg.sender, data);
303305
}
304306

305307
function mint(

solidity/contracts/zeto_anon_nullifier.sol

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,8 @@ contract Zeto_AnonNullifier is
205205
uint256[] memory nullifiers,
206206
uint256 output,
207207
uint256 root,
208-
Commonlib.Proof calldata proof
208+
Commonlib.Proof calldata proof,
209+
bytes calldata data
209210
) public {
210211
uint256[] memory outputs = new uint256[](nullifiers.length);
211212
outputs[0] = output;
@@ -218,6 +219,7 @@ contract Zeto_AnonNullifier is
218219
validateTransactionProposal(nullifiers, outputs, root);
219220
_withdrawWithNullifiers(amount, nullifiers, output, root, proof);
220221
processInputsAndOutputs(nullifiers, outputs);
222+
emit UTXOWithdraw(amount, nullifiers, output, msg.sender, data);
221223
}
222224

223225
function mint(

solidity/contracts/zeto_anon_nullifier_kyc.sol

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,8 @@ contract Zeto_AnonNullifierKyc is
215215
uint256[] memory nullifiers,
216216
uint256 output,
217217
uint256 root,
218-
Commonlib.Proof calldata proof
218+
Commonlib.Proof calldata proof,
219+
bytes calldata data
219220
) public {
220221
uint256[] memory outputs = new uint256[](nullifiers.length);
221222
outputs[0] = output;
@@ -228,6 +229,7 @@ contract Zeto_AnonNullifierKyc is
228229
validateTransactionProposal(nullifiers, outputs, root);
229230
_withdrawWithNullifiers(amount, nullifiers, output, root, proof);
230231
processInputsAndOutputs(nullifiers, outputs);
232+
emit UTXOWithdraw(amount, nullifiers, output, msg.sender, data);
231233
}
232234

233235
function mint(

solidity/test/zeto_anon.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ describe("Zeto based fungible token with anonymity without encryption or nullifi
151151
// Alice withdraws her UTXOs to ERC20 tokens
152152
const tx = await zeto
153153
.connect(Alice.signer)
154-
.withdraw(3, inputCommitments, outputCommitments[0], encodedProof);
154+
.withdraw(3, inputCommitments, outputCommitments[0], encodedProof, "0x");
155155
await tx.wait();
156156

157157
// Alice checks her ERC20 balance
@@ -262,7 +262,7 @@ describe("Zeto based fungible token with anonymity without encryption or nullifi
262262
// Alice withdraws her UTXOs to ERC20 tokens
263263
const tx = await zeto
264264
.connect(Alice.signer)
265-
.withdraw(80, inputCommitments, outputCommitments[0], encodedProof);
265+
.withdraw(80, inputCommitments, outputCommitments[0], encodedProof, "0x");
266266
await tx.wait();
267267

268268
// Alice checks her ERC20 balance
@@ -329,7 +329,7 @@ describe("Zeto based fungible token with anonymity without encryption or nullifi
329329
await expect(
330330
zeto
331331
.connect(Alice.signer)
332-
.withdraw(10, inputCommitments, outputCommitments[0], encodedProof),
332+
.withdraw(10, inputCommitments, outputCommitments[0], encodedProof, "0x"),
333333
).rejectedWith("UTXOAlreadySpent");
334334
});
335335

solidity/test/zeto_anon_enc.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ describe("Zeto based fungible token with anonymity and encryption", function ()
172172
// Alice withdraws her UTXOs to ERC20 tokens
173173
const tx = await zeto
174174
.connect(Alice.signer)
175-
.withdraw(3, inputCommitments, outputCommitments[0], encodedProof);
175+
.withdraw(3, inputCommitments, outputCommitments[0], encodedProof, "0x");
176176
await tx.wait();
177177

178178
// Alice checks her ERC20 balance
@@ -283,7 +283,7 @@ describe("Zeto based fungible token with anonymity and encryption", function ()
283283
// Alice withdraws her UTXOs to ERC20 tokens
284284
const tx = await zeto
285285
.connect(Alice.signer)
286-
.withdraw(80, inputCommitments, outputCommitments[0], encodedProof);
286+
.withdraw(80, inputCommitments, outputCommitments[0], encodedProof, "0x");
287287
await tx.wait();
288288

289289
// Alice checks her ERC20 balance
@@ -313,7 +313,7 @@ describe("Zeto based fungible token with anonymity and encryption", function ()
313313
await expect(
314314
zeto
315315
.connect(Alice.signer)
316-
.withdraw(10, inputCommitments, outputCommitments[0], encodedProof),
316+
.withdraw(10, inputCommitments, outputCommitments[0], encodedProof, "0x"),
317317
).rejectedWith("UTXOAlreadySpent");
318318
});
319319

solidity/test/zeto_anon_enc_nullifier.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,7 @@ describe("Zeto based fungible token with anonymity using nullifiers and encrypti
256256
withdrawCommitments[0],
257257
root.bigInt(),
258258
withdrawEncodedProof,
259+
"0x"
259260
);
260261
await tx.wait();
261262

@@ -457,6 +458,7 @@ describe("Zeto based fungible token with anonymity using nullifiers and encrypti
457458
outputCommitments[0],
458459
root.bigInt(),
459460
encodedProof,
461+
"0x"
460462
);
461463
await tx.wait();
462464

@@ -517,6 +519,7 @@ describe("Zeto based fungible token with anonymity using nullifiers and encrypti
517519
outputCommitments[0],
518520
root.bigInt(),
519521
encodedProof,
522+
"0x"
520523
),
521524
).rejectedWith("UTXOAlreadySpent");
522525
});
@@ -842,9 +845,7 @@ describe("Zeto based fungible token with anonymity using nullifiers and encrypti
842845
);
843846
const results: ContractTransactionReceipt | null = await tx.wait();
844847
console.log(
845-
`Time to execute transaction: ${Date.now() - startTx}ms. Gas used: ${
846-
results?.gasUsed
847-
}`,
848+
`Time to execute transaction: ${Date.now() - startTx}ms. Gas used: ${results?.gasUsed}`,
848849
);
849850
return results;
850851
}

solidity/test/zeto_anon_enc_nullifier_kyc.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,7 @@ describe("Zeto based fungible token with anonymity using nullifiers and encrypti
318318
withdrawCommitments[0],
319319
root.bigInt(),
320320
withdrawEncodedProof,
321+
"0x"
321322
);
322323
await tx.wait();
323324

@@ -565,6 +566,7 @@ describe("Zeto based fungible token with anonymity using nullifiers and encrypti
565566
outputCommitments[0],
566567
root.bigInt(),
567568
encodedProof,
569+
"0x"
568570
);
569571
await tx.wait();
570572

@@ -720,6 +722,7 @@ describe("Zeto based fungible token with anonymity using nullifiers and encrypti
720722
outputCommitments[0],
721723
root.bigInt(),
722724
encodedProof,
725+
"0x"
723726
);
724727
await tx.wait();
725728

@@ -787,6 +790,7 @@ describe("Zeto based fungible token with anonymity using nullifiers and encrypti
787790
outputCommitments[0],
788791
root.bigInt(),
789792
encodedProof,
793+
"0x"
790794
),
791795
).rejectedWith("UTXOAlreadySpent");
792796
});
@@ -1186,9 +1190,7 @@ describe("Zeto based fungible token with anonymity using nullifiers and encrypti
11861190
);
11871191
const results: ContractTransactionReceipt | null = await tx.wait();
11881192
console.log(
1189-
`Time to execute transaction: ${Date.now() - startTx}ms. Gas used: ${
1190-
results?.gasUsed
1191-
}`,
1193+
`Time to execute transaction: ${Date.now() - startTx}ms. Gas used: ${results?.gasUsed}`,
11921194
);
11931195
return results;
11941196
}

solidity/test/zeto_anon_enc_nullifier_non_repudiation.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,7 @@ describe("Zeto based fungible token with anonymity using nullifiers and encrypti
312312
withdrawCommitments[0],
313313
root.bigInt(),
314314
withdrawEncodedProof,
315+
"0x"
315316
);
316317
await tx.wait();
317318

@@ -569,6 +570,7 @@ describe("Zeto based fungible token with anonymity using nullifiers and encrypti
569570
outputCommitments[0],
570571
root.bigInt(),
571572
encodedProof,
573+
"0x"
572574
);
573575
await tx.wait();
574576

@@ -629,6 +631,7 @@ describe("Zeto based fungible token with anonymity using nullifiers and encrypti
629631
outputCommitments[0],
630632
root.bigInt(),
631633
encodedProof,
634+
"0x"
632635
),
633636
).rejectedWith("UTXOAlreadySpent");
634637
});
@@ -951,9 +954,7 @@ describe("Zeto based fungible token with anonymity using nullifiers and encrypti
951954
);
952955
const results: ContractTransactionReceipt | null = await tx.wait();
953956
console.log(
954-
`Time to execute transaction: ${Date.now() - startTx}ms. Gas used: ${
955-
results?.gasUsed
956-
}`,
957+
`Time to execute transaction: ${Date.now() - startTx}ms. Gas used: ${results?.gasUsed}`,
957958
);
958959
return results;
959960
}

0 commit comments

Comments
 (0)