requires in std.contracts over a list argument’s length is refused: “an argument is not a whole number the prover reads”Open and answer this issue on GitHub.
ready, bugs, queued · opened 2026-11-30 · updated 2026-11-30 · 0 comments
While building the SHA extensions’ platform primitive (commit “Prototype: SHA-256 in hardware as two platform primitives”, now on develop), its std.contracts entry first carried
[fn."hash::sha256_block_hardware"]
...
requires = ["state.len() == 8", "off >= 0 && off + 64 <= data.len()"]
signature = "(mut state: Vec[u32], data: ref Vec[u8], off: i64)"
and a caller that proved both from a guard (if h.len() != 8 || off < 0 || off + 64 > data.len() { return } right before the call) was refused:
error[NK1300]: `hash::sha256_block_hardware: state.len() == 8 && off >= 0 && off + 64 <= data.len()` is not proved: an argument is not a whole number the prover reads.
The entry was then shipped without requires and with panics = true; the Rust side checks the slice once more.
A std function’s precondition over the length of a list argument is read as a user function’s assert at its top is (Part III 14.2, ADR-269 D5): the same guard before the call proves it. For a user function the same claim is proved (probe below, Checked, no NK1300).
fn bump(mut h: Vec[u32]) {
assert(h.len() == 8)
h[0] = h[0] + 1
}
fn main() throws {
let mut h: Vec[u32] = [0; 8]
for _i in 0..<3 {
bump(h)
}
println(f"{h[0]}")
}
There is no std entry today with a requires over a list’s length (grep -n 'requires = \[.*len()' crates/nikaia-std/std.contracts finds none), so the probe needs one: add requires = ["state.len() == 8", "off >= 0 && off + 64 <= data.len()"] to hash::sha256_block_hardware in std.contracts, rebuild (cargo build --profile fast -p nikaia), and check:
use std::hash
fn step(mut h: Vec[u32], data: ref Vec[u8], off: i64) {
if h.len() != 8 || off < 0 || off + 64 > data.len() {
return
}
hash::sha256_block_hardware(h, data, off)
}
fn main() throws {
let mut h: Vec[u32] = [0; 8]
let d: Vec[u8] = [0; 64]
step(h, d, 0)
println(f"{h[0]}")
}
Expected: Checked. Actual: the NK1300 above, “an argument is not a whole number the prover reads”.
ADR-269 D5 (a precondition is the caller’s, proved at the call) and ADR-platform-layer-v1 D1 (a primitive’s std.contracts entry is its whole meaning for the language, and the prover checks every call against it).
std.contracts requires is turned into a claim at the call (the reading that answers “an argument is not a whole number the prover reads”): a NAME.len() of a list or text argument is read as the argument’s length, as in a user function’s precondition.hash::sha256_block_hardware gets its requires back and panics = false (#2957’s primitive).tests/compiler/tests/: the probe above checks; without the guard it is refused with NK1300 naming the claim.The probe checks with the requires in place, and the primitive’s entry carries it.
Generated by Claude Code