简体   繁体   English

如何在 Circom 中访问具有“未知”索引的数组元素?

[英]How to access array element with an "Unknown" index in Circom?

I have the following Circom (circuit compiler language) program:我有以下Circom (电路编译器语言)程序:

pragma circom 2.0.0;


template MAIN() {

    signal input array[2512];
    signal output d;

    signal v;
    v <== 168;

    d <== array[v];
}

component main = MAIN();

I want to access an array element at an arbitrary index and return it as a signal.我想访问任意索引处的数组元素并将其作为信号返回。

I'm getting the following error:我收到以下错误:

   ┌─ "/Users/ilia/compiling/main-circom/main.circom":85:11
   │
85 │     d <== array[v];
   │           ^^^^^^^^ Non-quadratic constraint was detected statically, using unknown index will cause the constraint to be non-quadratic

How can I access an array element with an "Unknown" index?如何访问具有“未知”索引的数组元素?

What I am trying to build is a program which takes in an array of bytes, seeks to a specific index and then takes SHA256 hash of array[index:] .我正在尝试构建的是一个程序,它接收一个字节数组,寻找一个特定的索引,然后使用array[index:]的 SHA256 hash 。 I don't know what the index will be, the index will be computed inside the program based on the contents of the array.我不知道索引是什么,索引将根据数组的内容在程序内部计算。

I've asked my previous Circom question on crypto.stackexchange.com, but got directed here.我已经在 crypto.stackexchange.com 上问过我之前的 Circom 问题,但在这里得到了指导。

I can use QuinSelector like so:我可以像这样使用QuinSelector

    component quinSelector = QuinSelector(2512);
    for (k=0; k< 2512; k++) {
        quinSelector.in[k] <== array[k];
    }
    quinSelector.index <== v;
    d <== quinSelector.out;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM