Skip to content

feat: Implement u32_less_than comparison primitive for Aiur#319

Open
arthurpaulino wants to merge 1 commit intomainfrom
ap/aiur-less-than
Open

feat: Implement u32_less_than comparison primitive for Aiur#319
arthurpaulino wants to merge 1 commit intomainfrom
ap/aiur-less-than

Conversation

@arthurpaulino
Copy link
Member

@arthurpaulino arthurpaulino commented Mar 4, 2026

Add a constrained comparison operation for 32-bit unsigned integers, returning 1 if x < y and 0 otherwise. The algorithm byte-decomposes both operands into 4 little-endian bytes, then computes y - x - 1 via a borrow chain of 8 u8_sub lookups (2 per byte). The final borrow determines the result: no borrow means x < y, borrow means x >= y.

No canonicality enforcement is needed since u32 values are below 2^32, which is well within the Goldilocks prime (p = 2^64 - 2^32 + 1), so the 4-byte decomposition is unique.

Resources per operation: 24 auxiliaries, 8 Bytes2 lookups, 2 polynomial constraints (one decomposition sum per operand).

Changes span Lean (Term, Meta, Check, Bytecode, Compile) and Rust (bytecode, FFI, execute, trace, constraints), plus end-to-end tests.

@arthurpaulino arthurpaulino changed the title feat: Implement less_than for full Goldilocks field elements feat: Implement u32_less_than comparison primitive for Aiur Mar 4, 2026
Add a constrained comparison operation for 32-bit unsigned integers,
returning 1 if x < y and 0 otherwise. The algorithm byte-decomposes both
operands into 4 little-endian bytes, then computes y - x - 1 via a
borrow chain of 8 u8_sub lookups (2 per byte). The final borrow
determines the result: no borrow means x < y, borrow means x >= y.

No canonicality enforcement is needed since u32 values are below 2^32,
which is well within the Goldilocks prime (p = 2^64 - 2^32 + 1), so the
4-byte decomposition is unique.

Resources per operation: 24 auxiliaries, 8 Bytes2 lookups, 2 polynomial
constraints (one decomposition sum per operand).

Changes span Lean (Term, Meta, Check, Bytecode, Compile) and Rust
(bytecode, FFI, execute, trace, constraints), plus end-to-end tests.
@arthurpaulino arthurpaulino changed the title feat: Implement u32_less_than comparison primitive for Aiur feat: Implement u32_less_than comparison primitive for Aiur Mar 4, 2026
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.

1 participant