Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ERROR] snarkJS: Error: Scalar size does not match #277

Open
utsavempiric20 opened this issue Jul 22, 2024 · 1 comment
Open

[ERROR] snarkJS: Error: Scalar size does not match #277

utsavempiric20 opened this issue Jul 22, 2024 · 1 comment

Comments

@utsavempiric20
Copy link

utsavempiric20 commented Jul 22, 2024

I face SnarkJS: Error: Scalar size does not match this issue when i convert the string to integer.give me the solution about it.
here my code :

pragma circom 2.0.0;

template StringToIntData(n) {
    signal input string[n];
    signal output integer;

    signal temp[n];
    signal mult_factor[n];
    signal resultInt[n+1];

    resultInt[0] <== 0;
    mult_factor[0] <== 1;
    for (var i = 1; i < n; i++) {
        mult_factor[i] <== mult_factor[i-1] * 10;
    }

    component partial_sum[n];
    for (var i = 0; i < n; i++) {
        partial_sum[i] = calaculateTheInt();

        temp[i] <== string[i] - 48; 

        partial_sum[i].in1 <== temp[i];
        partial_sum[i].in2 <== mult_factor[n-1-i];

        resultInt[i+1] <== resultInt[i] + partial_sum[i].out;
    }

    integer <== resultInt[n];
    log(integer);
}

template calaculateTheInt() {

    // Declaration of signals.
    signal input in1;
    signal input in2;
    signal output out;

    // Constraints.
    out <== in1 * in2;
}


component main {public [string]}= StringToIntData(5);

Input data is :

{
  "string": [49, 50, 51, 52, 53]
}
@Arvolear
Copy link
Contributor

Arvolear commented Aug 2, 2024

Hey @utsavempiric20, seems like your circuit doesn't have any private (non-public) inputs. That's why the snarkjs throws an error.

From ZK standpoint your circuit simply doesn't make sense, hence the error :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants