fabriziogianni7
fabriziogianni7

Reputation: 416

Why Circuit (circom) can't compare timestamp?

I have this circuit where I want to compare 2 timestamp.

If I try with smaller numbers, it's working, if I try with timestamps, it does not work.

Here's the circuit (.circom)

    pragma circom 2.0.0;

include "../node_modules/circomlib/circuits/comparators.circom";
include "../node_modules/circomlib/circuits/poseidon.circom";

template drivingLicenseConstraint() {
    // public
    signal input hashData; //input: is the hash we have in the SBT. is the hash of the hash of every data poseidon.hashData
    signal input ownerAddress;
    signal input threshold; // threshold: now timestamp, current time. it should be less than expiry date

    // private
    // idToSBTData[tokenId].encryptedIssuanceDate,
    // idToSBTData[tokenId].encryptedExpiryeDate,
    // idToSBTData[tokenId].encryptedOwnerName,
    // idToSBTData[tokenId].encryptedLicenseNumber,
    // idToSBTData[tokenId].encryptedLicenseType

    signal input expiryDate;

    // true/false
    signal output out;

    // check hash to be equal to hashData
    component hash = Poseidon(2);
    hash.inputs[0] <== ownerAddress;
    hash.inputs[1] <== expiryDate;
    hashData === hash.out;

    // check driving license is not expired
    // expiryDate should be bigger than current time in order to return true
    component greaterEqThan = GreaterEqThan(8); 
    greaterEqThan.in[0] <== expiryDate;
    greaterEqThan.in[1] <== threshold;

    out <-- greaterEqThan.out;
    out === 1;
}

component main {public [hashData,ownerAddress,threshold]} = drivingLicenseConstraint();

Upvotes: 1

Views: 251

Answers (1)

fabriziogianni7
fabriziogianni7

Reputation: 416

Need to change the argument for gre: component greaterEqThan = GreaterEqThan(8); becomes

component greaterEqThan = GreaterEqThan(64);

the argument is the number of bits the input have https://github.com/iden3/circomlib/blob/cff5ab6288b55ef23602221694a6a38a0239dcc0/circuits/comparators.circom#L117C1-L127C2

Upvotes: 1

Related Questions