Skip to content

feat: Implement u32_less_than comparison primitive for Aiur#319

Open
arthurpaulino wants to merge 2 commits intomainfrom
ap/aiur-less-than
Open

feat: Implement u32_less_than comparison primitive for Aiur#319
arthurpaulino wants to merge 2 commits 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
@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
@arthurpaulino arthurpaulino enabled auto-merge (squash) March 6, 2026 00:34
@arthurpaulino arthurpaulino force-pushed the ap/aiur-less-than branch 2 times, most recently from 2146fcf to 5a9b715 Compare March 6, 2026 19:11
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.
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