mirror of
https://github.com/saymrwulf/risc0-ed25519-verified.git
synced 2026-09-04 20:03:41 +00:00
Transpile the Scalar52 limb backend (backend::serial::u64::scalar
add/sub/mul/square/montgomery_*) from Rust to Lean via Charon/Aeneas,
scoped at the function level to the iterator-free arithmetic core.
- verification/extract-scalar.sh: function-level Charon/Aeneas extraction.
This fork (v4.1.3) inlines a local `black_box` (a volatile read used as an
optimization barrier) inside Scalar52::sub; charon cannot translate the
`&raw const` it lowers to, so it is marked --opaque and modeled below.
- verification/gen/CurveScalar/{Types,Funs}.lean: transpiled model (27 defs)
- verification/gen/CurveScalar/FunsExternal.lean: hand-written model of
Scalar52::sub::black_box as the identity on u64 (a volatile read returns
the value written; the qualifier is only an optimization barrier).
TypesExternal.lean is decl-free — this fork pulls in no external types
(unlike v5 dalek, which routes sub through subtle::Choice).
- verification/Proofs/ScalarDenote.lean: semantic foundation — Scalar52
denotation into ℤ/ℓℤ, limb-bound invariant, and L_val (the transpiled
constants::L denotes exactly the group order ℓ, kernel-checked).
- verification/check-scalar.sh: guarded compile of the gen modules plus the
denotation foundation.
check-scalar.sh passes: gen compiles; denotation + L = ℓ proven.
add/sub/mul remain in progress.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
34 lines
1.7 KiB
Bash
Executable file
34 lines
1.7 KiB
Bash
Executable file
#!/usr/bin/env bash
|
||
# Regenerate the SCALAR-layer Lean model (gen/CurveScalar) from Rust.
|
||
#
|
||
# SCOPE: the Scalar52 limb backend (backend::serial::u64::scalar) — the
|
||
# iterator-free ARITHMETIC core: add/sub/mul/square/montgomery_reduce/
|
||
# from_bytes/to_bytes mod ℓ = 2²⁵² + 27742317777372353535851937790883648493.
|
||
# The high-level crate::scalar wrapper (Sum/Product/NAF/radix/byte-parsing,
|
||
# all iterator-heavy) is brought in only for the signature layer.
|
||
set -euo pipefail
|
||
source ~/aeneas-toolchain/env.sh
|
||
HERE="$(cd "$(dirname "$0")" && pwd)"
|
||
CRATE=~/GitClone/FormalVerification/sources/risc0-curve25519-dalek-source/curve25519-dalek
|
||
|
||
echo "[1/2] charon: Rust -> LLBC (scalar + Scalar52)"
|
||
cd "$CRATE"
|
||
charon cargo --preset=aeneas \
|
||
--start-from 'crate::backend::serial::u64::scalar::_::add' \
|
||
--start-from 'crate::backend::serial::u64::scalar::_::sub' \
|
||
--start-from 'crate::backend::serial::u64::scalar::_::mul' \
|
||
--start-from 'crate::backend::serial::u64::scalar::_::square' \
|
||
--start-from 'crate::backend::serial::u64::scalar::_::montgomery_mul' \
|
||
--start-from 'crate::backend::serial::u64::scalar::_::montgomery_square' \
|
||
--start-from 'crate::backend::serial::u64::scalar::_::montgomery_reduce' \
|
||
--start-from 'crate::backend::serial::u64::scalar::_::montgomery_invert' \
|
||
--start-from 'crate::backend::serial::u64::scalar::_::as_montgomery' \
|
||
--start-from 'crate::backend::serial::u64::scalar::_::from_montgomery' \
|
||
--opaque 'crate::backend::serial::u64::scalar::_::sub::black_box' \
|
||
--dest-file "$HERE/CurveScalar.llbc" \
|
||
-- --no-default-features
|
||
|
||
echo "[2/2] aeneas: LLBC -> Lean (split files, CurveScalar.* modules)"
|
||
cd "$HERE"
|
||
aeneas -backend lean -split-files -subdir CurveScalar -dest gen CurveScalar.llbc
|
||
echo "Done."
|