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

The problem of circom compiler bottom layer algorithm #271

Open
MJJ-Shuai opened this issue Jun 20, 2024 · 0 comments
Open

The problem of circom compiler bottom layer algorithm #271

MJJ-Shuai opened this issue Jun 20, 2024 · 0 comments

Comments

@MJJ-Shuai
Copy link

static inline void add_l1nl2n(PFrElement r, PFrElement a, PFrElement b)
{
    r->type = Fr_LONG;

    Fr_rawAdd(r->longVal, a->longVal, b->longVal);
}
void Fr_rawAdd(FrRawElement pRawResult, const FrRawElement pRawA, const FrRawElement pRawB)
{
    uint64_t carry = mpn_add_n(pRawResult, pRawA, pRawB, Fr_N64);

    if(carry || mpn_cmp(pRawResult, Fr_rawq, Fr_N64) >= 0)
    {
        mpn_sub_n(pRawResult, pRawResult, Fr_rawq, Fr_N64);
    }
}

I noticed that circom, when dealing with the addition of two long and non-Montgomery-type data, only does one subtraction for the overflow result to try to get the result after modulo, but if the result is much larger than 2p, won't it appear that the result is not in the finite domain?

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

1 participant