Skip to content

fix: transformation of unconstrained contract library methods - #12746

Merged
nventuro merged 3 commits into
masterfrom
nv/fix-unconstrained-transformation
Mar 14, 2025
Merged

nventuro merged 3 commits into
masterfrom
nv/fix-unconstrained-transformation

Conversation

@nventuro

@nventuro nventuro commented Mar 14, 2025 •

Copy link
Copy Markdown
Contributor

We were not discarding contract library methods when searching for top-level unconstrained fns, and so any such function would get the UnconstrainedContext initialization injected, resulting in the correspoding oracle calls being included. If this were to be called from public, the transpiler would fail due to the unknown oracles, resulting in unconstrained contract library methods being unusable in public (and likely in private too, though this would fail at runtime).

I opened #12743 to track the work in formalizing the notion of top-level unconstrained fns (soon to be #[query] or #[app-query] or #[application] or something).

Fixes #12732

@nventuro
nventuro requested review from Thunkar and fcarreiro March 14, 2025 13:56
Comment on lines +219 to +225
#[contract_library_method]
fn inner_helper_with_failed_assertion() {
let not_true = false;
assert(not_true == true, "This assertion should fail!");
}

#[contract_library_method]

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@fcarreiro these functions were being called directly from public functions like any regular noir function, but any fn directly inside the contract mod gets made a contract entrypoint automatically (weird I know). We now detect and warn when we see these, so I added the contract_library_method attribute, which makes the fn not be an entrypoint (weird I know), which I assume is what you originally intended.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks yes! I guess they should be unconstrained as well? In any case if this works we can check later

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

No need, they'll be converted to unconstrained automatically if called from an unconstrained fn (like public fns are). We'd only need to make this helper unconstrained if we needed to use any of the unconstrained features (e.g. while or break).

@nventuro
nventuro enabled auto-merge (squash) March 14, 2025 16:07
@nventuro
nventuro merged commit 7d2fd5c into master Mar 14, 2025
@nventuro
nventuro deleted the nv/fix-unconstrained-transformation branch March 14, 2025 16:29
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.

Can't compile a contract using unconstrained code

3 participants