iden3/circomlib

Num2Bits error

KimiWu123 opened this issue · 1 comments

I'd like to convert my 256 bits data to bits array by Num2Bits. This is my input

77566169416202731942676121969132614529774733997845438300974228917086841813606
// exact 256 bits length

My circom code,

template Example_Num2Bits(nBits) {
    signal input data

    component external_nullifier_bits = Num2Bits(nBits);
    external_nullifier_bits.in <== data;
}
component main = Example_Num2Bits(256)

I got this error when calculating witness,

ERROR: Error: Constraint doesn't match main.external_nullifier_bits: /home/ubuntu/zk/circomlib/circuits/bitify.circom:35:4 -> 11901440800684906275936904733360789264129640796597335269879616357359416326755 != 77566169416202731942676121969132614529774733997845438300974228917086841813606

The value converted by Num2Bits is 11901440800684906275936904733360789264129640796597335269879616357359416326755
No idea what happened.

ytrezq commented

@KimiWu123 : Beware that arithmetic is implemented on modulo p that is a 254 bits number, not 256…