Skip to content

Commit

Permalink
fix: minor fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Ghadi8 committed Oct 15, 2024
1 parent 67c26c3 commit bedcadf
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 26 deletions.
4 changes: 2 additions & 2 deletions foundry.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ fs_permissions = [
runs = 256

[invariant]
runs=250
depth=128
runs=50 # keep this low on push for the github actions
depth=25 # keep this low on push for the github actions
fail_on_revert = true

# See more config options https://github.com/foundry-rs/foundry/blob/master/crates/config/README.md#all-options
Original file line number Diff line number Diff line change
Expand Up @@ -10,55 +10,58 @@ import {VerifierProveRSA65537SHA256} from "../../src/verifiers/prove/Verifier_pr

contract ProofOfPassportRegisterHandler is Test, TestCodeConstants, CodeConstants {
ProofOfPassportRegister s_register;
address[][] private registeredAddresses = new address[][](5);
address[][] private s_registeredAddresses = new address[][](5);

constructor(ProofOfPassportRegister _register) {
s_register = _register;
constructor(ProofOfPassportRegister register) {
s_register = register;
}

modifier notAlreadyRegisteredVerifier(uint256 signatureAlgorithm) {
if (signatureAlgorithm == 1 || signatureAlgorithm == 3 || signatureAlgorithm == 4) {
return;
}
_;
}

function registerProof(address recipient, uint256 signatureAlgorithmSeed) public {
if (recipient == address(0)) {
return;
}

uint256 signatureAlgorithm = _getSignatureAlgorithmBySeed(signatureAlgorithmSeed);
uint256 signatureAlgorithm = _getSignatureAlgorithmFromSeed(signatureAlgorithmSeed);

IProofOfPassportRegister.Proof memory proof = getProof(signatureAlgorithm);
uint256 nullifier = getNullifier(proof);

if (!s_register.isRegistered(nullifier, recipient)) {
s_register.registerWithProof(proof, recipient);
registeredAddresses[signatureAlgorithm].push(recipient);
s_registeredAddresses[signatureAlgorithm].push(recipient);
}
}

function setSigner(address _signer) public {
if (_signer == address(0)) {
function setSigner(address signer) public {
if (signer == address(0)) {
return;
}

address owner = s_register.owner();

vm.prank(owner);
s_register.setSigner(_signer);
s_register.setSigner(signer);
}

function removeSigner(address _signer) public {
bool isSigner = s_register.checkIfAddressIsSigner(_signer);
function removeSigner(address signer) public {
bool isSigner = s_register.checkIfAddressIsSigner(signer);

if (isSigner) {
address owner = s_register.owner();

vm.prank(owner);
s_register.removeSigner(_signer);
s_register.removeSigner(signer);
}
}

function removeVerifier(uint256 signatureAlgorithm) public {
if (signatureAlgorithm == 1 || signatureAlgorithm == 3 || signatureAlgorithm == 4) {
return;
}

function removeVerifier(uint256 signatureAlgorithm) public notAlreadyRegisteredVerifier(signatureAlgorithm) {
address verifier = s_register.getVerifier(signatureAlgorithm);

if (verifier == address(0)) {
Expand All @@ -71,11 +74,7 @@ contract ProofOfPassportRegisterHandler is Test, TestCodeConstants, CodeConstant
s_register.removeVerifier(signatureAlgorithm);
}

function setVerifier(uint256 signatureAlgorithm) public {
if (signatureAlgorithm == 1 || signatureAlgorithm == 3 || signatureAlgorithm == 4) {
return;
}

function setVerifier(uint256 signatureAlgorithm) public notAlreadyRegisteredVerifier(signatureAlgorithm) {
address owner = s_register.owner();

VerifierProveRSA65537SHA256 newVerifier = new VerifierProveRSA65537SHA256();
Expand All @@ -85,11 +84,11 @@ contract ProofOfPassportRegisterHandler is Test, TestCodeConstants, CodeConstant
}

function getRegisteredAddresses(uint256 signatureAlgorithm) public view returns (address[] memory) {
return registeredAddresses[signatureAlgorithm];
return s_registeredAddresses[signatureAlgorithm];
}

function getRegisteredAddressesCount(uint256 signatureAlgorithm) public view returns (uint256) {
return registeredAddresses[signatureAlgorithm].length;
return s_registeredAddresses[signatureAlgorithm].length;
}

function getNullifier(IProofOfPassportRegister.Proof memory proof) public view returns (uint256) {
Expand All @@ -110,7 +109,7 @@ contract ProofOfPassportRegisterHandler is Test, TestCodeConstants, CodeConstant
}
}

function _getSignatureAlgorithmBySeed(uint256 signatureAlgorithm) private pure returns (uint256) {
function _getSignatureAlgorithmFromSeed(uint256 signatureAlgorithm) private pure returns (uint256) {
if (signatureAlgorithm % 3 == 0) {
return 1;
} else if (signatureAlgorithm % 3 == 1) {
Expand Down

0 comments on commit bedcadf

Please sign in to comment.