@lfdecentralizedtrust/zeto-contracts 0.2.2 → 0.5.0
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 +70 -162
- 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/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 +451 -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 +613 -0
- package/contracts/lib/zeto_non_fungible.sol +236 -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 +9 -3
- package/ignition/modules/lib/deps.ts +8 -0
- package/ignition/modules/zeto_anon_burnable.ts +8 -7
- package/ignition/modules/zeto_anon_enc_nullifier.ts +31 -0
- package/ignition/modules/zeto_anon_enc_nullifier_kyc.ts +2 -2
- package/ignition/modules/zeto_anon_nullifier.ts +28 -4
- package/ignition/modules/zeto_anon_nullifier_burnable.ts +50 -16
- package/ignition/modules/zeto_anon_nullifier_kyc.ts +27 -12
- package/ignition/modules/zeto_nf_anon_nullifier.ts +14 -10
- package/package.json +4 -2
- package/scripts/deploy_cloneable.ts +19 -10
- package/scripts/deploy_upgradeable.ts +9 -5
- package/scripts/tokens/Zeto_Anon.ts +3 -3
- package/scripts/tokens/Zeto_AnonBurnable.ts +1 -1
- package/scripts/tokens/Zeto_AnonEnc.ts +12 -3
- package/scripts/tokens/Zeto_AnonEncNullifier.ts +5 -3
- package/scripts/tokens/Zeto_AnonEncNullifierKyc.ts +1 -1
- package/scripts/tokens/Zeto_AnonEncNullifierNonRepudiation.ts +1 -1
- package/scripts/tokens/Zeto_AnonNullifier.ts +1 -1
- package/scripts/tokens/Zeto_AnonNullifierBurnable.ts +1 -1
- package/scripts/tokens/Zeto_AnonNullifierKyc.ts +1 -1
- package/scripts/tokens/Zeto_AnonNullifierQurrency.ts +1 -1
- package/scripts/tokens/Zeto_NfAnon.ts +2 -2
- package/scripts/tokens/Zeto_NfAnonNullifier.ts +1 -1
- package/test/factory.ts +46 -73
- package/test/lib/anon_nullifier_helpers.ts +89 -0
- package/test/lib/anon_zeto_helpers.ts +76 -0
- package/test/lib/deploy.ts +3 -2
- 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 -26
- package/test/utils.ts +144 -21
- package/test/zeto_anon.ts +956 -465
- package/test/zeto_anon_enc.ts +881 -142
- package/test/zeto_anon_enc_nullifier.ts +847 -38
- package/test/zeto_anon_enc_nullifier_kyc.ts +120 -181
- package/test/zeto_anon_enc_nullifier_non_repudiation.ts +77 -46
- package/test/zeto_anon_nullifier.ts +1212 -953
- package/test/zeto_anon_nullifier_kyc.ts +674 -655
- package/test/zeto_anon_nullifier_qurrency.ts +452 -306
- package/test/zeto_nf_anon.ts +737 -137
- package/test/zeto_nf_anon_nullifier.ts +876 -246
- 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
|
@@ -15,16 +15,28 @@
|
|
|
15
15
|
// limitations under the License.
|
|
16
16
|
pragma solidity ^0.8.27;
|
|
17
17
|
|
|
18
|
-
import {Commonlib} from "../lib/common.sol";
|
|
18
|
+
import {Commonlib} from "../lib/common/common.sol";
|
|
19
19
|
import {Zeto_AnonNullifier} from "../zeto_anon_nullifier.sol";
|
|
20
|
-
|
|
20
|
+
import {ILockableCapability} from "../lib/interfaces/ILockableCapability.sol";
|
|
21
|
+
import {IZetoLockableCapability} from "../lib/interfaces/IZetoLockableCapability.sol";
|
|
21
22
|
|
|
22
|
-
/// @title
|
|
23
|
+
/// @title zkEscrow2
|
|
23
24
|
/// @author Kaleido, Inc.
|
|
24
|
-
/// @
|
|
25
|
+
/// @notice Sample on-chain escrow built on top of {Zeto_AnonNullifier},
|
|
26
|
+
/// the nullifier-based fungible Zeto token. The escrow flow is
|
|
27
|
+
/// identical to {zkEscrow1} (see that contract for a step-by-step
|
|
28
|
+
/// description); the only difference is that the underlying token
|
|
29
|
+
/// consumes its locked inputs as **raw UTXO hashes** under the
|
|
30
|
+
/// locked-input verifier rather than as nullifiers.
|
|
31
|
+
///
|
|
32
|
+
/// The {checkAndPadCommitments} +
|
|
33
|
+
/// {constructPublicSignalsAndVerifyProof} pair handles both
|
|
34
|
+
/// flavours uniformly via the `inputsLocked=true` flag, so this
|
|
35
|
+
/// escrow does not need a different proof-shaping path from
|
|
36
|
+
/// {zkEscrow1}; it just talks to a different token.
|
|
25
37
|
contract zkEscrow2 {
|
|
26
38
|
enum PaymentStatus {
|
|
27
|
-
UNKNOWN, //
|
|
39
|
+
UNKNOWN, // default value for empty payment slots
|
|
28
40
|
INITIATED,
|
|
29
41
|
APPROVED,
|
|
30
42
|
COMPLETED,
|
|
@@ -32,10 +44,9 @@ contract zkEscrow2 {
|
|
|
32
44
|
}
|
|
33
45
|
|
|
34
46
|
struct Payment {
|
|
35
|
-
|
|
47
|
+
bytes32 lockId;
|
|
36
48
|
uint256[] outputs;
|
|
37
|
-
|
|
38
|
-
Commonlib.Proof proof;
|
|
49
|
+
bytes proof;
|
|
39
50
|
PaymentStatus status;
|
|
40
51
|
}
|
|
41
52
|
|
|
@@ -46,7 +57,7 @@ contract zkEscrow2 {
|
|
|
46
57
|
|
|
47
58
|
event PaymentInitiated(
|
|
48
59
|
uint256 paymentId,
|
|
49
|
-
|
|
60
|
+
bytes32 lockId,
|
|
50
61
|
uint256[] outputs,
|
|
51
62
|
bytes data
|
|
52
63
|
);
|
|
@@ -57,27 +68,39 @@ contract zkEscrow2 {
|
|
|
57
68
|
zeto = Zeto_AnonNullifier(zetoAddress);
|
|
58
69
|
}
|
|
59
70
|
|
|
71
|
+
/// @notice Record a new escrowed payment against an existing lock.
|
|
72
|
+
/// @dev See {zkEscrow1.initiatePayment} for the rationale on
|
|
73
|
+
/// requiring `info.spender == address(this)` instead of any
|
|
74
|
+
/// caller-provided delegate parameter.
|
|
60
75
|
function initiatePayment(
|
|
61
|
-
|
|
76
|
+
bytes32 lockId,
|
|
62
77
|
uint256[] memory outputs,
|
|
63
78
|
bytes calldata data
|
|
64
79
|
) public {
|
|
80
|
+
ILockableCapability.LockInfo memory info = zeto.getLock(lockId);
|
|
81
|
+
require(info.spender == address(this), "Escrow is not the spender");
|
|
65
82
|
inflightCount++;
|
|
66
|
-
|
|
83
|
+
bytes memory emptyProof;
|
|
67
84
|
payments[inflightCount] = Payment(
|
|
68
|
-
|
|
85
|
+
lockId,
|
|
69
86
|
outputs,
|
|
70
|
-
0,
|
|
71
87
|
emptyProof,
|
|
72
88
|
PaymentStatus.INITIATED
|
|
73
89
|
);
|
|
74
|
-
emit PaymentInitiated(inflightCount,
|
|
90
|
+
emit PaymentInitiated(inflightCount, lockId, outputs, data);
|
|
75
91
|
}
|
|
76
92
|
|
|
93
|
+
/// @notice Verify the spend ZK proof for an initiated payment.
|
|
94
|
+
/// @dev The locked inputs are read fresh from
|
|
95
|
+
/// {Zeto_AnonNullifier.getLockedInputs} so that the verifier
|
|
96
|
+
/// sees the same array {Zeto_AnonNullifier} will use during
|
|
97
|
+
/// {spendLock} downstream. For nullifier tokens these are raw
|
|
98
|
+
/// UTXO hashes (not nullifiers): see
|
|
99
|
+
/// {Zeto_AnonNullifier.constructPublicInputs}'s
|
|
100
|
+
/// `inputsLocked` branch for the public-inputs layout.
|
|
77
101
|
function approvePayment(
|
|
78
102
|
uint256 paymentId,
|
|
79
|
-
|
|
80
|
-
Commonlib.Proof memory proof,
|
|
103
|
+
bytes calldata proof,
|
|
81
104
|
bytes calldata data
|
|
82
105
|
) public {
|
|
83
106
|
Payment storage payment = payments[paymentId];
|
|
@@ -85,33 +108,45 @@ contract zkEscrow2 {
|
|
|
85
108
|
payment.status == PaymentStatus.INITIATED,
|
|
86
109
|
"Payment not initiated"
|
|
87
110
|
);
|
|
88
|
-
uint256[] memory
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
111
|
+
uint256[] memory lockedInputs = zeto.getLockedInputs(payment.lockId);
|
|
112
|
+
(
|
|
113
|
+
uint256[] memory paddedInputs,
|
|
114
|
+
uint256[] memory paddedOutputs
|
|
115
|
+
) = zeto.checkAndPadCommitments(lockedInputs, payment.outputs);
|
|
92
116
|
require(
|
|
93
|
-
zeto.
|
|
117
|
+
zeto.constructPublicSignalsAndVerifyProof(
|
|
118
|
+
paddedInputs,
|
|
119
|
+
paddedOutputs,
|
|
120
|
+
proof,
|
|
121
|
+
true
|
|
122
|
+
),
|
|
94
123
|
"Invalid proof"
|
|
95
124
|
);
|
|
96
125
|
payment.proof = proof;
|
|
97
|
-
payment.root = root;
|
|
98
126
|
payment.status = PaymentStatus.APPROVED;
|
|
99
127
|
emit PaymentApproved(paymentId, data);
|
|
100
128
|
}
|
|
101
129
|
|
|
130
|
+
/// @notice Forward the approved spend proof to
|
|
131
|
+
/// {Zeto_AnonNullifier.spendLock}. After this returns the lock
|
|
132
|
+
/// is consumed, the locked UTXOs are marked spent on the
|
|
133
|
+
/// underlying nullifier storage, and the unlocked outputs are
|
|
134
|
+
/// appended to the regular commitments tree.
|
|
102
135
|
function completePayment(uint256 paymentId, bytes calldata data) public {
|
|
103
136
|
Payment storage payment = payments[paymentId];
|
|
104
137
|
require(
|
|
105
138
|
payment.status == PaymentStatus.APPROVED,
|
|
106
139
|
"Payment not approved"
|
|
107
140
|
);
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
141
|
+
IZetoLockableCapability.ZetoSpendLockArgs
|
|
142
|
+
memory spendArgs = IZetoLockableCapability.ZetoSpendLockArgs({
|
|
143
|
+
txId: bytes32(paymentId),
|
|
144
|
+
lockedOutputs: new uint256[](0),
|
|
145
|
+
outputs: payment.outputs,
|
|
146
|
+
proof: payment.proof,
|
|
147
|
+
data: ""
|
|
148
|
+
});
|
|
149
|
+
zeto.spendLock(payment.lockId, abi.encode(spendArgs), "");
|
|
115
150
|
payment.status = PaymentStatus.COMPLETED;
|
|
116
151
|
emit PaymentCompleted(paymentId, data);
|
|
117
152
|
}
|
|
@@ -16,8 +16,16 @@
|
|
|
16
16
|
pragma solidity ^0.8.27;
|
|
17
17
|
|
|
18
18
|
import {Groth16Verifier_AnonNullifierQurrencyTransfer} from "../verifiers/verifier_anon_nullifier_qurrency_transfer.sol";
|
|
19
|
-
import {Commonlib} from "../lib/common.sol";
|
|
19
|
+
import {Commonlib} from "../lib/common/common.sol";
|
|
20
20
|
|
|
21
|
+
/// @title TestVerifierQurrency
|
|
22
|
+
/// @notice Thin standalone wrapper around the
|
|
23
|
+
/// {Groth16Verifier_AnonNullifierQurrencyTransfer} verifier so that
|
|
24
|
+
/// its 48-element public-input signature can be exercised in
|
|
25
|
+
/// isolation, without dragging in the full {Zeto_AnonNullifierQurrency}
|
|
26
|
+
/// token. Useful for end-to-end ML-KEM payload tests where we need
|
|
27
|
+
/// to confirm the snarkjs proof matches what the on-chain verifier
|
|
28
|
+
/// expects, decoupled from token bookkeeping.
|
|
21
29
|
contract TestVerifierQurrency {
|
|
22
30
|
Groth16Verifier_AnonNullifierQurrencyTransfer verifier;
|
|
23
31
|
|
|
@@ -29,7 +37,7 @@ contract TestVerifierQurrency {
|
|
|
29
37
|
|
|
30
38
|
function verifyProof(
|
|
31
39
|
Commonlib.Proof memory proof,
|
|
32
|
-
uint256[
|
|
40
|
+
uint256[48] memory publicInputs
|
|
33
41
|
) public returns (bool) {
|
|
34
42
|
bool result = verifier.verifyProof(
|
|
35
43
|
proof.pA,
|
package/contracts/test/smt.sol
CHANGED
|
@@ -18,7 +18,12 @@ pragma solidity ^0.8.27;
|
|
|
18
18
|
import {SmtLib} from "@iden3/contracts/contracts/lib/SmtLib.sol";
|
|
19
19
|
import {PoseidonUnit3L} from "@iden3/contracts/contracts/lib/Poseidon.sol";
|
|
20
20
|
|
|
21
|
-
|
|
21
|
+
/// @title TestSmt
|
|
22
|
+
/// @notice Standalone harness for poking at the {SmtLib} sparse Merkle tree
|
|
23
|
+
/// library used by the nullifier-based Zeto storage. Not part of the
|
|
24
|
+
/// production tree; intended for unit tests that need to compare
|
|
25
|
+
/// on-chain SMT behavior against an off-chain reference (e.g. the
|
|
26
|
+
/// js-merkletree library) without spinning up a full Zeto token.
|
|
22
27
|
contract TestSmt {
|
|
23
28
|
using SmtLib for SmtLib.Data;
|
|
24
29
|
|
|
@@ -16,25 +16,27 @@
|
|
|
16
16
|
pragma solidity ^0.8.27;
|
|
17
17
|
|
|
18
18
|
import {Zeto_Anon} from "../zeto_anon.sol";
|
|
19
|
-
import {
|
|
20
|
-
import {ZetoCommon} from "../lib/zeto_common.sol";
|
|
19
|
+
import {IZetoInitializable} from "../lib/interfaces/IZetoInitializable.sol";
|
|
21
20
|
|
|
21
|
+
/// @title TenDecimals
|
|
22
|
+
/// @notice Test sibling of {Zeto_Anon} that overrides {decimals} to 10.
|
|
23
|
+
/// Confirms that downstream extensions can change the decimals
|
|
24
|
+
/// exposed by the inherited {ZetoCommon.decimals} view (default 4)
|
|
25
|
+
/// without otherwise altering the token. The {initialize} override
|
|
26
|
+
/// is required because {Zeto_Anon.initialize} is `virtual` —
|
|
27
|
+
/// re-declaring it here keeps it callable on the proxy and
|
|
28
|
+
/// locks the implementation otherwise unchanged.
|
|
22
29
|
contract TenDecimals is Zeto_Anon {
|
|
23
|
-
function decimals()
|
|
24
|
-
public
|
|
25
|
-
pure
|
|
26
|
-
override(IZeto, ZetoCommon)
|
|
27
|
-
returns (uint8)
|
|
28
|
-
{
|
|
30
|
+
function decimals() public pure override returns (uint8) {
|
|
29
31
|
return 10;
|
|
30
32
|
}
|
|
31
33
|
|
|
32
34
|
function initialize(
|
|
33
|
-
string
|
|
34
|
-
string
|
|
35
|
+
string calldata name,
|
|
36
|
+
string calldata symbol,
|
|
35
37
|
address initialOwner,
|
|
36
|
-
VerifiersInfo calldata
|
|
38
|
+
IZetoInitializable.VerifiersInfo calldata verifiers
|
|
37
39
|
) public override initializer {
|
|
38
|
-
|
|
40
|
+
__ZetoAnon_init(name, symbol, initialOwner, verifiers);
|
|
39
41
|
}
|
|
40
42
|
}
|
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
// SPDX-License-Identifier: GPL-3.0
|
|
2
|
+
/*
|
|
3
|
+
Copyright 2021 0KIMS association.
|
|
4
|
+
|
|
5
|
+
This file is generated with [snarkJS](https://github.com/iden3/snarkjs).
|
|
6
|
+
|
|
7
|
+
snarkJS is a free software: you can redistribute it and/or modify it
|
|
8
|
+
under the terms of the GNU General Public License as published by
|
|
9
|
+
the Free Software Foundation, either version 3 of the License, or
|
|
10
|
+
(at your option) any later version.
|
|
11
|
+
|
|
12
|
+
snarkJS is distributed in the hope that it will be useful, but WITHOUT
|
|
13
|
+
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
|
14
|
+
or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
|
|
15
|
+
License for more details.
|
|
16
|
+
|
|
17
|
+
You should have received a copy of the GNU General Public License
|
|
18
|
+
along with snarkJS. If not, see <https://www.gnu.org/licenses/>.
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
pragma solidity >=0.7.0 <0.9.0;
|
|
22
|
+
|
|
23
|
+
contract Verifier_Anon {
|
|
24
|
+
// Scalar field size
|
|
25
|
+
uint256 constant r = 21888242871839275222246405745257275088548364400416034343698204186575808495617;
|
|
26
|
+
// Base field size
|
|
27
|
+
uint256 constant q = 21888242871839275222246405745257275088696311157297823662689037894645226208583;
|
|
28
|
+
|
|
29
|
+
// Verification Key data
|
|
30
|
+
uint256 constant alphax = 20491192805390485299153009773594534940189261866228447918068658471970481763042;
|
|
31
|
+
uint256 constant alphay = 9383485363053290200918347156157836566562967994039712273449902621266178545958;
|
|
32
|
+
uint256 constant betax1 = 4252822878758300859123897981450591353533073413197771768651442665752259397132;
|
|
33
|
+
uint256 constant betax2 = 6375614351688725206403948262868962793625744043794305715222011528459656738731;
|
|
34
|
+
uint256 constant betay1 = 21847035105528745403288232691147584728191162732299865338377159692350059136679;
|
|
35
|
+
uint256 constant betay2 = 10505242626370262277552901082094356697409835680220590971873171140371331206856;
|
|
36
|
+
uint256 constant gammax1 = 11559732032986387107991004021392285783925812861821192530917403151452391805634;
|
|
37
|
+
uint256 constant gammax2 = 10857046999023057135944570762232829481370756359578518086990519993285655852781;
|
|
38
|
+
uint256 constant gammay1 = 4082367875863433681332203403145435568316851327593401208105741076214120093531;
|
|
39
|
+
uint256 constant gammay2 = 8495653923123431417604973247489272438418190587263600148770280649306958101930;
|
|
40
|
+
uint256 constant deltax1 = 11559732032986387107991004021392285783925812861821192530917403151452391805634;
|
|
41
|
+
uint256 constant deltax2 = 10857046999023057135944570762232829481370756359578518086990519993285655852781;
|
|
42
|
+
uint256 constant deltay1 = 4082367875863433681332203403145435568316851327593401208105741076214120093531;
|
|
43
|
+
uint256 constant deltay2 = 8495653923123431417604973247489272438418190587263600148770280649306958101930;
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
uint256 constant IC0x = 9951854304440957729970048255417847267132931648166621883720076413912489896527;
|
|
47
|
+
uint256 constant IC0y = 14409176055818543230693338142067842611649413262894612537199808888445023112373;
|
|
48
|
+
|
|
49
|
+
uint256 constant IC1x = 5259573331603891045109512098668147509749008117612868524737824308087424702574;
|
|
50
|
+
uint256 constant IC1y = 19525471913445311889626897591512951562906439006910912392554279452294201846276;
|
|
51
|
+
|
|
52
|
+
uint256 constant IC2x = 11117692645622336630958982687810991395188114569363058873106896045606988623896;
|
|
53
|
+
uint256 constant IC2y = 14276217142757598463675207289976891700417433194631189996761010950688853664150;
|
|
54
|
+
|
|
55
|
+
uint256 constant IC3x = 3527562448445671453901857866044085741707077263419661700847282228715451090636;
|
|
56
|
+
uint256 constant IC3y = 7570409468150382685653626446363808187419423223162341311148036786121924318272;
|
|
57
|
+
|
|
58
|
+
uint256 constant IC4x = 10841264388322700588655341388056493072376766887069865783096807172059689381322;
|
|
59
|
+
uint256 constant IC4y = 14972730259646309083115284299844029307953343465611976912389044052401119428032;
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
// Memory data
|
|
63
|
+
uint16 constant pVk = 0;
|
|
64
|
+
uint16 constant pPairing = 128;
|
|
65
|
+
|
|
66
|
+
uint16 constant pLastMem = 896;
|
|
67
|
+
|
|
68
|
+
function verifyProof(uint[2] calldata _pA, uint[2][2] calldata _pB, uint[2] calldata _pC, uint[4] calldata _pubSignals) public view returns (bool) {
|
|
69
|
+
assembly {
|
|
70
|
+
function checkField(v) {
|
|
71
|
+
if iszero(lt(v, r)) {
|
|
72
|
+
mstore(0, 0)
|
|
73
|
+
return(0, 0x20)
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
// G1 function to multiply a G1 value(x,y) to value in an address
|
|
78
|
+
function g1_mulAccC(pR, x, y, s) {
|
|
79
|
+
let success
|
|
80
|
+
let mIn := mload(0x40)
|
|
81
|
+
mstore(mIn, x)
|
|
82
|
+
mstore(add(mIn, 32), y)
|
|
83
|
+
mstore(add(mIn, 64), s)
|
|
84
|
+
|
|
85
|
+
success := staticcall(sub(gas(), 2000), 7, mIn, 96, mIn, 64)
|
|
86
|
+
|
|
87
|
+
if iszero(success) {
|
|
88
|
+
mstore(0, 0)
|
|
89
|
+
return(0, 0x20)
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
mstore(add(mIn, 64), mload(pR))
|
|
93
|
+
mstore(add(mIn, 96), mload(add(pR, 32)))
|
|
94
|
+
|
|
95
|
+
success := staticcall(sub(gas(), 2000), 6, mIn, 128, pR, 64)
|
|
96
|
+
|
|
97
|
+
if iszero(success) {
|
|
98
|
+
mstore(0, 0)
|
|
99
|
+
return(0, 0x20)
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
function checkPairing(pA, pB, pC, pubSignals, pMem) -> isOk {
|
|
104
|
+
let _pPairing := add(pMem, pPairing)
|
|
105
|
+
let _pVk := add(pMem, pVk)
|
|
106
|
+
|
|
107
|
+
mstore(_pVk, IC0x)
|
|
108
|
+
mstore(add(_pVk, 32), IC0y)
|
|
109
|
+
|
|
110
|
+
// Compute the linear combination vk_x
|
|
111
|
+
|
|
112
|
+
g1_mulAccC(_pVk, IC1x, IC1y, calldataload(add(pubSignals, 0)))
|
|
113
|
+
|
|
114
|
+
g1_mulAccC(_pVk, IC2x, IC2y, calldataload(add(pubSignals, 32)))
|
|
115
|
+
|
|
116
|
+
g1_mulAccC(_pVk, IC3x, IC3y, calldataload(add(pubSignals, 64)))
|
|
117
|
+
|
|
118
|
+
g1_mulAccC(_pVk, IC4x, IC4y, calldataload(add(pubSignals, 96)))
|
|
119
|
+
|
|
120
|
+
|
|
121
|
+
// -A
|
|
122
|
+
mstore(_pPairing, calldataload(pA))
|
|
123
|
+
mstore(add(_pPairing, 32), mod(sub(q, calldataload(add(pA, 32))), q))
|
|
124
|
+
|
|
125
|
+
// B
|
|
126
|
+
mstore(add(_pPairing, 64), calldataload(pB))
|
|
127
|
+
mstore(add(_pPairing, 96), calldataload(add(pB, 32)))
|
|
128
|
+
mstore(add(_pPairing, 128), calldataload(add(pB, 64)))
|
|
129
|
+
mstore(add(_pPairing, 160), calldataload(add(pB, 96)))
|
|
130
|
+
|
|
131
|
+
// alpha1
|
|
132
|
+
mstore(add(_pPairing, 192), alphax)
|
|
133
|
+
mstore(add(_pPairing, 224), alphay)
|
|
134
|
+
|
|
135
|
+
// beta2
|
|
136
|
+
mstore(add(_pPairing, 256), betax1)
|
|
137
|
+
mstore(add(_pPairing, 288), betax2)
|
|
138
|
+
mstore(add(_pPairing, 320), betay1)
|
|
139
|
+
mstore(add(_pPairing, 352), betay2)
|
|
140
|
+
|
|
141
|
+
// vk_x
|
|
142
|
+
mstore(add(_pPairing, 384), mload(add(pMem, pVk)))
|
|
143
|
+
mstore(add(_pPairing, 416), mload(add(pMem, add(pVk, 32))))
|
|
144
|
+
|
|
145
|
+
|
|
146
|
+
// gamma2
|
|
147
|
+
mstore(add(_pPairing, 448), gammax1)
|
|
148
|
+
mstore(add(_pPairing, 480), gammax2)
|
|
149
|
+
mstore(add(_pPairing, 512), gammay1)
|
|
150
|
+
mstore(add(_pPairing, 544), gammay2)
|
|
151
|
+
|
|
152
|
+
// C
|
|
153
|
+
mstore(add(_pPairing, 576), calldataload(pC))
|
|
154
|
+
mstore(add(_pPairing, 608), calldataload(add(pC, 32)))
|
|
155
|
+
|
|
156
|
+
// delta2
|
|
157
|
+
mstore(add(_pPairing, 640), deltax1)
|
|
158
|
+
mstore(add(_pPairing, 672), deltax2)
|
|
159
|
+
mstore(add(_pPairing, 704), deltay1)
|
|
160
|
+
mstore(add(_pPairing, 736), deltay2)
|
|
161
|
+
|
|
162
|
+
|
|
163
|
+
let success := staticcall(sub(gas(), 2000), 8, _pPairing, 768, _pPairing, 0x20)
|
|
164
|
+
|
|
165
|
+
isOk := and(success, mload(_pPairing))
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
let pMem := mload(0x40)
|
|
169
|
+
mstore(0x40, add(pMem, pLastMem))
|
|
170
|
+
|
|
171
|
+
// Validate that all evaluations ∈ F
|
|
172
|
+
|
|
173
|
+
checkField(calldataload(add(_pubSignals, 0)))
|
|
174
|
+
|
|
175
|
+
checkField(calldataload(add(_pubSignals, 32)))
|
|
176
|
+
|
|
177
|
+
checkField(calldataload(add(_pubSignals, 64)))
|
|
178
|
+
|
|
179
|
+
checkField(calldataload(add(_pubSignals, 96)))
|
|
180
|
+
|
|
181
|
+
|
|
182
|
+
// Validate all evaluations
|
|
183
|
+
let isValid := checkPairing(_pA, _pB, _pC, _pubSignals, pMem)
|
|
184
|
+
|
|
185
|
+
mstore(0, isValid)
|
|
186
|
+
return(0, 0x20)
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
}
|