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

Implement generic assert_eq #247

Merged
merged 4 commits into from
Jan 8, 2025
Merged

Conversation

bufferhe4d
Copy link
Contributor

Adds generic assert_eq using #231.

It recursively goes through any nested structure like arrays or structs.

Copy link
Collaborator

@katat katat left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is really nice to have! Great work @bufferhe4d !

@katat
Copy link
Collaborator

katat commented Jan 6, 2025

@mimoo might want a round of review

@mimoo
Copy link
Contributor

mimoo commented Jan 8, 2025

let's merge this one?

@mimoo mimoo merged commit 99c3935 into zksecurity:main Jan 8, 2025
1 check passed
comparisons.push(Comparison::VarConst(cvar.clone(), cst.clone()));
}
(ConstOrCell::Cell(lhs), ConstOrCell::Cell(rhs)) => {
comparisons.push(Comparison::Vars(lhs.clone(), rhs.clone()));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why return a comparisons array btw? Why not just do the constraints right here?

match (lhs_cvar, rhs_cvar) {
        // two constants
        (ConstOrCell::Const(a), ConstOrCell::Const(b)) => {
            if a != b {
                Err(Error::new(
                    "constraint-generation",
                    ErrorKind::AssertionFailed,
                    span,
                ))?
            }
        }

        // a const and a var
        (ConstOrCell::Const(cst), ConstOrCell::Cell(cvar))
        | (ConstOrCell::Cell(cvar), ConstOrCell::Const(cst)) => {
            compiler.backend.assert_eq_const(cvar, *cst, span)
        }
        (ConstOrCell::Cell(lhs), ConstOrCell::Cell(rhs)) => {
            compiler.backend.assert_eq_var(lhs, rhs, span)
        }

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for the delayed reply. I think the reason was that I couldn't figure how to pass the compiler backend recursively. Hence used the table instead. I can look into it again to make it more elegant.

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

Successfully merging this pull request may close these issues.

3 participants