Skip to content

[Bug] Constants exceeding field prime silently wrap without warning #403

@chamitro

Description

@chamitro

Summary

Integer constants larger than the field prime are silently reduced modulo p without any compiler warning.

Environment

  • Circom: 2.2.3
  • OS: Ubuntu

Reproducer

pragma circom 2.0.0;

template Test() {
    signal input a;
    signal output c;
    
    // p+1 where p = 21888242871839275222246405745257275088548364400416034343698204186575808495617
    c <== a + 21888242871839275222246405745257275088548364400416034343698204186575808495618;
}

component main = Test();
circom test.circom --r1cs --wasm --output .
echo '{"a": "5"}' > input.json
node test_js/generate_witness.js test_js/test.wasm input.json w.wtns
snarkjs wtns export json w.wtns w.json
cat w.json  # Returns 6 instead of expected large number!

Results

Constant Expected Actual
p Warning or 0 Silent 0
p+1 Warning or error Silent 1
p+2 Warning or error Silent 2
2p Warning or error Silent 0
100p+42 Warning or error Silent 42

Expected Behavior

Compiler should emit a warning like:

warning: constant exceeds field prime, will be reduced modulo p

Comparison

Noir correctly rejects with:

error: Integer literal is too large
  value exceeds limit of 21888242871839275222246405745257275088548364400416034343698204186575808495616

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions