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

feat!: automatically validate inputs #7520

Open
wants to merge 10 commits into
base: master
Choose a base branch
from

Conversation

asterite
Copy link
Collaborator

@asterite asterite commented Feb 25, 2025

Description

Problem

Resolves #4218

Summary

This PR transforms a program like this:

fn main(x: u8, y: u8) {
    assert_eq(x, y);
}

into this one:

fn main(x: u8, y: u8) {
    if !std::runtime::is_unconstrained() {
        std::validation::AssertsIsValidInput::assert_is_valid_input(x);
        std::validation::AssertsIsValidInput::assert_is_valid_input(y);
    }
    assert_eq(x, y);
}

The idea is that all inputs now must implement the AssertsIsValidInput trait.

The if !std::runtime::is_unconstrained() check is so that these checks aren't done for brillig (I thought --force-brillig would be passed to the Elaborator to avoid having this check but this wasn't the case).

Pending:

  • Validate return values from unconstrained functions called from constrained functions
  • Make sure the name of the trait and its method are okay
  • Docs

Additional Context

Documentation

Check one:

  • No documentation needed.
  • Documentation included in this PR.
  • [For Experimental Features] Documentation to be submitted in a separate PR.

PR Checklist

  • I have tested the changes locally.
  • I have formatted the changes with Prettier and/or cargo fmt on default settings.

@asterite asterite changed the title Ab/trait that validates input feat!: automatically validate inputs Feb 25, 2025
Copy link
Contributor

github-actions bot commented Feb 25, 2025

Changes to circuit sizes

Generated at commit: b0e1584992ecc528c7a85dd034339958dbe272f8, compared to commit: 677c10c50e6944e9e11d5579048f77cab59cf91a

🧾 Summary (10% most significant diffs)

Program ACIR opcodes (+/-) % Circuit size (+/-) %
6 +127 ❌ +57.99% +4,030 ❌ +56.86%
conditional_regression_short_circuit +127 ❌ +53.36% +4,031 ❌ +56.73%

Full diff report 👇
Program ACIR opcodes (+/-) % Circuit size (+/-) %
6 346 (+127) +57.99% 11,118 (+4,030) +56.86%
conditional_regression_short_circuit 365 (+127) +53.36% 11,137 (+4,031) +56.73%
sha256 1,436 (+157) +12.28% 24,583 (+4,019) +19.54%
sha256_var_padding_regression 3,818 (+350) +10.09% 193,653 (+31,417) +19.36%
fold_call_witness_condition 5 (+1) +25.00% 19 (+1) +5.56%
regression 278 (-2) -0.71% 3,811 (0) 0.00%
array_if_cond_simple 43 (-59) -57.84% 2,977 (-148) -4.74%

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.

Add trait which validates circuit inputs / unconstrained function return values
1 participant