diff --git a/src/circuit-wrapper.ts b/src/circuit-wrapper.ts index 96da242f..52f5ae6b 100644 --- a/src/circuit-wrapper.ts +++ b/src/circuit-wrapper.ts @@ -75,6 +75,10 @@ export class RLNProver { x: bigint; epoch: bigint; }): Promise { + if (args.x <= BigInt(0)) { + // y = identitySecret + a1 * x + throw new Error('identity secret is directly leaked if x = 0') + } const witness: RLNWitness = { identitySecret: args.identitySecret, userMessageLimit: args.userMessageLimit, diff --git a/src/contract-wrapper.ts b/src/contract-wrapper.ts index 48934f30..aee05ca9 100644 --- a/src/contract-wrapper.ts +++ b/src/contract-wrapper.ts @@ -90,10 +90,6 @@ export class RLNContract { return this.signer || this.provider } - async getTokenAddress() { - return this.rlnContract.token() - } - async getSignerAddress() { if (this.signer === undefined) { throw new Error('Cannot get signer address if signer is not set') @@ -101,6 +97,30 @@ export class RLNContract { return this.signer.getAddress() } + async getMinimalDeposit() { + return this.rlnContract.MINIMAL_DEPOSIT() + } + + async getMaximalRate() { + return this.rlnContract.MAXIMAL_RATE() + } + + async getFeeReceiver() { + return this.rlnContract.FEE_RECEIVER() + } + + async getFeePercentage() { + return this.rlnContract.FEE_PERCENTAGE() + } + + async getFreezePeriod() { + return this.rlnContract.FREEZE_PERIOD() + } + + async getTokenAddress() { + return this.rlnContract.token() + } + async getLogs() { const rlnContractAddress = await this.rlnContract.getAddress() const currentBlockNumber = await this.provider.getBlockNumber() @@ -160,8 +180,11 @@ export class RLNContract { erc20ABI, this.getContractRunner(), ) - const txApprove = await tokenContract.approve(rlnContractAddress, amount) - await txApprove.wait() + const allowance = await tokenContract.allowance(await this.getSignerAddress(), rlnContractAddress) + if (allowance < amount) { + const txApprove = await tokenContract.approve(rlnContractAddress, amount) + await txApprove.wait() + } const txRegister = await this.rlnContract.register(identityCommitment, amount) const receipt = await txRegister.wait() return receipt diff --git a/src/registry.ts b/src/registry.ts index 71e9feea..2c253cfe 100644 --- a/src/registry.ts +++ b/src/registry.ts @@ -137,6 +137,9 @@ export class ContractRLNRegistry implements IRLNRegistry { identitySecret, address: userAddressBigInt, }) + if (identityCommitment != BigInt(proof.publicSignals[0]) || userAddressBigInt != BigInt(proof.publicSignals[1])) { + throw new Error('Withdraw proof public signals do not match') + } await this.rlnContract.withdraw(identityCommitment, proof.proof) } @@ -163,6 +166,9 @@ export class ContractRLNRegistry implements IRLNRegistry { identitySecret, address: receiverBigInt, }) + if (identityCommitment != BigInt(proof.publicSignals[0]) || receiverBigInt != BigInt(proof.publicSignals[1])) { + throw new Error('Withdraw proof public signals do not match') + } await this.rlnContract.slash(identityCommitment, receiver, proof.proof) } }