Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplify factory's deploy method #49

Merged
merged 5 commits into from
Sep 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 53 additions & 16 deletions solidity/contracts/factory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -20,54 +20,91 @@ import {IZetoFungibleInitializable} from "./lib/interfaces/zeto_fungible_initial
import {IZetoNonFungibleInitializable} from "./lib/interfaces/zeto_nf_initializable.sol";

contract ZetoTokenFactory {
// all the addresses needed by the factory to
// clone a Zeto token and initialize it. The
// "implementation" is used to clone the token,
// the rest of the addresses are used to initialize
struct ImplementationInfo {
address implementation;
address depositVerifier;
address withdrawVerifier;
address verifier;
EnriqueL8 marked this conversation as resolved.
Show resolved Hide resolved
}

event ZetoTokenDeployed(address indexed zetoToken);

mapping(string => address) internal implementations;
mapping(string => ImplementationInfo) internal implementations;

constructor() {}

function registerImplementation(
string memory name,
EnriqueL8 marked this conversation as resolved.
Show resolved Hide resolved
address implementation
ImplementationInfo memory implementation
) public {
require(
implementation.implementation != address(0),
"Factory: implementation address is required"
);
require(
implementation.verifier != address(0),
"Factory: verifier address is required"
);
// the depositVerifier and withdrawVerifier are optional
// for the non-fungible token implementations
implementations[name] = implementation;
}

function deployZetoFungibleToken(
string memory name,
address initialOwner,
address _depositVerifier,
address _withdrawVerifier,
address _verifier
address initialOwner
) public returns (address) {
address instance = Clones.clone(implementations[name]);
ImplementationInfo memory args = implementations[name];
require(
instance != address(0),
args.implementation != address(0),
"Factory: failed to find implementation"
);
// check that the registered implementation is for a fungible token
// and has the required verifier addresses
require(
args.depositVerifier != address(0),
"Factory: depositVerifier address is required"
);
require(
args.withdrawVerifier != address(0),
"Factory: withdrawVerifier address is required"
);
address instance = Clones.clone(args.implementation);
require(
instance != address(0),
"Factory: failed to clone implementation"
);
(IZetoFungibleInitializable(instance)).initialize(
initialOwner,
_depositVerifier,
_withdrawVerifier,
_verifier
args.verifier,
args.depositVerifier,
args.withdrawVerifier
);
emit ZetoTokenDeployed(instance);
return instance;
}

function deployZetoNonFungibleToken(
string memory name,
address initialOwner,
address _verifier
address initialOwner
) public returns (address) {
address instance = Clones.clone(implementations[name]);
ImplementationInfo memory args = implementations[name];
require(
instance != address(0),
args.implementation != address(0),
"Factory: failed to find implementation"
);
address instance = Clones.clone(args.implementation);
require(
instance != address(0),
"Factory: failed to clone implementation"
);
(IZetoNonFungibleInitializable(instance)).initialize(
initialOwner,
_verifier
args.verifier
EnriqueL8 marked this conversation as resolved.
Show resolved Hide resolved
);
emit ZetoTokenDeployed(instance);
return instance;
Expand Down
2 changes: 1 addition & 1 deletion solidity/contracts/lib/verifier_anon.sol
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ contract Groth16Verifier_Anon {
function verifyProof(uint[2] calldata _pA, uint[2][2] calldata _pB, uint[2] calldata _pC, uint[4] calldata _pubSignals) public view returns (bool) {
assembly {
function checkField(v) {
if iszero(lt(v, q)) {
if iszero(lt(v, r)) {
EnriqueL8 marked this conversation as resolved.
Show resolved Hide resolved
mstore(0, 0)
return(0, 0x20)
}
Expand Down
2 changes: 1 addition & 1 deletion solidity/contracts/lib/verifier_anon_enc.sol
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ contract Groth16Verifier_AnonEnc {
function verifyProof(uint[2] calldata _pA, uint[2][2] calldata _pB, uint[2] calldata _pC, uint[9] calldata _pubSignals) public view returns (bool) {
assembly {
function checkField(v) {
if iszero(lt(v, q)) {
if iszero(lt(v, r)) {
mstore(0, 0)
return(0, 0x20)
}
Expand Down
2 changes: 1 addition & 1 deletion solidity/contracts/lib/verifier_anon_enc_nullifier.sol
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ contract Groth16Verifier_AnonEncNullifier {
function verifyProof(uint[2] calldata _pA, uint[2][2] calldata _pB, uint[2] calldata _pC, uint[12] calldata _pubSignals) public view returns (bool) {
assembly {
function checkField(v) {
if iszero(lt(v, q)) {
if iszero(lt(v, r)) {
mstore(0, 0)
return(0, 0x20)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,65 +46,65 @@ contract Groth16Verifier_AnonEncNullifierNonRepudiation {
uint256 constant IC0x = 7150602979198858324531264522050588047187864437625863115811019715531635342988;
uint256 constant IC0y = 18679352390540645799385538354080686740567422609949222164932202910206044361948;

uint256 constant IC1x = 20546933274967030575375764341048743544324686989399521428648988679453729672574;
uint256 constant IC1y = 12508114839394924272812953998788733726366166299611685224529406794282661918326;
uint256 constant IC1x = 20223737820803182000349268235929514427158015173398419989210846794808922069321;
uint256 constant IC1y = 19667519192504952779059431068168374697689187072685801450130109271314785916816;

uint256 constant IC2x = 4824487154794987582159170214878483637081677445844342466036965508921744954935;
uint256 constant IC2y = 20012603198977770575569235401254259856586296867286368963744054141596358017087;
uint256 constant IC2x = 7218856416869576295091037655873055759382316689150166584580005310257749626402;
uint256 constant IC2y = 18250824158316410204270915259713657522920241651507178610002708235185510464683;

uint256 constant IC3x = 13085357126364845655853054082065212176091907021303910631162840784306734614619;
uint256 constant IC3y = 18804105409926626067249386718984129501631713486331558650377019201942999164026;
uint256 constant IC3x = 10439404763847100272263651164703534229485312727099492374093433329301042860786;
uint256 constant IC3y = 11622072859931810063779349289989468302907213687444913890818865119671330403457;

uint256 constant IC4x = 12528747712399663633358900443201580207926260592781923514277748953386784545366;
uint256 constant IC4y = 15321444228429619370937074885438969957292587843245489130733239123958247484861;
uint256 constant IC4x = 3552958783616921573961765146209426612549096385286630602708070235513481501531;
uint256 constant IC4y = 7983004287008394591564704928605579735201397516705121349773346875253626793464;

uint256 constant IC5x = 15170475719758944115055889107023002588735327166378614199529086892326318914036;
uint256 constant IC5y = 8049620939170724410788843120022172935628332772087338494071162782553013962701;
uint256 constant IC5x = 7951915017279680503511105259632243418945970352099146353813397644881747832494;
uint256 constant IC5y = 15580187666685695375077645460858502959715552703766566567151236942633699459128;

uint256 constant IC6x = 663212334310334458163964230706247925833592395378902112591903654282088356896;
uint256 constant IC6y = 18754096412278896828863969347540361991262912756002947341277567135884137505700;
uint256 constant IC6x = 3810270046381397249153853319380867614609141932721597496641486068943447688518;
uint256 constant IC6y = 1789454555200419624433391404653719772125697252632300424422488567482953480839;

uint256 constant IC7x = 20346276952621247154598337223390816957539156326029095923114626385997849044836;
uint256 constant IC7y = 14162941292712917832463365746473687309497470625202464394839847050411947997730;
uint256 constant IC7x = 16582813285159387606825357695015456733307275683978941475967473789385465564139;
uint256 constant IC7y = 3370584196021878105671518949045188232217596798052799318361611555383941238644;

uint256 constant IC8x = 9248410646176563087034094961520748988428755370925933675211425461428345682132;
uint256 constant IC8y = 16296459388365501491563324106975466555396912797798729190644235870219784844785;
uint256 constant IC8x = 6410335958983016577852137704582430672625504797739898593884922605316966411317;
uint256 constant IC8y = 3561862755304133383761205380693974589872824992821334084854993222686099463287;

uint256 constant IC9x = 9083178110926851007296941420083669034008805783810176535662907367069262727367;
uint256 constant IC9y = 15272763540483910405229167164610099740544044456470363583487218543845277099600;
uint256 constant IC9x = 141988548012661067741546583487301665549799271673511121018755490875713551541;
uint256 constant IC9y = 11381489344212088827476994843766826329038542391607626896308015896573859623397;

uint256 constant IC10x = 6354539810570543825451702405001201431078418348494468217519344348456480113941;
uint256 constant IC10y = 14540363042032996638579967445622113233183047698171994701106413211929582200504;
uint256 constant IC10x = 2400404699093079437844767864727773463595132175554480756228013854499052897743;
uint256 constant IC10y = 16641639829319720713179419428727890115364728294133162095260244114066308681409;

uint256 constant IC11x = 15402490451329192726419686867507693651971698735095781620032357680507202300189;
uint256 constant IC11y = 18776825231374543966149883553033553817834994082859635640079373756431539000683;
uint256 constant IC11x = 18819343891508230813261093280482339631274788730864531524665810946260398413656;
uint256 constant IC11y = 939232547935730618247481870142928145681722172369345232371161962470473621455;

uint256 constant IC12x = 16338362324500910711458540995499662519825721035310309481766476791493413746239;
uint256 constant IC12y = 129099945110516700528901469394272124510164422816290268103236030804276978710;
uint256 constant IC12x = 19857900065761502826857489987079136225805396737807491159881256000358449239287;
uint256 constant IC12y = 14866158318731160894408347837912771366289709323081067853939131732571761322111;

uint256 constant IC13x = 11686582902269214695960711960780724175103725174284777129365136927796869647584;
uint256 constant IC13y = 16554706279775398925299029296786737540004147995537952533299814336712439852546;
uint256 constant IC13x = 654111863936885718257781142757347689010710641411633200860925542163991689666;
uint256 constant IC13y = 11276189838628957949004554103071438492770960919007402030163410690856320771850;

uint256 constant IC14x = 1391059691151041573765539336288822522255681866074476156253345556778984687459;
uint256 constant IC14y = 16704486067549765602531907643704887579736996248257686347177482380766430723027;
uint256 constant IC14x = 18969339244741250740753343010366495968956160496467373979506746525890248084164;
uint256 constant IC14y = 16274901896353030323013083904924198681645770552447391614076698136484842443636;

uint256 constant IC15x = 153683678643759940797793591527517619064774215867646038050151398326850833641;
uint256 constant IC15y = 10230454976416116340677437871207060840790045686005977662254602253013714878079;
uint256 constant IC15x = 5364945303376219658991823159374369520315533888650937587824150006805793367435;
uint256 constant IC15y = 15362324963834315062007218005904228090931585348452894617514266495515429954814;

uint256 constant IC16x = 3441020770783390721678420247863897181109537666056397599894290091843736969820;
uint256 constant IC16y = 6055734993367315995358389133634934031147209478192955140864459573136358459493;
uint256 constant IC16x = 7706652216614464307929318948621370806407028558413501412600554293234571043615;
uint256 constant IC16y = 4833155926438490231386220605163689437125897398884350656367983521056280632956;

uint256 constant IC17x = 16527482750362549411008515901030842811912583605167601846885701091727174163211;
uint256 constant IC17y = 21585460817698485257775813166157933463370089150885624438358161246914839874341;
uint256 constant IC17x = 1149166998309009330377390731594951819957167640308447230581596039029228635856;
uint256 constant IC17y = 17144496829204247748601976511350134750390256256716017203573337962163783928337;

uint256 constant IC18x = 5160955003840090131394114139067065035981538497817208563069514645767377705530;
uint256 constant IC18y = 4181642833667505155381399863468629907868977089312944758512189096196173663418;
uint256 constant IC18x = 9682269424428793097631391573982450090008352352784483866555904822950699832063;
uint256 constant IC18y = 7320838209204172545348024044818590112291242261458837363572039110259358463391;

uint256 constant IC19x = 4948442373592038976616201519852321320214615187307434803062754967096074408052;
uint256 constant IC19y = 14438208973905067256163771533917323300141311808685588768679512426522803920513;
uint256 constant IC19x = 1605487566693008705655072065911584353872368504749215742640417657776546622076;
uint256 constant IC19y = 2308043445104009725610511269022057743503782008796761536470885918528911939324;

uint256 constant IC20x = 21457772000319313553189685943142214457813393234972252846551500469611496162749;
uint256 constant IC20y = 11933932056971968632710667592027741826157658464631123816752425793753877842729;
uint256 constant IC20x = 2240609051444145211347356467283693175838292400028588894056540660459977622330;
uint256 constant IC20y = 1655940193015866774646205663901575824326740364428355076410141345515995005827;

uint256 constant IC21x = 4853016079991973626530212093282440895734792373602971804488540915961627345640;
uint256 constant IC21y = 7414374958276543278011110955360778512607526840415566794056500103235098338046;
Expand Down Expand Up @@ -146,7 +146,7 @@ contract Groth16Verifier_AnonEncNullifierNonRepudiation {
function verifyProof(uint[2] calldata _pA, uint[2][2] calldata _pB, uint[2] calldata _pC, uint[30] calldata _pubSignals) public view returns (bool) {
assembly {
function checkField(v) {
if iszero(lt(v, q)) {
if iszero(lt(v, r)) {
mstore(0, 0)
return(0, 0x20)
}
Expand Down
2 changes: 1 addition & 1 deletion solidity/contracts/lib/verifier_anon_nullifier.sol
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ contract Groth16Verifier_AnonNullifier {
function verifyProof(uint[2] calldata _pA, uint[2][2] calldata _pB, uint[2] calldata _pC, uint[7] calldata _pubSignals) public view returns (bool) {
assembly {
function checkField(v) {
if iszero(lt(v, q)) {
if iszero(lt(v, r)) {
mstore(0, 0)
return(0, 0x20)
}
Expand Down
2 changes: 1 addition & 1 deletion solidity/contracts/lib/verifier_anon_nullifier_kyc.sol
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ contract Groth16Verifier_AnonNullifierKyc {
function verifyProof(uint[2] calldata _pA, uint[2][2] calldata _pB, uint[2] calldata _pC, uint[8] calldata _pubSignals) public view returns (bool) {
assembly {
function checkField(v) {
if iszero(lt(v, q)) {
if iszero(lt(v, r)) {
mstore(0, 0)
return(0, 0x20)
}
Expand Down
2 changes: 1 addition & 1 deletion solidity/contracts/lib/verifier_check_hashes_value.sol
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ contract Groth16Verifier_CheckHashesValue {
function verifyProof(uint[2] calldata _pA, uint[2][2] calldata _pB, uint[2] calldata _pC, uint[2] calldata _pubSignals) public view returns (bool) {
assembly {
function checkField(v) {
if iszero(lt(v, q)) {
if iszero(lt(v, r)) {
mstore(0, 0)
return(0, 0x20)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ contract Groth16Verifier_CheckInputsOutputsValue {
function verifyProof(uint[2] calldata _pA, uint[2][2] calldata _pB, uint[2] calldata _pC, uint[4] calldata _pubSignals) public view returns (bool) {
assembly {
function checkField(v) {
if iszero(lt(v, q)) {
if iszero(lt(v, r)) {
mstore(0, 0)
return(0, 0x20)
}
Expand Down
2 changes: 1 addition & 1 deletion solidity/contracts/lib/verifier_check_nullifier_value.sol
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ contract Groth16Verifier_CheckNullifierValue {
function verifyProof(uint[2] calldata _pA, uint[2][2] calldata _pB, uint[2] calldata _pC, uint[7] calldata _pubSignals) public view returns (bool) {
assembly {
function checkField(v) {
if iszero(lt(v, q)) {
if iszero(lt(v, r)) {
mstore(0, 0)
return(0, 0x20)
}
Expand Down
2 changes: 1 addition & 1 deletion solidity/contracts/lib/verifier_nf_anon.sol
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ contract Groth16Verifier_NfAnon {
function verifyProof(uint[2] calldata _pA, uint[2][2] calldata _pB, uint[2] calldata _pC, uint[2] calldata _pubSignals) public view returns (bool) {
assembly {
function checkField(v) {
if iszero(lt(v, q)) {
if iszero(lt(v, r)) {
mstore(0, 0)
return(0, 0x20)
}
Expand Down
2 changes: 1 addition & 1 deletion solidity/contracts/lib/verifier_nf_anon_nullifier.sol
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ contract Groth16Verifier_NfAnonNullifier {
function verifyProof(uint[2] calldata _pA, uint[2][2] calldata _pB, uint[2] calldata _pC, uint[3] calldata _pubSignals) public view returns (bool) {
assembly {
function checkField(v) {
if iszero(lt(v, q)) {
if iszero(lt(v, r)) {
mstore(0, 0)
return(0, 0x20)
}
Expand Down
4 changes: 2 additions & 2 deletions solidity/contracts/zeto_anon.sol
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ contract Zeto_Anon is ZetoBase, ZetoFungibleWithdraw, UUPSUpgradeable {

function initialize(
address initialOwner,
Groth16Verifier_Anon _verifier,
Groth16Verifier_CheckHashesValue _depositVerifier,
Groth16Verifier_CheckInputsOutputsValue _withdrawVerifier,
Groth16Verifier_Anon _verifier
Groth16Verifier_CheckInputsOutputsValue _withdrawVerifier
) public initializer {
__ZetoBase_init(initialOwner);
__ZetoFungibleWithdraw_init(_depositVerifier, _withdrawVerifier);
Expand Down
4 changes: 2 additions & 2 deletions solidity/contracts/zeto_anon_enc.sol
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ contract Zeto_AnonEnc is ZetoBase, ZetoFungibleWithdraw, UUPSUpgradeable {

function initialize(
address initialOwner,
Groth16Verifier_AnonEnc _verifier,
Groth16Verifier_CheckHashesValue _depositVerifier,
Groth16Verifier_CheckInputsOutputsValue _withdrawVerifier,
Groth16Verifier_AnonEnc _verifier
Groth16Verifier_CheckInputsOutputsValue _withdrawVerifier
) public initializer {
__ZetoBase_init(initialOwner);
__ZetoFungibleWithdraw_init(_depositVerifier, _withdrawVerifier);
Expand Down
4 changes: 2 additions & 2 deletions solidity/contracts/zeto_anon_enc_nullifier.sol
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ contract Zeto_AnonEncNullifier is

function initialize(
address initialOwner,
Groth16Verifier_AnonEncNullifier _verifier,
Groth16Verifier_CheckHashesValue _depositVerifier,
Groth16Verifier_CheckNullifierValue _withdrawVerifier,
Groth16Verifier_AnonEncNullifier _verifier
Groth16Verifier_CheckNullifierValue _withdrawVerifier
) public initializer {
__ZetoNullifier_init(initialOwner);
__ZetoFungibleWithdrawWithNullifiers_init(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,9 @@ contract Zeto_AnonEncNullifierNonRepudiation is

function initialize(
address initialOwner,
Groth16Verifier_AnonEncNullifierNonRepudiation _verifier,
Groth16Verifier_CheckHashesValue _depositVerifier,
Groth16Verifier_CheckNullifierValue _withdrawVerifier,
Groth16Verifier_AnonEncNullifierNonRepudiation _verifier
Groth16Verifier_CheckNullifierValue _withdrawVerifier
) public initializer {
__ZetoNullifier_init(initialOwner);
__ZetoFungibleWithdrawWithNullifiers_init(
Expand Down
Loading
Loading