pragma circom 2.0.0; include "single_cell.circom"; include "poseidon2_hash.circom"; include "extract_bits.circom"; include "log2.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( maxLog2N ) { signal input entropy; signal input slotRoot; signal input counter; signal input cellIndexBitMask[maxLog2N]; // bit mask for the cell index range signal output indexBits[maxLog2N]; // calculate the hash component pos = Poseidon2_hash_rate2( 3 ); // input is 3 field elements signal hash; pos.inp[0] <== entropy; pos.inp[1] <== slotRoot; pos.inp[2] <== counter; pos.out ==> hash; // extract the lowest `maxLog2N = 32` bits component md = ExtractLowerBits(maxLog2N); md.inp <== hash; for(var i=0; i