@lfdecentralizedtrust/zeto-contracts 0.2.2 → 0.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +76 -162
- package/config/eip170.ts +30 -0
- package/contracts/factory.sol +30 -34
- package/contracts/factory_upgradeable.sol +11 -7
- package/contracts/lib/common/util.sol +40 -0
- package/contracts/lib/interfaces/ILockableCapability.sol +318 -0
- package/contracts/lib/interfaces/{izeto.sol → IZeto.sol} +13 -1
- package/contracts/lib/interfaces/{izeto_initializable.sol → IZetoInitializable.sol} +14 -12
- package/contracts/lib/interfaces/{izeto_kyc.sol → IZetoKyc.sol} +3 -3
- package/contracts/lib/interfaces/IZetoLockHooks.sol +42 -0
- package/contracts/lib/interfaces/IZetoLockableCapability.sol +237 -0
- package/contracts/lib/interfaces/IZetoStorage.sol +106 -0
- package/contracts/lib/interfaces/{izeto_lockable.sol → IZetoVerifier.sol} +8 -21
- package/contracts/lib/registry.sol +74 -26
- package/contracts/lib/storage/base.sol +210 -0
- package/contracts/lib/storage/nullifier.sol +166 -0
- package/contracts/lib/zeto_common.sol +277 -28
- package/contracts/lib/zeto_fungible.sol +443 -33
- package/contracts/lib/zeto_fungible_base.sol +69 -0
- package/contracts/lib/zeto_fungible_burn.sol +83 -53
- package/contracts/lib/zeto_fungible_burn_nullifier.sol +115 -72
- package/contracts/lib/zeto_fungible_nullifier.sol +167 -0
- package/contracts/lib/zeto_lockable.sol +219 -0
- package/contracts/lib/zeto_lockable_lib.sol +460 -0
- package/contracts/lib/zeto_lockable_storage.sol +43 -0
- package/contracts/lib/zeto_non_fungible.sol +228 -0
- package/contracts/lib/zeto_non_fungible_base.sol +61 -0
- package/contracts/lib/zeto_non_fungible_nullifier.sol +61 -0
- package/contracts/test/escrow1.sol +90 -34
- package/contracts/test/escrow2.sol +64 -29
- package/contracts/test/qurrency.sol +10 -2
- package/contracts/test/smt.sol +6 -1
- package/contracts/test/tendecimals.sol +14 -12
- package/contracts/verifiers/impl/anon.sol +189 -0
- package/contracts/verifiers/impl/anon_batch.sol +301 -0
- package/contracts/verifiers/impl/anon_enc.sol +266 -0
- package/contracts/verifiers/impl/anon_enc_batch.sol +602 -0
- package/contracts/verifiers/impl/anon_enc_nullifier.sol +287 -0
- package/contracts/verifiers/impl/anon_enc_nullifier_batch.sol +679 -0
- package/contracts/verifiers/impl/anon_enc_nullifier_kyc.sol +294 -0
- package/contracts/verifiers/impl/anon_enc_nullifier_kyc_batch.sol +686 -0
- package/contracts/verifiers/impl/anon_enc_nullifier_non_repudiation.sol +413 -0
- package/contracts/verifiers/impl/anon_enc_nullifier_non_repudiation_batch.sol +1141 -0
- package/contracts/verifiers/impl/anon_nullifier_kyc_transfer.sol +217 -0
- package/contracts/verifiers/impl/anon_nullifier_kyc_transferLocked.sol +196 -0
- package/contracts/verifiers/impl/anon_nullifier_kyc_transferLocked_batch.sol +308 -0
- package/contracts/verifiers/impl/anon_nullifier_kyc_transfer_batch.sol +385 -0
- package/contracts/verifiers/impl/anon_nullifier_qurrency_transfer.sol +497 -0
- package/contracts/verifiers/impl/anon_nullifier_qurrency_transfer_batch.sol +1001 -0
- package/contracts/verifiers/{verifier_anon_nullifier_transferLocked.sol → impl/anon_nullifier_transfer.sol} +12 -19
- package/contracts/verifiers/{verifier_anon_nullifier_transferLocked_batch.sol → impl/anon_nullifier_transfer_batch.sol} +44 -51
- package/contracts/verifiers/impl/burn.sol +182 -0
- package/contracts/verifiers/impl/burn_batch.sol +238 -0
- package/contracts/verifiers/impl/burn_nullifier.sol +203 -0
- package/contracts/verifiers/impl/burn_nullifier_batch.sol +315 -0
- package/contracts/verifiers/impl/deposit.sol +182 -0
- package/contracts/verifiers/impl/deposit_kyc.sol +189 -0
- package/contracts/verifiers/impl/nf_anon.sol +175 -0
- package/contracts/verifiers/{verifier_nf_anon_nullifier_transferLocked.sol → impl/nf_anon_nullifier_transfer.sol} +6 -13
- package/contracts/verifiers/impl/withdraw.sol +189 -0
- package/contracts/verifiers/impl/withdraw_batch.sol +245 -0
- package/contracts/verifiers/impl/withdraw_nullifier.sol +210 -0
- package/contracts/verifiers/impl/withdraw_nullifier_batch.sol +322 -0
- package/contracts/verifiers/verifier_anon.sol +31 -186
- package/contracts/verifiers/verifier_anon_batch.sol +31 -298
- package/contracts/verifiers/verifier_anon_enc.sol +31 -263
- package/contracts/verifiers/verifier_anon_enc_batch.sol +31 -599
- package/contracts/verifiers/verifier_anon_enc_nullifier.sol +31 -284
- package/contracts/verifiers/verifier_anon_enc_nullifier_batch.sol +33 -676
- package/contracts/verifiers/verifier_anon_enc_nullifier_kyc.sol +31 -291
- package/contracts/verifiers/verifier_anon_enc_nullifier_kyc_batch.sol +33 -683
- package/contracts/verifiers/verifier_anon_enc_nullifier_non_repudiation.sol +33 -410
- package/contracts/verifiers/verifier_anon_enc_nullifier_non_repudiation_batch.sol +33 -1138
- package/contracts/verifiers/verifier_anon_nullifier_kyc_transfer.sol +33 -214
- package/contracts/verifiers/verifier_anon_nullifier_kyc_transferLocked.sol +33 -221
- package/contracts/verifiers/verifier_anon_nullifier_kyc_transferLocked_batch.sol +33 -389
- package/contracts/verifiers/verifier_anon_nullifier_kyc_transfer_batch.sol +33 -382
- package/contracts/verifiers/verifier_anon_nullifier_qurrency_transfer.sol +33 -221
- package/contracts/verifiers/verifier_anon_nullifier_qurrency_transfer_batch.sol +33 -389
- package/contracts/verifiers/verifier_anon_nullifier_transfer.sol +33 -207
- package/contracts/verifiers/verifier_anon_nullifier_transfer_batch.sol +33 -375
- package/contracts/verifiers/verifier_burn.sol +31 -179
- package/contracts/verifiers/verifier_burn_batch.sol +31 -235
- package/contracts/verifiers/verifier_burn_nullifier.sol +31 -200
- package/contracts/verifiers/verifier_burn_nullifier_batch.sol +31 -312
- package/contracts/verifiers/verifier_deposit.sol +31 -179
- package/contracts/verifiers/verifier_deposit_kyc.sol +34 -0
- package/contracts/verifiers/verifier_nf_anon.sol +31 -172
- package/contracts/verifiers/verifier_nf_anon_nullifier_transfer.sol +33 -179
- package/contracts/verifiers/verifier_withdraw.sol +31 -186
- package/contracts/verifiers/verifier_withdraw_batch.sol +31 -242
- package/contracts/verifiers/verifier_withdraw_nullifier.sol +31 -207
- package/contracts/verifiers/verifier_withdraw_nullifier_batch.sol +33 -319
- package/contracts/zeto_anon.sol +77 -231
- package/contracts/zeto_anon_burnable.sol +56 -12
- package/contracts/zeto_anon_enc.sol +93 -190
- package/contracts/zeto_anon_enc_nullifier.sol +249 -195
- package/contracts/zeto_anon_enc_nullifier_kyc.sol +51 -232
- package/contracts/zeto_anon_enc_nullifier_non_repudiation.sol +231 -238
- package/contracts/zeto_anon_nullifier.sol +164 -298
- package/contracts/zeto_anon_nullifier_burnable.sol +68 -18
- package/contracts/zeto_anon_nullifier_kyc.sol +40 -345
- package/contracts/zeto_anon_nullifier_qurrency.sol +217 -361
- package/contracts/zeto_nf_anon.sol +55 -130
- package/contracts/zeto_nf_anon_nullifier.sol +90 -152
- package/hardhat.config.ts +18 -3
- package/ignition/modules/lib/deps.ts +13 -0
- package/ignition/modules/test/tendecimals.ts +7 -1
- package/ignition/modules/zeto_anon.ts +3 -0
- package/ignition/modules/zeto_anon_burnable.ts +11 -7
- package/ignition/modules/zeto_anon_enc.ts +3 -0
- package/ignition/modules/zeto_anon_enc_nullifier.ts +34 -0
- package/ignition/modules/zeto_anon_enc_nullifier_kyc.ts +5 -2
- package/ignition/modules/zeto_anon_enc_nullifier_non_repudiation.ts +3 -0
- package/ignition/modules/zeto_anon_nullifier.ts +31 -4
- package/ignition/modules/zeto_anon_nullifier_burnable.ts +53 -16
- package/ignition/modules/zeto_anon_nullifier_kyc.ts +30 -12
- package/ignition/modules/zeto_anon_nullifier_qurrency.ts +3 -0
- package/ignition/modules/zeto_nf_anon.ts +3 -1
- package/ignition/modules/zeto_nf_anon_nullifier.ts +17 -12
- package/package.json +7 -3
- package/scripts/deploy_cloneable.ts +19 -10
- package/scripts/deploy_upgradeable.ts +9 -5
- package/scripts/lib/zeto_libraries.ts +47 -0
- package/scripts/tokens/Zeto_Anon.ts +6 -3
- package/scripts/tokens/Zeto_AnonBurnable.ts +4 -1
- package/scripts/tokens/Zeto_AnonEnc.ts +15 -3
- package/scripts/tokens/Zeto_AnonEncNullifier.ts +11 -8
- package/scripts/tokens/Zeto_AnonEncNullifierKyc.ts +7 -6
- package/scripts/tokens/Zeto_AnonEncNullifierNonRepudiation.ts +7 -6
- package/scripts/tokens/Zeto_AnonNullifier.ts +7 -6
- package/scripts/tokens/Zeto_AnonNullifierBurnable.ts +7 -6
- package/scripts/tokens/Zeto_AnonNullifierKyc.ts +7 -6
- package/scripts/tokens/Zeto_AnonNullifierQurrency.ts +7 -8
- package/scripts/tokens/Zeto_NfAnon.ts +5 -3
- package/scripts/tokens/Zeto_NfAnonNullifier.ts +7 -7
- package/test/factory.ts +55 -73
- package/test/lib/anon_nullifier_helpers.ts +89 -0
- package/test/lib/anon_zeto_helpers.ts +76 -0
- package/test/lib/deploy.ts +5 -2
- package/test/lib/eip170.ts +23 -0
- package/test/lib/utils.ts +74 -35
- package/test/test/escrow1.ts +185 -58
- package/test/test/escrow2.ts +200 -107
- package/test/test/qurrency.ts +13 -33
- package/test/usdc-shielding.ts +39 -27
- package/test/utils.ts +144 -21
- package/test/zeto_anon.ts +956 -465
- package/test/zeto_anon_enc.ts +881 -143
- package/test/zeto_anon_enc_nullifier.ts +850 -39
- package/test/zeto_anon_enc_nullifier_kyc.ts +123 -182
- package/test/zeto_anon_enc_nullifier_non_repudiation.ts +80 -47
- package/test/zeto_anon_nullifier.ts +1212 -954
- package/test/zeto_anon_nullifier_kyc.ts +677 -656
- package/test/zeto_anon_nullifier_qurrency.ts +455 -307
- package/test/zeto_nf_anon.ts +737 -138
- package/test/zeto_nf_anon_nullifier.ts +876 -247
- package/contracts/lib/zeto_base.sol +0 -293
- package/contracts/lib/zeto_fungible_withdraw.sol +0 -132
- package/contracts/lib/zeto_fungible_withdraw_nullifier.sol +0 -144
- package/contracts/lib/zeto_nullifier.sol +0 -340
- package/contracts/zkDvP.sol_ +0 -273
- package/test/zkDvP.ts_ +0 -455
- /package/contracts/lib/{common.sol → common/common.sol} +0 -0
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
// Copyright © 2024 Kaleido, Inc.
|
|
2
|
+
//
|
|
3
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
//
|
|
5
|
+
// ZK helpers for the `anon_nullifier_transfer` circuit family ({Zeto_AnonNullifier}
|
|
6
|
+
// unlocked-input transfers and createLock). Extracted so escrow and other suites
|
|
7
|
+
// can use them without importing the full `zeto_anon_nullifier.ts` Hardhat module.
|
|
8
|
+
|
|
9
|
+
import { AbiCoder, BigNumberish, ethers } from "ethers";
|
|
10
|
+
import { encodeProof } from "zeto-js";
|
|
11
|
+
import { groth16 } from "snarkjs";
|
|
12
|
+
import { User, UTXO, logger } from "./utils";
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Build a Groth16 proof for an unlocked-input nullifier transfer (merkle-backed).
|
|
16
|
+
*/
|
|
17
|
+
export async function prepareProof(
|
|
18
|
+
circuit: any,
|
|
19
|
+
provingKey: any,
|
|
20
|
+
signer: User,
|
|
21
|
+
inputs: UTXO[],
|
|
22
|
+
_nullifiers: UTXO[],
|
|
23
|
+
outputs: UTXO[],
|
|
24
|
+
root: BigInt,
|
|
25
|
+
merkleProof: BigInt[][],
|
|
26
|
+
owners: User[],
|
|
27
|
+
lockDelegate?: string,
|
|
28
|
+
) {
|
|
29
|
+
const nullifiers = _nullifiers.map((nullifier) => nullifier.hash) as [
|
|
30
|
+
BigNumberish,
|
|
31
|
+
BigNumberish,
|
|
32
|
+
];
|
|
33
|
+
const inputCommitments: BigNumberish[] = inputs.map(
|
|
34
|
+
(input) => input.hash,
|
|
35
|
+
) as BigNumberish[];
|
|
36
|
+
const inputValues = inputs.map((input) => BigInt(input.value || 0n));
|
|
37
|
+
const inputSalts = inputs.map((input) => input.salt || 0n);
|
|
38
|
+
const outputCommitments: BigNumberish[] = outputs.map(
|
|
39
|
+
(output) => output.hash,
|
|
40
|
+
) as BigNumberish[];
|
|
41
|
+
const outputValues = outputs.map((output) => BigInt(output.value || 0n));
|
|
42
|
+
const outputOwnerPublicKeys: BigNumberish[][] = owners.map(
|
|
43
|
+
(owner) => owner.babyJubPublicKey,
|
|
44
|
+
) as BigNumberish[][];
|
|
45
|
+
|
|
46
|
+
const startWitnessCalculation = Date.now();
|
|
47
|
+
const inputObj: Record<string, unknown> = {
|
|
48
|
+
nullifiers,
|
|
49
|
+
inputCommitments,
|
|
50
|
+
inputValues,
|
|
51
|
+
inputSalts,
|
|
52
|
+
inputOwnerPrivateKey: signer.formattedPrivateKey,
|
|
53
|
+
root,
|
|
54
|
+
enabled: nullifiers.map((n) => (n !== 0n ? 1 : 0)),
|
|
55
|
+
merkleProof,
|
|
56
|
+
outputCommitments,
|
|
57
|
+
outputValues,
|
|
58
|
+
outputSalts: outputs.map((output) => output.salt || 0n),
|
|
59
|
+
outputOwnerPublicKeys,
|
|
60
|
+
};
|
|
61
|
+
if (lockDelegate) {
|
|
62
|
+
inputObj["lockDelegate"] = ethers.toBigInt(lockDelegate);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
const witness = await circuit.calculateWTNSBin(inputObj, true);
|
|
66
|
+
const timeWithnessCalculation = Date.now() - startWitnessCalculation;
|
|
67
|
+
|
|
68
|
+
const startProofGeneration = Date.now();
|
|
69
|
+
const { proof } = (await groth16.prove(provingKey, witness)) as {
|
|
70
|
+
proof: BigNumberish[];
|
|
71
|
+
publicSignals: BigNumberish[];
|
|
72
|
+
};
|
|
73
|
+
const timeProofGeneration = Date.now() - startProofGeneration;
|
|
74
|
+
|
|
75
|
+
logger.debug(
|
|
76
|
+
`Witness calculation time: ${timeWithnessCalculation}ms. Proof generation time: ${timeProofGeneration}ms.`,
|
|
77
|
+
);
|
|
78
|
+
|
|
79
|
+
const encodedProof = encodeProof(proof);
|
|
80
|
+
return encodedProof;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/** ABI encoding for nullifier transfer proofs: root prefix + Groth16 tuple. */
|
|
84
|
+
export function encodeToBytes(root: any, proof: any) {
|
|
85
|
+
return new AbiCoder().encode(
|
|
86
|
+
["uint256 root", "tuple(uint256[2] pA, uint256[2][2] pB, uint256[2] pC)"],
|
|
87
|
+
[root, proof],
|
|
88
|
+
);
|
|
89
|
+
}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
// Copyright © 2024 Kaleido, Inc.
|
|
2
|
+
//
|
|
3
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
//
|
|
5
|
+
// Shared ZK helpers for the plain `anon` circuit (non-nullifier tokens such as
|
|
6
|
+
// {Zeto_Anon}). Kept separate from `zeto_anon.ts` so escrow and other suites
|
|
7
|
+
// can import these without registering the full Zeto_Anon Hardhat test module.
|
|
8
|
+
|
|
9
|
+
import { AbiCoder, BigNumberish } from "ethers";
|
|
10
|
+
import { encodeProof } from "zeto-js";
|
|
11
|
+
import { groth16 } from "snarkjs";
|
|
12
|
+
import { formatPrivKeyForBabyJub, stringifyBigInts } from "maci-crypto";
|
|
13
|
+
import { User, UTXO, logger, ZERO_UTXO } from "./utils";
|
|
14
|
+
|
|
15
|
+
const ZERO_PUBKEY = [0n, 0n];
|
|
16
|
+
|
|
17
|
+
export async function prepareProof(
|
|
18
|
+
circuit: any,
|
|
19
|
+
provingKey: any,
|
|
20
|
+
signer: User,
|
|
21
|
+
inputs: UTXO[],
|
|
22
|
+
outputs: UTXO[],
|
|
23
|
+
owners: User[],
|
|
24
|
+
) {
|
|
25
|
+
const inputCommitments: BigNumberish[] = inputs.map(
|
|
26
|
+
(input) => input.hash,
|
|
27
|
+
) as BigNumberish[];
|
|
28
|
+
const inputValues = inputs.map((input) => BigInt(input.value || 0n));
|
|
29
|
+
const inputSalts = inputs.map((input) => input.salt || 0n);
|
|
30
|
+
const outputCommitments: BigNumberish[] = outputs.map(
|
|
31
|
+
(output) => output.hash,
|
|
32
|
+
) as BigNumberish[];
|
|
33
|
+
const outputValues = outputs.map((output) => BigInt(output.value || 0n));
|
|
34
|
+
const outputSalts = outputs.map((o) => o.salt || 0n);
|
|
35
|
+
const outputOwnerPublicKeys: BigNumberish[][] = owners.map(
|
|
36
|
+
(owner) => owner.babyJubPublicKey || ZERO_PUBKEY,
|
|
37
|
+
) as BigNumberish[][];
|
|
38
|
+
const otherInputs = stringifyBigInts({
|
|
39
|
+
inputOwnerPrivateKey: formatPrivKeyForBabyJub(signer.babyJubPrivateKey),
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
const startWitnessCalculation = Date.now();
|
|
43
|
+
const witness = await circuit.calculateWTNSBin(
|
|
44
|
+
{
|
|
45
|
+
inputCommitments,
|
|
46
|
+
inputValues,
|
|
47
|
+
inputSalts,
|
|
48
|
+
outputCommitments,
|
|
49
|
+
outputValues,
|
|
50
|
+
outputSalts,
|
|
51
|
+
outputOwnerPublicKeys,
|
|
52
|
+
...otherInputs,
|
|
53
|
+
},
|
|
54
|
+
true,
|
|
55
|
+
);
|
|
56
|
+
const timeWitnessCalculation = Date.now() - startWitnessCalculation;
|
|
57
|
+
|
|
58
|
+
const startProofGeneration = Date.now();
|
|
59
|
+
const { proof, publicSignals } = (await groth16.prove(
|
|
60
|
+
provingKey,
|
|
61
|
+
witness,
|
|
62
|
+
)) as { proof: BigNumberish[]; publicSignals: BigNumberish[] };
|
|
63
|
+
const timeProofGeneration = Date.now() - startProofGeneration;
|
|
64
|
+
logger.debug(
|
|
65
|
+
`Witness calculation time: ${timeWitnessCalculation}ms, Proof generation time: ${timeProofGeneration}ms`,
|
|
66
|
+
);
|
|
67
|
+
const encodedProof = encodeProof(proof);
|
|
68
|
+
return encodedProof;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export function encodeToBytes(proof: any) {
|
|
72
|
+
return new AbiCoder().encode(
|
|
73
|
+
["tuple(uint256[2] pA, uint256[2][2] pB, uint256[2] pC)"],
|
|
74
|
+
[proof],
|
|
75
|
+
);
|
|
76
|
+
}
|
package/test/lib/deploy.ts
CHANGED
|
@@ -10,9 +10,12 @@ import {
|
|
|
10
10
|
deployNonFungible as deployNonFungibleCloneable,
|
|
11
11
|
} from "../../scripts/deploy_cloneable";
|
|
12
12
|
import fungibilities from "../../scripts/tokens.json";
|
|
13
|
+
import { logger } from "./utils";
|
|
13
14
|
import { ethers } from "hardhat";
|
|
15
|
+
import { assertEip170Compliant } from "./eip170";
|
|
14
16
|
|
|
15
17
|
export async function deployZeto(tokenName: string) {
|
|
18
|
+
await assertEip170Compliant(tokenName);
|
|
16
19
|
let zeto, erc20, deployer;
|
|
17
20
|
|
|
18
21
|
// for testing with public chains, skip deployment if
|
|
@@ -34,7 +37,7 @@ export async function deployZeto(tokenName: string) {
|
|
|
34
37
|
}
|
|
35
38
|
|
|
36
39
|
if (process.env.USE_FACTORY !== "true") {
|
|
37
|
-
|
|
40
|
+
logger.debug("Deploying as upgradeable contracts");
|
|
38
41
|
// setup via the deployment scripts
|
|
39
42
|
const deployFunc = isFungible
|
|
40
43
|
? deployFungibleUpgradeable
|
|
@@ -42,7 +45,7 @@ export async function deployZeto(tokenName: string) {
|
|
|
42
45
|
const result = await deployFunc(tokenName);
|
|
43
46
|
({ deployer, zeto, erc20 } = result as any);
|
|
44
47
|
} else {
|
|
45
|
-
|
|
48
|
+
logger.debug('Deploying as cloneable contracts using "ZetoTokenFactory"');
|
|
46
49
|
let args, zetoImpl;
|
|
47
50
|
const deployFunc = isFungible
|
|
48
51
|
? deployFungibleCloneable
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { artifacts } from "hardhat";
|
|
2
|
+
import {
|
|
3
|
+
EIP170_BYTE_LIMIT,
|
|
4
|
+
EIP170_EXEMPT_TOKEN_SET,
|
|
5
|
+
} from "../../config/eip170";
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Assert a token implementation fits EIP-170 before deploy when it is not exempt.
|
|
9
|
+
* Hardhat Network runs with allowUnlimitedContractSize enabled (see hardhat.config.ts);
|
|
10
|
+
* exempt tokens may exceed the limit.
|
|
11
|
+
*/
|
|
12
|
+
export async function assertEip170Compliant(tokenName: string): Promise<void> {
|
|
13
|
+
if (EIP170_EXEMPT_TOKEN_SET.has(tokenName)) {
|
|
14
|
+
return;
|
|
15
|
+
}
|
|
16
|
+
const artifact = await artifacts.readArtifact(tokenName);
|
|
17
|
+
const deployedBytes = (artifact.deployedBytecode.length - 2) / 2;
|
|
18
|
+
if (deployedBytes > EIP170_BYTE_LIMIT) {
|
|
19
|
+
throw new Error(
|
|
20
|
+
`${tokenName} deployed bytecode is ${deployedBytes} bytes, exceeding EIP-170 limit ${EIP170_BYTE_LIMIT}`,
|
|
21
|
+
);
|
|
22
|
+
}
|
|
23
|
+
}
|
package/test/lib/utils.ts
CHANGED
|
@@ -18,13 +18,15 @@ import {
|
|
|
18
18
|
ContractTransactionReceipt,
|
|
19
19
|
Signer,
|
|
20
20
|
BigNumberish,
|
|
21
|
-
AddressLike,
|
|
22
21
|
} from "ethers";
|
|
23
22
|
import {
|
|
24
23
|
genKeypair,
|
|
25
24
|
formatPrivKeyForBabyJub,
|
|
26
|
-
genEcdhSharedKey,
|
|
27
25
|
} from "maci-crypto";
|
|
26
|
+
import { Logger, ILogObj } from "tslog";
|
|
27
|
+
const logLevel = process.env.LOG_LEVEL || "3";
|
|
28
|
+
export const logger: Logger<ILogObj> = new Logger({ name: "e2e", minLevel: parseInt(logLevel) });
|
|
29
|
+
|
|
28
30
|
import { Poseidon, newSalt, tokenUriHash } from "zeto-js";
|
|
29
31
|
|
|
30
32
|
const poseidonHash3 = Poseidon.poseidon3;
|
|
@@ -35,18 +37,18 @@ export interface UTXO {
|
|
|
35
37
|
value?: number;
|
|
36
38
|
tokenId?: number;
|
|
37
39
|
uri?: string;
|
|
38
|
-
hash:
|
|
39
|
-
salt?:
|
|
40
|
+
hash: bigint;
|
|
41
|
+
salt?: bigint;
|
|
40
42
|
}
|
|
41
43
|
|
|
42
|
-
export const ZERO_UTXO: UTXO = { hash:
|
|
44
|
+
export const ZERO_UTXO: UTXO = { hash: 0n };
|
|
43
45
|
|
|
44
46
|
export interface User {
|
|
45
47
|
signer: Signer;
|
|
46
48
|
ethAddress: string;
|
|
47
|
-
babyJubPrivateKey:
|
|
48
|
-
babyJubPublicKey:
|
|
49
|
-
formattedPrivateKey:
|
|
49
|
+
babyJubPrivateKey: bigint;
|
|
50
|
+
babyJubPublicKey: bigint[];
|
|
51
|
+
formattedPrivateKey: bigint;
|
|
50
52
|
}
|
|
51
53
|
|
|
52
54
|
export async function newUser(signer: Signer) {
|
|
@@ -62,7 +64,7 @@ export async function newUser(signer: Signer) {
|
|
|
62
64
|
};
|
|
63
65
|
}
|
|
64
66
|
|
|
65
|
-
export function newUTXO(value: number, owner: User, salt?:
|
|
67
|
+
export function newUTXO(value: number, owner: User, salt?: bigint): UTXO {
|
|
66
68
|
if (!salt) salt = newSalt();
|
|
67
69
|
const hash = poseidonHash4([
|
|
68
70
|
BigInt(value),
|
|
@@ -77,7 +79,7 @@ export function newAssetUTXO(
|
|
|
77
79
|
tokenId: number,
|
|
78
80
|
uri: string,
|
|
79
81
|
owner: User,
|
|
80
|
-
salt?:
|
|
82
|
+
salt?: bigint,
|
|
81
83
|
): UTXO {
|
|
82
84
|
if (!salt) salt = newSalt();
|
|
83
85
|
const hash = poseidonHash5([
|
|
@@ -122,10 +124,13 @@ export async function doMint(
|
|
|
122
124
|
.connect(minter)
|
|
123
125
|
.mint(outputCommitments, "0x");
|
|
124
126
|
const result = await tx.wait();
|
|
125
|
-
|
|
127
|
+
logger.debug(`Method mint() complete. Gas used: ${result?.gasUsed}`);
|
|
126
128
|
if (result?.gasUsed && Array.isArray(gasHistories)) {
|
|
127
129
|
gasHistories.push(result?.gasUsed);
|
|
128
130
|
}
|
|
131
|
+
if (!result) {
|
|
132
|
+
throw new Error("doMint: transaction receipt is null");
|
|
133
|
+
}
|
|
129
134
|
return result;
|
|
130
135
|
}
|
|
131
136
|
|
|
@@ -141,10 +146,13 @@ export async function doDeposit(
|
|
|
141
146
|
.connect(depositUser)
|
|
142
147
|
.deposit(amount, commitment, proof, "0x");
|
|
143
148
|
const result = await tx.wait();
|
|
144
|
-
|
|
149
|
+
logger.debug(`Method deposit() complete. Gas used: ${result?.gasUsed}`);
|
|
145
150
|
if (result?.gasUsed && Array.isArray(gasHistories)) {
|
|
146
151
|
gasHistories.push(result?.gasUsed);
|
|
147
152
|
}
|
|
153
|
+
if (!result) {
|
|
154
|
+
throw new Error("doDeposit: transaction receipt is null");
|
|
155
|
+
}
|
|
148
156
|
return result;
|
|
149
157
|
}
|
|
150
158
|
|
|
@@ -162,17 +170,23 @@ export async function doWithdraw(
|
|
|
162
170
|
.connect(withdrawUser)
|
|
163
171
|
.withdraw(amount, nullifiers, commitment, root, proof);
|
|
164
172
|
const result = await tx.wait();
|
|
165
|
-
|
|
173
|
+
logger.debug(`Method withdraw() complete. Gas used: ${result?.gasUsed}`);
|
|
166
174
|
if (result?.gasUsed && Array.isArray(gasHistories)) {
|
|
167
175
|
gasHistories.push(result?.gasUsed);
|
|
168
176
|
}
|
|
177
|
+
if (!result) {
|
|
178
|
+
throw new Error("doWithdraw: transaction receipt is null");
|
|
179
|
+
}
|
|
169
180
|
return result;
|
|
170
181
|
}
|
|
171
182
|
|
|
172
183
|
export function parseUTXOEvents(
|
|
173
184
|
zetoTokenContract: any,
|
|
174
|
-
result: ContractTransactionReceipt,
|
|
185
|
+
result: ContractTransactionReceipt | null,
|
|
175
186
|
) {
|
|
187
|
+
if (!result) {
|
|
188
|
+
throw new Error("parseUTXOEvents: transaction receipt is null");
|
|
189
|
+
}
|
|
176
190
|
let returnValues: any[] = [];
|
|
177
191
|
for (const log of result.logs || []) {
|
|
178
192
|
const event = zetoTokenContract.interface.parseLog(log as any);
|
|
@@ -183,6 +197,13 @@ export function parseUTXOEvents(
|
|
|
183
197
|
outputs: event?.args.outputs,
|
|
184
198
|
submitter: event?.args.submitter,
|
|
185
199
|
};
|
|
200
|
+
} else if (event?.name === "UTXOTransferLocked") {
|
|
201
|
+
e = {
|
|
202
|
+
lockedInputs: event?.args.lockedInputs,
|
|
203
|
+
lockedOutputs: event?.args.lockedOutputs,
|
|
204
|
+
outputs: event?.args.outputs,
|
|
205
|
+
submitter: event?.args.submitter,
|
|
206
|
+
};
|
|
186
207
|
} else if (event?.name === "UTXOTransferWithEncryptedValues") {
|
|
187
208
|
e = {
|
|
188
209
|
inputs: event?.args.inputs,
|
|
@@ -192,6 +213,15 @@ export function parseUTXOEvents(
|
|
|
192
213
|
submitter: event?.args.submitter,
|
|
193
214
|
ecdhPublicKey: event?.args.ecdhPublicKey,
|
|
194
215
|
};
|
|
216
|
+
} else if (event?.name === "UTXOTransferWithMlkemEncryptedValues") {
|
|
217
|
+
e = {
|
|
218
|
+
inputs: event?.args.inputs,
|
|
219
|
+
outputs: event?.args.outputs,
|
|
220
|
+
encryptedValues: event?.args.encryptedValues,
|
|
221
|
+
encryptionNonce: event?.args.encryptionNonce,
|
|
222
|
+
submitter: event?.args.submitter,
|
|
223
|
+
encapsulatedSharedSecret: event?.args.encapsulatedSharedSecret,
|
|
224
|
+
};
|
|
195
225
|
} else if (event?.name === "UTXOTransferNonRepudiation") {
|
|
196
226
|
e = {
|
|
197
227
|
inputs: event?.args.inputs,
|
|
@@ -208,36 +238,45 @@ export function parseUTXOEvents(
|
|
|
208
238
|
receivers: event?.args.receivers,
|
|
209
239
|
submitter: event?.args.submitter,
|
|
210
240
|
};
|
|
211
|
-
} else if (event?.name === "
|
|
241
|
+
} else if (event?.name === "UTXOWithdraw") {
|
|
212
242
|
e = {
|
|
213
|
-
|
|
214
|
-
|
|
243
|
+
amount: event?.args.amount,
|
|
244
|
+
inputs: event?.args.inputs,
|
|
245
|
+
output: event?.args.output,
|
|
215
246
|
};
|
|
216
|
-
} else if (event?.name === "
|
|
247
|
+
} else if (event?.name === "LockCreate") {
|
|
217
248
|
e = {
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
delegate: event?.args.delegate,
|
|
249
|
+
lockId: event?.args.lockId,
|
|
250
|
+
lockData: event?.args.lockData,
|
|
221
251
|
};
|
|
222
|
-
} else if (event?.name === "
|
|
252
|
+
} else if (event?.name === "UnlockPrepare") {
|
|
223
253
|
e = {
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
254
|
+
lockId: event?.args.lockId,
|
|
255
|
+
operator: event?.args.operator,
|
|
256
|
+
settle: event?.args.settle,
|
|
227
257
|
};
|
|
228
|
-
} else if (event?.name === "
|
|
258
|
+
} else if (event?.name === "Unlock") {
|
|
229
259
|
e = {
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
260
|
+
lockId: event?.args.lockId,
|
|
261
|
+
operator: event?.args.operator,
|
|
262
|
+
inputs: event?.args.inputs,
|
|
263
|
+
delegate: event?.args.delegate,
|
|
264
|
+
settle: event?.args.settle,
|
|
234
265
|
};
|
|
235
|
-
} else if (
|
|
236
|
-
event?.name === "PaymentApproved" ||
|
|
237
|
-
event?.name === "PaymentCompleted"
|
|
238
|
-
) {
|
|
266
|
+
} else if (event?.name === "LockRollback") {
|
|
239
267
|
e = {
|
|
240
|
-
|
|
268
|
+
lockId: event?.args.lockId,
|
|
269
|
+
operator: event?.args.operator,
|
|
270
|
+
inputs: event?.args.inputs,
|
|
271
|
+
delegate: event?.args.delegate,
|
|
272
|
+
rollback: event?.args.rollback,
|
|
273
|
+
};
|
|
274
|
+
} else if (event?.name === "LockDelegate") {
|
|
275
|
+
e = {
|
|
276
|
+
lockId: event?.args.lockId,
|
|
277
|
+
operator: event?.args.operator,
|
|
278
|
+
oldDelegate: event?.args.oldDelegate,
|
|
279
|
+
newDelegate: event?.args.newDelegate,
|
|
241
280
|
};
|
|
242
281
|
}
|
|
243
282
|
returnValues.push(e);
|