Skip to content

Take public logup sum into account in check_relation_uses#457

Open
az-starkware wants to merge 2 commits intoadar/relation_uses_audit_fixesfrom
adar/relation_uses_audit_fixes2
Open

Take public logup sum into account in check_relation_uses#457
az-starkware wants to merge 2 commits intoadar/relation_uses_audit_fixesfrom
adar/relation_uses_audit_fixes2

Conversation

@az-starkware
Copy link
Copy Markdown
Collaborator

No description provided.

@cursor
Copy link
Copy Markdown

cursor Bot commented Apr 15, 2026

PR Summary

Medium Risk
Changes the core verifier’s relation-usage accounting by incorporating statement-level (public logup) relation uses and requires all Statement implementations to return per-relation use counts, which could cause verification failures if counts are wrong or incomplete.

Overview
Updates the Statement::public_logup_sum API to return both the public logup sum and a per-relation use-count map, and threads this through the verifier.

Extends check_relation_uses to include these extra statement-level uses when bounding relation usage, and updates Cairo/Circuit/example statements to track and report relation names/counts (including new Cairo relation-name constants and a LogupSum helper).

Reviewed by Cursor Bugbot for commit e82d50f. Bugbot is set up for automated code reviews on this repo. Configure here.

@reviewable-StarkWare
Copy link
Copy Markdown
Collaborator

This change is Reviewable

Copy link
Copy Markdown

@cursor cursor Bot left a comment

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit e82d50f. Configure here.


pub fn add_yield_term(&mut self, context: &mut Context<impl IValue>, term: Var) {
self.var = self.var.map(|var| eval!(context, (var) - (term))).or(Some(term));
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

add_yield_term wrong sign when var is None

Medium Severity

add_yield_term uses .or(Some(term)) as the fallback when self.var is None, which sets the sum to +term instead of -term. A yield term represents a subtraction, so an empty LogupSum getting a yield term first would produce the wrong sign. Currently the only call site (line 607) always calls add_use_term first, so the None path isn't hit — but the method's contract is broken for that case, making it a latent correctness issue.

Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit e82d50f. Configure here.

@az-starkware az-starkware force-pushed the adar/relation_uses_audit_fixes branch 3 times, most recently from d2555f3 to e8cf28a Compare April 19, 2026 11:08
@ilyalesokhin-starkware
Copy link
Copy Markdown
Contributor

crates/cairo_air/src/statement.rs line 76 at r1 (raw file):

    pub fn add_yield_term(&mut self, context: &mut Context<impl IValue>, term: Var) {
        self.var = self.var.map(|var| eval!(context, (var) - (term))).or(Some(term));
    }

Don't we count yields?

Code quote:

    pub fn add_yield_term(&mut self, context: &mut Context<impl IValue>, term: Var) {
        self.var = self.var.map(|var| eval!(context, (var) - (term))).or(Some(term));
    }

@ilyalesokhin-starkware
Copy link
Copy Markdown
Contributor

crates/cairo_air/src/statement.rs line 76 at r1 (raw file):

Previously, ilyalesokhin-starkware wrote…

Don't we count yields?

I guess the use count is also a bound on the yield_count for opcodes.

@ilyalesokhin-starkware
Copy link
Copy Markdown
Contributor

crates/cairo_air/src/statement.rs line 58 at r2 (raw file):

#[derive(Default)]
struct LogupSum {

Document.

Code quote:

LogupSum

@ilyalesokhin-starkware
Copy link
Copy Markdown
Contributor

crates/cairo_air/src/statement.rs line 58 at r2 (raw file):

#[derive(Default)]
struct LogupSum {

consider renaming to TrackedLogupSum or PublicLogupSum

Code quote:

LogupSum 

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