一键导入
felt-construction
Use when constructing a `Felt` from a numeric value in Rust — avoid silently truncating values that may exceed the field modulus.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
菜单
Use when constructing a `Felt` from a numeric value in Rust — avoid silently truncating values that may exceed the field modulus.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
基于 SOC 职业分类
Enforce type-signature conventions for public Miden Assembly (.masm) procedures. Use when adding, editing, or reviewing a `pub proc` signature — parameter and return types, semantic type aliases, struct/array/tuple types, and how the signature maps onto the operand stack and the doc-comment Inputs/Outputs.
Enforce inline commenting conventions for Miden Assembly (.masm) files. Use when editing, reviewing, or creating .masm files.
Enforce doc comment conventions for Miden Assembly (.masm) procedures. Use when editing, reviewing, or creating .masm procedures, especially when documenting inputs, outputs, panic conditions, or invocation types.
Use when writing kernel, account, or note MASM code that reads from or writes to the advice provider (advice stack / advice map) — validate advice data.
Use when writing a Rust test that exercises a failure path or a MASM test that expects a `panic` / `assert` — assert on the specific expected error variant or error code.
Use when writing or reviewing MASM hot paths — prefer the cheaper equivalent instruction: `neq.0` over `gt.0` for non-zero checks, `cdrop` over an `if/else` selecting between two values, `dup.N` over `loc_load` for a value still on the stack, `eqw` over element-wise word comparison, `u32gt`/`u32lt` over generic `gt`/`lt` on known-u32 operands.
| name | felt-construction |
| description | Use when constructing a `Felt` from a numeric value in Rust — avoid silently truncating values that may exceed the field modulus. |
Do not call Felt::new(x) when x could exceed the field modulus. Felt::new silently truncates oversized values, which produces a valid-looking Felt that no longer equals the original input — a classic source of hard-to-attribute bugs.
Use one of:
Felt::from(x) where x is a u32 or smaller (infallible).Felt::try_from(x) for u64-and-larger inputs, returning Result.assert!(x < Felt::MODULUS) before Felt::new(x) if you have already proven the bound.The field modulus sits just below 2^64, so Felt::new truncates only for a narrow band of large values — most tests pass and production hits the bad input as a value mismatch far from the call. Felt::from(u32) cannot truncate and Felt::try_from forces the bound check.
// Good: u32 input, infallible conversion
let f = Felt::from(slot_index as u32);
// Good: untrusted u64 input, checked conversion
let f = Felt::try_from(user_value).map_err(|_| Error::FeltOverflow)?;
// Bad: silent truncation on any value >= MODULUS
let f = Felt::new(user_value);