forked from Rate-Limiting-Nullifier/rlnjs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfigs.ts
43 lines (36 loc) · 20.6 KB
/
configs.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import * as fs from "fs"
import * as path from "path"
import { VerificationKey } from "../src/types"
const thisFileDirname = __dirname
function parseVerificationKeyJSON(json: string): VerificationKey {
const o = JSON.parse(json)
// NOTE: This is not a complete check, to do better we can check values are of the correct type
if (!o.protocol) throw new Error('Verification key has no protocol')
if (!o.curve) throw new Error('Verification key has no curve')
if (!o.nPublic) throw new Error('Verification key has no nPublic')
if (!o.vk_alpha_1) throw new Error('Verification key has no vk_alpha_1')
if (!o.vk_beta_2) throw new Error('Verification key has no vk_beta_2')
if (!o.vk_gamma_2) throw new Error('Verification key has no vk_gamma_2')
if (!o.vk_delta_2) throw new Error('Verification key has no vk_delta_2')
if (!o.vk_alphabeta_12) throw new Error('Verification key has no vk_alphabeta_12')
if (!o.IC) throw new Error('Verification key has no IC')
return o
}
function getParamsPath(paramsDir: string) {
const verificationKeyPath = path.join(paramsDir, "verification_key.json")
return {
wasmFilePath: path.join(paramsDir, "circuit.wasm"),
finalZkeyPath: path.join(paramsDir, "final.zkey"),
verificationKey: parseVerificationKeyJSON(fs.readFileSync(verificationKeyPath, "utf-8")),
}
}
export const rlnParams = getParamsPath(
path.join(thisFileDirname, "..", "zkeyFiles", "rln")
)
export const withdrawParams = getParamsPath(
path.join(thisFileDirname, "..", "zkeyFiles", "withdraw")
)
// Ref: https://github.com/Rate-Limiting-Nullifier/rln-contracts/blob/b31e47faf014ba0d47e684220568ef4b6cc389fd/src/RLN.sol#L10
export const rlnContractBytecode = "0x6101806040523480156200001257600080fd5b50604051620017bc380380620017bc833981016040819052620000359162000117565b6001600160a01b038416620000b65760405162461bcd60e51b815260206004820152603460248201527f524c4e2c20636f6e7374727563746f723a20666565207265636569766572206360448201527f616e6e6f74206265203078302061646472657373000000000000000000000000606482015260840160405180910390fd5b60809790975260a095909552600190931b60c05260ff909116610100526001600160a01b0390811660e05261012091909152908116610140521661016052620001a2565b80516001600160a01b03811681146200011257600080fd5b919050565b600080600080600080600080610100898b0312156200013557600080fd5b885197506020890151965060408901519550606089015160ff811681146200015c57600080fd5b94506200016c60808a01620000fa565b935060a089015192506200018360c08a01620000fa565b91506200019360e08a01620000fa565b90509295985092959890939650565b60805160a05160c05160e0516101005161012051610140516101605161154c62000270600039600081816101710152610ea101526000818161035d015281816104e901528181610798015281816107cc0152610b480152600081816102a6015261041b01526000818160fe015261074f01526000818161031001526107ee0152600081816102e901526108650152600081816101b00152610aa701526000818161013c0152818161071c015281816108d40152818161096301528181610a7e0152610d6d015261154c6000f3fe608060405234801561001057600080fd5b50600436106100f45760003560e01c8063823c82ca11610097578063d3e78e4d11610066578063d3e78e4d1461030b578063d66d6c1014610332578063eb15f67514610345578063fc0c546a1461035857600080fd5b8063823c82ca146102a15780638be9b119146102c85780639cf502fe146102db578063d0383d68146102e457600080fd5b80632bf7a65d116100d35780632bf7a65d146101ab57806337bdc99b146101d25780635cc07076146101e75780635daf08ca1461024257600080fd5b80620b46f8146100f95780631810847c146101375780632b7ac3f31461016c575b600080fd5b6101207f000000000000000000000000000000000000000000000000000000000000000081565b60405160ff90911681526020015b60405180910390f35b61015e7f000000000000000000000000000000000000000000000000000000000000000081565b60405190815260200161012e565b6101937f000000000000000000000000000000000000000000000000000000000000000081565b6040516001600160a01b03909116815260200161012e565b61015e7f000000000000000000000000000000000000000000000000000000000000000081565b6101e56101e036600461126b565b61037f565b005b61021e6101f536600461126b565b60026020819052600091825260409091208054600182015491909201546001600160a01b031683565b6040805193845260208401929092526001600160a01b03169082015260600161012e565b61027c61025036600461126b565b60016020819052600091825260409091208054918101546002909101546001600160a01b039092169183565b604080516001600160a01b03909416845260208401929092529082015260600161012e565b61015e7f000000000000000000000000000000000000000000000000000000000000000081565b6101e56102d636600461129c565b61051b565b61015e60005481565b61015e7f000000000000000000000000000000000000000000000000000000000000000081565b6101937f000000000000000000000000000000000000000000000000000000000000000081565b6101e56103403660046112e8565b610860565b6101e561035336600461130a565b610c10565b6101937f000000000000000000000000000000000000000000000000000000000000000081565b6000818152600260208181526040808420815160608101835281548082526001830154948201949094529301546001600160a01b0316908301529091036104175760405162461bcd60e51b815260206004820152602160248201527f524c4e2c2072656c656173653a206e6f2073756368207769746864726177616c6044820152607360f81b60648201526084015b60405180910390fd5b80517f000000000000000000000000000000000000000000000000000000000000000090610445904361134e565b116104925760405162461bcd60e51b815260206004820181905260248201527f524c4e2c2072656c656173653a2063616e6e6f742072656c6561736520796574604482015260640161040e565b6000828152600260208181526040808420848155600180820186905590840180546001600160a01b0319908116909155818452828620805490911681559081018590559092019290925582015190820151610517917f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031691610e35565b5050565b6001600160a01b03821661057c5760405162461bcd60e51b815260206004820152602260248201527f524c4e2c20736c6173683a20656d707479207265636569766572206164647265604482015261737360f01b606482015260840161040e565b600083815260016020818152604092839020835160608101855281546001600160a01b0316808252938201549281019290925260020154928101929092526106065760405162461bcd60e51b815260206004820181905260248201527f524c4e2c20736c6173683a206d656d62657220646f65736e2774206578697374604482015260640161040e565b80516001600160a01b038085169116036106725760405162461bcd60e51b815260206004820152602760248201527f524c4e2c20736c6173683a2073656c662d736c617368696e672069732070726f6044820152661a1a589a5d195960ca1b606482015260840161040e565b61067d848484610e9d565b6106c95760405162461bcd60e51b815260206004820152601960248201527f524c4e2c20736c6173683a20696e76616c69642070726f6f6600000000000000604482015260640161040e565b600084815260016020818152604080842080546001600160a01b031990811682558185018690556002918201869055818452918520858155938401859055929092018054909216909155820151610741907f000000000000000000000000000000000000000000000000000000000000000090611361565b9050600060646107748360ff7f000000000000000000000000000000000000000000000000000000000000000016611361565b61077e919061138e565b90506107bf8561078e838561134e565b6001600160a01b037f0000000000000000000000000000000000000000000000000000000000000000169190610e35565b6108136001600160a01b037f0000000000000000000000000000000000000000000000000000000000000000167f000000000000000000000000000000000000000000000000000000000000000083610e35565b60408084015181519081526001600160a01b03871660208201527f707cd9719d0c14265b9e456f7add99095401f907e570e5cdd65a92920947c450910160405180910390a1505050505050565b6000547f000000000000000000000000000000000000000000000000000000000000000081106108d25760405162461bcd60e51b815260206004820152601a60248201527f524c4e2c2072656769737465723a207365742069732066756c6c000000000000604482015260640161040e565b7f000000000000000000000000000000000000000000000000000000000000000082101561095e5760405162461bcd60e51b815260206004820152603360248201527f524c4e2c2072656769737465723a20616d6f756e74206973206c6f77657220746044820152721a185b881b5a5b9a5b585b0819195c1bdcda5d606a1b606482015260840161040e565b6109887f0000000000000000000000000000000000000000000000000000000000000000836113a2565b156109fb5760405162461bcd60e51b815260206004820152603d60248201527f524c4e2c2072656769737465723a20616d6f756e742073686f756c642062652060448201527f61206d756c7469706c65206f66206d696e696d616c206465706f736974000000606482015260840161040e565b6000838152600160205260409020546001600160a01b031615610a775760405162461bcd60e51b815260206004820152602e60248201527f524c4e2c2072656769737465723a206964436f6d6d69746d656e7420616c726560448201526d18591e481c9959da5cdd195c995960921b606482015260840161040e565b6000610aa37f00000000000000000000000000000000000000000000000000000000000000008461138e565b90507f0000000000000000000000000000000000000000000000000000000000000000811115610b3b5760405162461bcd60e51b815260206004820152603d60248201527f524c4e2c2072656769737465723a206d657373616765206c696d69742063616e60448201527f6e6f74206265206d6f7265207468616e204d4158494d414c5f52415445000000606482015260840161040e565b610b706001600160a01b037f000000000000000000000000000000000000000000000000000000000000000016333086611038565b6040805160608082018352338252602080830185815283850187815260008a8152600180855290879020955186546001600160a01b0319166001600160a01b039091161786559151918501919091555160029093019290925582518781529182018490529181018490527fff42916a89d1f5125f7f47168ee59c2b3fc9246ad1b229082ee85b69d001b5d7910160405180910390a1506001016000555050565b600082815260016020818152604092839020835160608101855281546001600160a01b031680825293820154928101929092526002015492810192909252610ca65760405162461bcd60e51b815260206004820152602360248201527f524c4e2c2077697468647261773a206d656d62657220646f65736e27742065786044820152621a5cdd60ea1b606482015260840161040e565b60008381526002602052604090205415610d0e5760405162461bcd60e51b8152602060048201526024808201527f524c4e2c2072656c656173653a2073756368207769746864726177616c2065786044820152636973747360e01b606482015260840161040e565b610d1d83826000015184610e9d565b610d695760405162461bcd60e51b815260206004820152601c60248201527f524c4e2c2077697468647261773a20696e76616c69642070726f6f6600000000604482015260640161040e565b60007f00000000000000000000000000000000000000000000000000000000000000008260200151610d9b9190611361565b60408051606081018252438152602080820184815286516001600160a01b0390811684860190815260008b81526002808652908790209551865592516001860155519390910180546001600160a01b03191693909116929092179091558482015191519182529192507fad2d771c5ad1c1e6f50cc769e53ec1e194002c29f28c3dd2af5639b60d8072a6910160405180910390a150505050565b6040516001600160a01b038316602482015260448101829052610e9890849063a9059cbb60e01b906064015b60408051601f198184030181529190526020810180516001600160e01b03166001600160e01b031990931692909217909152611076565b505050565b60007f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031663f5c9d69e604051806040016040528085600060088110610eec57610eec6113b6565b6020020135815260200185600160088110610f0957610f096113b6565b6020020135905260408051608081018252868201359181019182529081906060820188600360200201358152508152602001604051806040016040528088600460088110610f5957610f596113b6565b6020020135815260200188600560088110610f7657610f766113b6565b60200201359052905260408051808201909152808760066020020135815260200187600760088110610faa57610faa6113b6565b602002013581525060405180604001604052808a8152602001896001600160a01b03168152506040518563ffffffff1660e01b8152600401610fef94939291906113ef565b602060405180830381865afa15801561100c573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611030919061147a565b949350505050565b6040516001600160a01b03808516602483015283166044820152606481018290526110709085906323b872dd60e01b90608401610e61565b50505050565b60006110cb826040518060400160405280602081526020017f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c6564815250856001600160a01b03166111489092919063ffffffff16565b805190915015610e9857808060200190518101906110e9919061147a565b610e985760405162461bcd60e51b815260206004820152602a60248201527f5361666545524332303a204552433230206f7065726174696f6e20646964206e6044820152691bdd081cdd58d8d9595960b21b606482015260840161040e565b6060611030848460008585600080866001600160a01b0316858760405161116f91906114c7565b60006040518083038185875af1925050503d80600081146111ac576040519150601f19603f3d011682016040523d82523d6000602084013e6111b1565b606091505b50915091506111c2878383876111cd565b979650505050505050565b6060831561123c578251600003611235576001600160a01b0385163b6112355760405162461bcd60e51b815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e7472616374000000604482015260640161040e565b5081611030565b61103083838151156112515781518083602001fd5b8060405162461bcd60e51b815260040161040e91906114e3565b60006020828403121561127d57600080fd5b5035919050565b80610100810183101561129657600080fd5b92915050565b600080600061014084860312156112b257600080fd5b8335925060208401356001600160a01b03811681146112d057600080fd5b91506112df8560408601611284565b90509250925092565b600080604083850312156112fb57600080fd5b50508035926020909101359150565b600080610120838503121561131e57600080fd5b8235915061132f8460208501611284565b90509250929050565b634e487b7160e01b600052601160045260246000fd5b8181038181111561129657611296611338565b808202811582820484141761129657611296611338565b634e487b7160e01b600052601260045260246000fd5b60008261139d5761139d611378565b500490565b6000826113b1576113b1611378565b500690565b634e487b7160e01b600052603260045260246000fd5b8060005b60028110156110705781518452602093840193909101906001016113d0565b61014081016113fe82876113cc565b6040808301866000805b60028082106114175750611451565b835185845b8381101561143a57825182526020928301929091019060010161141c565b505050938501935060209290920191600101611408565b505050505061146360c08301856113cc565b6114716101008301846113cc565b95945050505050565b60006020828403121561148c57600080fd5b8151801515811461149c57600080fd5b9392505050565b60005b838110156114be5781810151838201526020016114a6565b50506000910152565b600082516114d98184602087016114a3565b9190910192915050565b60208152600082518060208401526115028160408501602087016114a3565b601f01601f1916919091016040019291505056fea264697066735822122065c2656fc05b878be4775d524cc0c3fdd902c0d2d65498d53f0126b9ea09306264736f6c63430008130033"
export const testERC20ContractBytecode = "0x60806040523480156200001157600080fd5b5060405162000b8d38038062000b8d833981016040819052620000349162000179565b6040518060400160405280600981526020016805465737445524332360bc1b815250604051806040016040528060038152602001621514d560ea1b815250816003908162000083919062000237565b50600462000092828262000237565b505050620000a73382620000ae60201b60201c565b506200032b565b6001600160a01b038216620001095760405162461bcd60e51b815260206004820152601f60248201527f45524332303a206d696e7420746f20746865207a65726f206164647265737300604482015260640160405180910390fd5b80600260008282546200011d919062000303565b90915550506001600160a01b038216600081815260208181526040808320805486019055518481527fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef910160405180910390a35050565b505050565b6000602082840312156200018c57600080fd5b5051919050565b634e487b7160e01b600052604160045260246000fd5b600181811c90821680620001be57607f821691505b602082108103620001df57634e487b7160e01b600052602260045260246000fd5b50919050565b601f8211156200017457600081815260208120601f850160051c810160208610156200020e5750805b601f850160051c820191505b818110156200022f578281556001016200021a565b505050505050565b81516001600160401b0381111562000253576200025362000193565b6200026b81620002648454620001a9565b84620001e5565b602080601f831160018114620002a357600084156200028a5750858301515b600019600386901b1c1916600185901b1785556200022f565b600085815260208120601f198616915b82811015620002d457888601518255948401946001909101908401620002b3565b5085821015620002f35787850151600019600388901b60f8161c191681555b5050505050600190811b01905550565b808201808211156200032557634e487b7160e01b600052601160045260246000fd5b92915050565b610852806200033b6000396000f3fe608060405234801561001057600080fd5b50600436106100a95760003560e01c80633950935111610071578063395093511461012357806370a082311461013657806395d89b411461015f578063a457c2d714610167578063a9059cbb1461017a578063dd62ed3e1461018d57600080fd5b806306fdde03146100ae578063095ea7b3146100cc57806318160ddd146100ef57806323b872dd14610101578063313ce56714610114575b600080fd5b6100b66101a0565b6040516100c3919061069c565b60405180910390f35b6100df6100da366004610706565b610232565b60405190151581526020016100c3565b6002545b6040519081526020016100c3565b6100df61010f366004610730565b61024c565b604051601281526020016100c3565b6100df610131366004610706565b610270565b6100f361014436600461076c565b6001600160a01b031660009081526020819052604090205490565b6100b6610292565b6100df610175366004610706565b6102a1565b6100df610188366004610706565b610321565b6100f361019b36600461078e565b61032f565b6060600380546101af906107c1565b80601f01602080910402602001604051908101604052809291908181526020018280546101db906107c1565b80156102285780601f106101fd57610100808354040283529160200191610228565b820191906000526020600020905b81548152906001019060200180831161020b57829003601f168201915b5050505050905090565b60003361024081858561035a565b60019150505b92915050565b60003361025a85828561047e565b6102658585856104f8565b506001949350505050565b600033610240818585610283838361032f565b61028d91906107fb565b61035a565b6060600480546101af906107c1565b600033816102af828661032f565b9050838110156103145760405162461bcd60e51b815260206004820152602560248201527f45524332303a2064656372656173656420616c6c6f77616e63652062656c6f77604482015264207a65726f60d81b60648201526084015b60405180910390fd5b610265828686840361035a565b6000336102408185856104f8565b6001600160a01b03918216600090815260016020908152604080832093909416825291909152205490565b6001600160a01b0383166103bc5760405162461bcd60e51b8152602060048201526024808201527f45524332303a20617070726f76652066726f6d20746865207a65726f206164646044820152637265737360e01b606482015260840161030b565b6001600160a01b03821661041d5760405162461bcd60e51b815260206004820152602260248201527f45524332303a20617070726f766520746f20746865207a65726f206164647265604482015261737360f01b606482015260840161030b565b6001600160a01b0383811660008181526001602090815260408083209487168084529482529182902085905590518481527f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925910160405180910390a3505050565b600061048a848461032f565b905060001981146104f257818110156104e55760405162461bcd60e51b815260206004820152601d60248201527f45524332303a20696e73756666696369656e7420616c6c6f77616e6365000000604482015260640161030b565b6104f2848484840361035a565b50505050565b6001600160a01b03831661055c5760405162461bcd60e51b815260206004820152602560248201527f45524332303a207472616e736665722066726f6d20746865207a65726f206164604482015264647265737360d81b606482015260840161030b565b6001600160a01b0382166105be5760405162461bcd60e51b815260206004820152602360248201527f45524332303a207472616e7366657220746f20746865207a65726f206164647260448201526265737360e81b606482015260840161030b565b6001600160a01b038316600090815260208190526040902054818110156106365760405162461bcd60e51b815260206004820152602660248201527f45524332303a207472616e7366657220616d6f756e7420657863656564732062604482015265616c616e636560d01b606482015260840161030b565b6001600160a01b03848116600081815260208181526040808320878703905593871680835291849020805487019055925185815290927fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef910160405180910390a36104f2565b600060208083528351808285015260005b818110156106c9578581018301518582016040015282016106ad565b506000604082860101526040601f19601f8301168501019250505092915050565b80356001600160a01b038116811461070157600080fd5b919050565b6000806040838503121561071957600080fd5b610722836106ea565b946020939093013593505050565b60008060006060848603121561074557600080fd5b61074e846106ea565b925061075c602085016106ea565b9150604084013590509250925092565b60006020828403121561077e57600080fd5b610787826106ea565b9392505050565b600080604083850312156107a157600080fd5b6107aa836106ea565b91506107b8602084016106ea565b90509250929050565b600181811c908216806107d557607f821691505b6020821081036107f557634e487b7160e01b600052602260045260246000fd5b50919050565b8082018082111561024657634e487b7160e01b600052601160045260246000fdfea264697066735822122054d059ee835775206d7458a862cc8d640ae1efb1e18a09dbc64742523c5c2e2964736f6c63430008130033"
export const mockVerifierBytecode = "0x608060405234801561001057600080fd5b506000805460ff1916600117905561022c8061002d6000396000f3fe608060405234801561001057600080fd5b50600436106100415760003560e01c80633f546a7b146100465780636537214714610069578063f5c9d69e1461008a575b600080fd5b6100676100543660046100a6565b6000805460ff1916911515919091179055565b005b6000546100769060ff1681565b604051901515815260200160405180910390f35b610076610098366004610156565b60005460ff16949350505050565b6000602082840312156100b857600080fd5b813580151581146100c857600080fd5b9392505050565b6040805190810167ffffffffffffffff8111828210171561010057634e487b7160e01b600052604160045260246000fd5b60405290565b600082601f83011261011757600080fd5b61011f6100cf565b80604084018581111561013157600080fd5b845b8181101561014b578035845260209384019301610133565b509095945050505050565b600080600080610140858703121561016d57600080fd5b6101778686610106565b9350604086605f87011261018a57600080fd5b6101926100cf565b8060c08801898111156101a457600080fd5b8389015b818110156101c9576101ba8b82610106565b845260209093019284016101a8565b508196506101d78a82610106565b9550505050506101eb866101008701610106565b90509295919450925056fea2646970667358221220d34849fd672045fa5d1669cae36e59adb19a0747b5ecf63a5dae9d051a32151d64736f6c63430008130033"