feat(v2.1-rv64): switch to u16 limbs in keccak/sha2 airs#2802
feat(v2.1-rv64): switch to u16 limbs in keccak/sha2 airs#2802shuklaayush wants to merge 1 commit into
Conversation
This comment was marked as outdated.
This comment was marked as outdated.
This comment has been minimized.
This comment has been minimized.
d5e1353 to
db27775
Compare
This comment was marked as outdated.
This comment was marked as outdated.
This comment has been minimized.
This comment has been minimized.
This comment was marked as outdated.
This comment was marked as outdated.
db27775 to
8b0a2d8
Compare
This comment was marked as outdated.
This comment was marked as outdated.
This comment has been minimized.
This comment has been minimized.
8b0a2d8 to
7acbea7
Compare
This comment was marked as outdated.
This comment was marked as outdated.
This comment has been minimized.
This comment has been minimized.
…lumns PR 3 of the memory-bus-u16 split (stacked on PR 1, disjoint from PR 2). Shrinks SHA-2 and Keccak chip trace columns that are only consumed as packed u16 cells through the memory bus. SHA-2: - Main chip: prev_state / new_state are u16 cells; message_bytes becomes message_u16s; dst/state/input pointer limbs are u16-shaped. - Block hasher: prev_hash / final_hash are u16 cells. - sha2_bus MESSAGE_1 / MESSAGE_2 payloads packed to u16 on sender and receiver. - CUDA tracegen + tests updated. - Carry columns (carry_a, carry_e, carry_or_buffer in sha2-air) stay 8-bit bounded — byte carries are still constrained as bytes. Keccak: - keccakf_op: preimage / postimage / buffer_ptr_limbs migrated to u16 cells; pointer composition uses the scaled 16-bit bound. - keccakf_state_bus payload between keccakf_op and keccakf_perm packed to u16. - xorin: pointer limbs u16-shaped; the byte-XOR buffers (preimage_buffer_bytes, input_bytes, postimage_buffer_bytes) stay byte-shaped — those columns still carry byte-level XOR data. - CUDA tracegen + tests updated; bitwise-lookup wiring removed from keccakf_op now that pointer bytes no longer need byte-level checks. Adapters helper: - Add expand_to_rv64_block in riscv/circuit::adapters: zero-pads `N` u16 limbs to one RV64 register bus block (BLOCK_FE_WIDTH cells). Used by keccakf_op and xorin for pointer reads against u16-celled RV64_REGISTER_AS. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
7acbea7 to
337518b
Compare
|
Claude finished @shuklaayush's task in 2m 7s —— View job Code Review: PR #2802 — u16 limbs in keccak/sha2 airs
This is a clean, well-scoped PR. The mechanical transformation from byte-shaped to u16-shaped columns is consistent across all affected chips and their CUDA counterparts. The constraint logic is simplified throughout by removing the Positive observations
Minor issues / suggestions
No blocking issues foundThe constraint changes are algebraically sound — the u16 cell columns pass directly through the memory bus (which now expects |
Note: cells_used metrics omitted because CUDA tracegen does not expose unpadded trace heights. Commit: 337518b |
PR 3 of the memory-bus-u16 split, stacked on #2794 (disjoint from PR 2). Shrinks SHA-2 and Keccak chip trace columns that are only consumed as packed u16 cells through the memory bus.
Why
#2794 still stores SHA-2 main-chip state / message bytes and Keccak state / pointer columns byte-shaped, packing them at memory-bus call sites via
pack_u8_block. Because these columns are never inspected byte-by-byte by the AIR (the constraints operate on packed u16 values, or on byte-XOR buffers that intentionally stay byte-shaped), they can be stored u16-shaped directly — halving the affected trace columns and removing onepack_u8_blockper row.This is the second of the four cell-narrowing PRs (after PR 2 for RV64 control-flow) and is disjoint from it: the only files in this PR live under
extensions/sha2,extensions/keccak256, andcrates/circuits/sha2-air, plus one helper addition inextensions/riscv/circuit/src/adapters/mod.rs.What changes
SHA-2 section
Files:
extensions/sha2/circuit/src/sha2_chips/{main_chip,block_hasher_chip}/,crates/circuits/sha2-air/src/{air,columns,trace}.rs,extensions/sha2/circuit/cuda/.Main chip:
prev_state,new_stateare u16 cells.message_bytesreshapes tomessage_u16s(byte pairs packed at the call site).dst_ptr_limbs,state_ptr_limbs,input_ptr_limbsreshape to u16 where the AIR only consumes them as packed pointer cells; the high u16 cell gets the scaled 16-bit range check.Block hasher:
prev_hash,final_hashare u16 cells.sha2_bus:MESSAGE_1/MESSAGE_2payloads are packed to u16 on both sender and receiver.Stays byte-shaped (8-bit bounded by construction):
carry_a,carry_e,carry_or_bufferinsha2-air.Keccak section
Files:
extensions/keccak256/circuit/src/{keccakf_op,xorin}/,extensions/keccak256/circuit/cuda/.keccakf_op:preimage,postimagereshape to u16 cells.buffer_ptr_limbsreshape to u16; pointer composition uses the scaled 16-bit bound.keccakf_state_buspayload betweenkeccakf_opandkeccakf_permis packed to u16.xorin:keccakf_op).preimage_buffer_bytes,input_bytes,postimage_buffer_bytes) stay byte-shaped — those columns still carry byte-level XOR data and the AIR inspects them directly.CUDA tracegen mirrors the new shapes;
keccakf_opdrops thebitwise_lookupparameter from its kernel and ABI signatures now that pointer bytes no longer need byte-level checks. The call chip still wiresbitwise_lu.Adapter helper (cross-cut)
File:
extensions/riscv/circuit/src/adapters/mod.rs.expand_to_rv64_block: zero-padsNu16 limbs to one RV64 bus block (BLOCK_FE_WIDTHcells). Used bykeccakf_opandxorinfor pointer reads against u16-celledRV64_REGISTER_AS.BLOCK_FE_WIDTHimported into the adapters module to support the new helper.The existing
expand_to_rv64_register(8 u8 limbs, byte-shaped) is kept for byte-shaped chips and the legacy paths.Migration notes
pack_u8_block).RV64_REGISTER_ASfrom chips storing only the low 32 bits of the register should useexpand_to_rv64_block(BLOCK_FE_WIDTH cells, zero-padded) instead ofexpand_to_rv64_register(8 u8s).bitwise_lookup_busis removed forkeccakf_op.resolves int-7832, int-7833