pragma circom 2.0.0; include "single_cell.circom"; include "poseidon2_hash.circom"; include "extract_bits.circom"; include "misc.circom"; //------------------------------------------------------------------------------ // // calculate the linear index of the k-th cell we want to sample. // this version return the binary decomposition of the index // (we need that for the Merkle proof anyway, it's cheaper this way) // // the formula for this is: // // idx = H( entropy | slotRoot | counter ) `mod` nCells // // NOTE: we assume `nCells` is a power of two. // template CalculateCellIndexBits( nCells ) { var log2N = CeilLog2(nCells); assert( nCells == (1< hash; // extract the lowest `log2(nCells)` bits component md = ExtractLowerBits(log2N); md.inp <== hash; md.out ==> indexBits; } //------------------------------------------------------------------------------ // // same as above, but returns an integer index instead of its binary decomposition. // template CalculateCellIndexInteger( nCells ) { var log2N = CeilLog2(nCells); assert( nCells == (1< prove[cnt].indexBits; prove[cnt].slotRoot <== slotRoot; prove[cnt].data <== cellData[cnt]; prove[cnt].merklePath <== merklePaths[cnt]; } } //------------------------------------------------------------------------------