From afb7f8f39ebe78448650f79b981e173b0f31e64c Mon Sep 17 00:00:00 2001 From: Dendi Suhubdy <4477337+dendisuhubdy@users.noreply.github.com> Date: Fri, 20 Nov 2026 02:23:03 +0800 Subject: [PATCH] perps: pinned, precomputed state-proof verifier keys for chain 22 (CON-601) A block carrying a tier-18 perps state proof made every validator build that shape's verifier key (~1.7 GB with `parallel`, ~3.3-4 GB without), so a 2 GB validator could OOM on a valid block. Chain 22 pins the keys instead. - core: gated genesis field `perps.state_proof_keys` (serde default + skip, bound into the genesis hash only when set, `rand-perps-ext-3` persisted); check() admits only canonical shapes of the chain (<= 8, ordered, needs engine_program_log_height). When set, an unpinned declared shape is refused before any key is touched, at validate and at apply. - zkvm (node-local executor.rs): `perp_vk` module (chain-22 shapes, compiled-in SHA-256 pins, file names, blob/check); pinned mode refuses unpinned shapes in perp_pre_key, verifies only against loaded keys and never builds one. - node: `perps_key` loads every pinned file at startup (--perps-key-dir, RAND_PERPS_KEY_DIR, beside the binary), refuses to start on a missing or mismatched file, reports rand_status.perps_keys; rand_getPerps serves the list; `rand-node keygen-perp-vk` (--print-pinned, --check, --genesis-json, --profile --out-dir); `verify` loads them too. - client: `rand perp prove` refuses non-canonical shapes on a pinned chain. - keys: the four chain-22 Production files (tier 18, program 14, input 16, poseidon2 20, public 7/8/9/10), 13 685 bytes each, in crates/randprotocol-zkvm/keys/. - deploy: the chain-22 cut sets the field from the shipped files held to the cutting rand-node's pins, asserts it, probes it in the hash and reads it back in check-limits (selftest 467 passed, 0 failed); release.yml ships, sums, attests and checks the files; roll-all.sh installs them (PERPS_VK_DIR). - docs: deploy.md, perps.md, CHANGELOG. Chain 21's genesis and pins are unchanged (the field is absent there). Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01YGaYNLS2uLR7w6m2JtejVo --- .github/workflows/release.yml | 21 +- CHANGELOG.md | 17 + crates/randprotocol-client/src/perps.rs | 29 ++ .../randprotocol-client/tests/wallet_flow.rs | 1 + crates/randprotocol-core/src/confidential.rs | 21 +- crates/randprotocol-core/src/genesis.rs | 33 ++ crates/randprotocol-core/src/ledger/mod.rs | 1 + crates/randprotocol-core/src/ledger/perps.rs | 336 +++++++++++++- crates/randprotocol-node/src/agg_executor.rs | 12 + crates/randprotocol-node/src/lib.rs | 1 + crates/randprotocol-node/src/main.rs | 70 ++- crates/randprotocol-node/src/msauth_key.rs | 1 + crates/randprotocol-node/src/node.rs | 13 + crates/randprotocol-node/src/perps_key.rs | 411 ++++++++++++++++++ crates/randprotocol-node/src/rpc.rs | 8 + crates/randprotocol-node/src/storage.rs | 1 + crates/randprotocol-node/src/verify_cache.rs | 12 + .../randprotocol-node/tests/burst_memory.rs | 1 + crates/randprotocol-node/tests/cluster.rs | 1 + .../randprotocol-node/tests/common/cluster.rs | 1 + crates/randprotocol-node/tests/common/mod.rs | 1 + crates/randprotocol-node/tests/dandelion.rs | 1 + crates/randprotocol-node/tests/genesis_cli.rs | 1 + .../randprotocol-node/tests/prover_hosted.rs | 2 + .../tests/public_rpc_check.rs | 1 + .../randprotocol-node/tests/rpc_contract.rs | 1 + crates/randprotocol-node/tests/split_auth.rs | 1 + ...k-production-t18-pg14-in16-pub10-p2h20.bin | Bin 0 -> 13685 bytes ...vk-production-t18-pg14-in16-pub7-p2h20.bin | Bin 0 -> 13685 bytes ...vk-production-t18-pg14-in16-pub8-p2h20.bin | Bin 0 -> 13685 bytes ...vk-production-t18-pg14-in16-pub9-p2h20.bin | Bin 0 -> 13685 bytes crates/randprotocol-zkvm/src/executor.rs | 214 ++++++++- crates/randprotocol-zkvm/tests/perp_vk.rs | 63 +++ deploy/cut-chain22-genesis.sh | 217 +++++++-- deploy/roll-all.sh | 40 +- deploy/sync-zkvm.sh | 4 +- docs/deploy.md | 62 +++ docs/perps.md | 23 +- 38 files changed, 1571 insertions(+), 51 deletions(-) create mode 100644 crates/randprotocol-node/src/perps_key.rs create mode 100644 crates/randprotocol-zkvm/keys/perp-vk-production-t18-pg14-in16-pub10-p2h20.bin create mode 100644 crates/randprotocol-zkvm/keys/perp-vk-production-t18-pg14-in16-pub7-p2h20.bin create mode 100644 crates/randprotocol-zkvm/keys/perp-vk-production-t18-pg14-in16-pub8-p2h20.bin create mode 100644 crates/randprotocol-zkvm/keys/perp-vk-production-t18-pg14-in16-pub9-p2h20.bin create mode 100644 crates/randprotocol-zkvm/tests/perp_vk.rs diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 58b69d40..5a1dd449 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -188,7 +188,10 @@ jobs: # The precomputed msauth verifier key (private multisig): the committed blob, shipped # beside the binaries and installed at /usr/local/bin/msauth-vk-production.bin. cp crates/randprotocol-zkvm/keys/msauth-vk-production.bin dist/ - ( cd dist && sha256sum rand-node rand rand-prover msauth-vk-production.bin > SHA256SUMS && cat SHA256SUMS ) + # CON-601: the four pinned perps state-proof verifier keys (chain 22's + # perps.state_proof_keys), shipped beside the binaries and installed in /usr/local/bin. + cp crates/randprotocol-zkvm/keys/perp-vk-production-*.bin dist/ + ( cd dist && sha256sum rand-node rand rand-prover msauth-vk-production.bin perp-vk-production-*.bin > SHA256SUMS && cat SHA256SUMS ) dist/rand-node --version - name: The msauth key blob is the one this rand-node pins working-directory: fullnode @@ -198,6 +201,19 @@ jobs: want=$(dist/rand-node keygen-msauth-vk --print-pinned production) echo "msauth-vk-production.bin sha256 $got, pinned $want" [ "$got" = "$want" ] || { echo "::error::dist/msauth-vk-production.bin ($got) is not the pin compiled into dist/rand-node ($want)"; exit 1; } + - name: The perps state-proof key files are the ones this rand-node pins (CON-601) + working-directory: fullnode + run: | + set -euo pipefail + n=0 + while read -r name want; do + got=$(dist/rand-node keygen-perp-vk --check "dist/$name") + echo "$name sha256 $got, pinned $want" + [ "$got" = "$want" ] || { echo "::error::dist/$name ($got) is not the pin compiled into dist/rand-node ($want)"; exit 1; } + n=$((n + 1)) + done < <(dist/rand-node keygen-perp-vk --print-pinned production) + shipped=$(ls dist/perp-vk-production-*.bin | wc -l) + [ "$n" -eq 4 ] && [ "$shipped" -eq "$n" ] || { echo "::error::rand-node pins $n perp-vk files, dist holds $shipped (want 4)"; exit 1; } - name: Build provenance uses: actions/attest-build-provenance@96278af6caaf10aea03fd8d33a09a777ca52d62f # v3.2.0 with: @@ -206,6 +222,7 @@ jobs: fullnode/dist/rand fullnode/dist/rand-prover fullnode/dist/msauth-vk-production.bin + fullnode/dist/perp-vk-production-*.bin - name: The release working-directory: fullnode env: @@ -248,4 +265,4 @@ jobs: prerelease="" case "$TAG" in *-rc*|*-alpha*|*-beta*) prerelease="--prerelease" ;; esac gh release create "$TAG" --repo "$REPO" --verify-tag --title "$TAG" --notes-file notes.md $prerelease \ - dist/rand-node dist/rand dist/rand-prover dist/msauth-vk-production.bin dist/SHA256SUMS + dist/rand-node dist/rand dist/rand-prover dist/msauth-vk-production.bin dist/perp-vk-production-*.bin dist/SHA256SUMS diff --git a/CHANGELOG.md b/CHANGELOG.md index c033c79c..dd7b6347 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,23 @@ stopped at v0.4 until 2026-09-30, when the entries v0.5 to v0.6.7 were written f ## Unreleased +Perps (**a chain cut, chain 22**; chain 21 unchanged): + +- **Pinned state-proof verifier keys (CON-601, monorepo#23).** A new gated genesis field, + `perps.state_proof_keys`, lists the state-proof shapes a chain admits, each with the SHA-256 of + its precomputed key file. It is omitted when empty and bound into the genesis hash only when + set (`rand-perps-ext-3` in the persisted section). On such a chain an unpinned shape is refused + before any key build, at validate and apply. Pinned keys come only from hash-matched files, + loaded at startup (`--perps-key-dir`, `RAND_PERPS_KEY_DIR`, default beside the binary). The node + refuses to start if one is missing or mismatched, and never builds a pinned key. + `rand_status.perps_keys` and `rand_getPerps.state_proof_keys` report them. New + `rand-node keygen-perp-vk` (`--print-pinned`, `--check`, `--genesis-json`, `--profile + --out-dir`). Chain 22's four keys are the canonical tier-18 shapes (program 14, input 16, + poseidon2 20, public 7–10), 13 685 bytes each, committed in `crates/randprotocol-zkvm/keys/`, + shipped by the release workflow and installed by `deploy/roll-all.sh` (`PERPS_VK_DIR`). The + chain-22 cut script sets, asserts, hash-probes and reads back the field. `rand perp prove` + refuses a non-canonical shape on a pinned chain. + zkVM (**a chain cut: constraint set 11, for chain 22 and v0.8.7**; chain 21 stays on the set-9 v0.8.6 line): diff --git a/crates/randprotocol-client/src/perps.rs b/crates/randprotocol-client/src/perps.rs index b3a6a699..f36ad1c8 100644 --- a/crates/randprotocol-client/src/perps.rs +++ b/crates/randprotocol-client/src/perps.rs @@ -141,6 +141,10 @@ pub struct PerpsState { /// The recorded heights no state proof has covered, ascending: the blocks the next window /// runs the engine over. pub pending_heights: Vec, + /// CON-601: the shapes of the genesis' pinned state-proof keys (`state_proof_keys`), empty + /// when unset (chain 21) or from a node that predates the field. Set, a proof of any other + /// shape is refused by every node, so `rand perp prove` proves at the canonical shape only. + pub state_proof_keys: Vec, } impl PerpsState { @@ -170,6 +174,17 @@ impl PerpsState { Some(a) => a.iter().map(|h| u64_of(h, "pending_heights")).collect::>()?, None => Vec::new(), }, + state_proof_keys: match v["state_proof_keys"].as_array() { + Some(a) => a + .iter() + .map(|k| { + serde_json::from_value::(k.clone()) + .map(|k| k.shape()) + .map_err(|e| anyhow!("rand_getPerps.state_proof_keys: {e}")) + }) + .collect::>()?, + None => Vec::new(), + }, }) } @@ -662,6 +677,13 @@ pub async fn prove_and_submit_state_proof_shaped( ) -> Result<(Hash, u8, usize)> { let state = PerpsState::fetch(rpc).await?; let canonical = proves_canonical(canonical, &state); + // CON-601: a chain pinning its state-proof keys admits their shapes only — the canonical ones. + if !state.state_proof_keys.is_empty() && !canonical { + bail!( + "this chain pins its state-proof keys (rand_getPerps.state_proof_keys, {} shapes): only the canonical shape is admitted; drop --smallest", + state.state_proof_keys.len() + ); + } job.check_for(state.sparse_windows)?; let executor = ZkExecutor::new(profile); let (segment, r_from, r_to) = job_segment(job, &executor); @@ -765,6 +787,12 @@ pub async fn prove_and_submit_state_proof_shaped( state.max_tier ); } + if !state.state_proof_keys.is_empty() { + let shape = randprotocol_zkvm::executor::proof_shape(&proof).ok_or_else(|| anyhow!("the proof's header does not decode"))?; + if !state.state_proof_keys.contains(&shape) { + bail!("the proof declares {shape:?}, none of the chain's pinned state-proof key shapes: nothing submitted"); + } + } let proof_bytes = proof.len(); wallet::check_proof_size(proof_bytes, wallet::proof_cap(rpc.limits().await?.as_ref()))?; let action = Action::PerpStateProof { @@ -1013,6 +1041,7 @@ mod tests { max_window_heights: 16, engine_program_log_height: 0, pending_heights: pending, + state_proof_keys: Vec::new(), } } diff --git a/crates/randprotocol-client/tests/wallet_flow.rs b/crates/randprotocol-client/tests/wallet_flow.rs index 1630c4b5..a0dd4d07 100644 --- a/crates/randprotocol-client/tests/wallet_flow.rs +++ b/crates/randprotocol-client/tests/wallet_flow.rs @@ -185,6 +185,7 @@ async fn start_configured(dir: &tempfile::TempDir, key: &Keypair, genesis: Genes // pays the policy floor it reads from `rand_getLimits`. gas_policy: Some(randprotocol_core::gas::GasPolicy::DEFAULT), msauth, + perps_keys: Default::default(), }) .await .expect("node starts") diff --git a/crates/randprotocol-core/src/confidential.rs b/crates/randprotocol-core/src/confidential.rs index 2eff5444..3a328924 100644 --- a/crates/randprotocol-core/src/confidential.rs +++ b/crates/randprotocol-core/src/confidential.rs @@ -90,7 +90,9 @@ pub struct ProofShape { /// that wrapper inherits the default. The private-multisig methods — `install_msauth_vk`, /// `enable_auth_multisig`, `build_msauth_key`, `auth_header`, `warm_auth_multisig` and /// `auth_multisig_key_ready` — have no default at all, so a wrapper that does not forward one -/// does not compile. +/// does not compile. The pinned state-proof key methods (CON-601) — `set_perp_pinned_keys`, +/// `install_perp_vk` and `perp_pinned_keys_installed` — have defaults (no pins, refuse, 0) and are +/// forwarded by both node wrappers (`CachingExecutor`, `AggExecutor`). pub trait ConfidentialExecutor: Send + Sync { /// Validate program code at deploy time (must be cheap: it runs inside block application) /// and return the code commitment recorded on chain. @@ -246,6 +248,23 @@ pub trait ConfidentialExecutor: Send + Sync { /// CON-60: the genesis perps section's `max_tier` and `engine_program_log_height` (0 = none), /// told once at genesis load. fn set_perp_config(&self, _max_tier: u8, _engine_program_log_height: u8) {} + /// CON-601: the genesis perps section's pinned state-proof keys (`state_proof_keys`: each + /// shape and the SHA-256 of its key file), told once at genesis load. With any set, the + /// executor verifies a state proof only under a key installed from its pinned file + /// ([`Self::install_perp_vk`]) and **never builds one**: a shape not pinned, or pinned but not + /// installed, is refused before any key is touched. A no-op by default. + fn set_perp_pinned_keys(&self, _pins: &[(ProofShape, [u8; 32])]) {} + /// CON-601: install one pinned state-proof key from its file's bytes — refused unless their + /// SHA-256 is one [`Self::set_perp_pinned_keys`] named (checked before anything is decoded), + /// the blob is for this executor's profile and constraint set, and its shape is that pin's. + /// Returns the shape installed. Refuses by default (no key cache to install into). + fn install_perp_vk(&self, _blob: &[u8]) -> Result { + Err("this executor holds no state-proof keys".into()) + } + /// CON-601: how many pinned state-proof keys are installed (0 by default). + fn perp_pinned_keys_installed(&self) -> usize { + 0 + } /// [`Self::decode_invoke`]'s twin for [`Self::verify_perp`]: everything but the STARK /// verification, the segment's digest still compared. The ledger never calls this; kept as /// `verify_perp`'s header twin (no production caller). Defaults to the full verify. diff --git a/crates/randprotocol-core/src/genesis.rs b/crates/randprotocol-core/src/genesis.rs index 675fe6ea..c65cf453 100644 --- a/crates/randprotocol-core/src/genesis.rs +++ b/crates/randprotocol-core/src/genesis.rs @@ -4851,6 +4851,7 @@ mod tests { max_window_heights: 0, engine_program_log_height: 0, max_pending_digests: 0, + state_proof_keys: Vec::new(), markets: vec![MarketSpec { id: 0, symbol: "BTC-PERP".into(), @@ -4889,6 +4890,38 @@ mod tests { let mut too_much = on.clone(); too_much.perps.as_mut().unwrap().initial_collateral = 1 << 63; assert!(matches!(too_much.build(&StubExecutor), Err(GenesisError::BadPerps(why)) if why.contains("initial_collateral"))); + // CON-601: the pinned state-proof keys — bound only when set, every pin bound, through the + // file and back; refused without the engine pin (the section's own check). + let mut keyed = on.clone(); + { + let k = keyed.perps.as_mut().unwrap(); + k.engine_program_log_height = 14; + k.state_proof_keys = crate::ledger::perps::canonical_state_proof_shapes(16, 14, 8) + .iter() + .map(|s| crate::ledger::perps::StateProofKeyPin { + tier: s.tier, + program_log_height: s.program_log_height, + input_log_height: s.input_log_height, + public_log_height: s.public_log_height, + poseidon2_log_height: s.poseidon2_log_height, + sha256: [0xab; 32], + }) + .collect(); + } + let mut pinned_only = on.clone(); + pinned_only.perps.as_mut().unwrap().engine_program_log_height = 14; + let keyed_g = build(&keyed); + assert_eq!(keyed_g.ledger.perps().unwrap().config.state_proof_keys.len(), 1, "8 blocks: one public height"); + assert_ne!(keyed_g.hash(), build(&pinned_only).hash(), "state_proof_keys is bound"); + assert!(keyed.to_json().contains("\"state_proof_keys\"")); + assert!(!pinned_only.to_json().contains("state_proof_keys"), "absent from a file that does not set it"); + assert_eq!(Genesis::from_json(&keyed.to_json()).unwrap(), keyed, "it round-trips"); + let mut moved = keyed.clone(); + moved.perps.as_mut().unwrap().state_proof_keys[0].sha256[0] = 0xac; + assert_ne!(build(&moved).hash(), keyed_g.hash(), "the digest is bound"); + let mut unpinned_engine = keyed.clone(); + unpinned_engine.perps.as_mut().unwrap().engine_program_log_height = 0; + assert!(matches!(unpinned_engine.build(&StubExecutor), Err(GenesisError::BadPerps(why)) if why.contains("state_proof_keys"))); let stray = on.to_json().replace("\"max_tier\"", "\"max_tiers\""); assert!(Genesis::from_json(&stray).is_err(), "a stray key is refused"); // Beside RPL-2's section too. diff --git a/crates/randprotocol-core/src/ledger/mod.rs b/crates/randprotocol-core/src/ledger/mod.rs index 61d5a9f1..ac6505eb 100644 --- a/crates/randprotocol-core/src/ledger/mod.rs +++ b/crates/randprotocol-core/src/ledger/mod.rs @@ -6468,6 +6468,7 @@ pub(crate) mod tests { max_window_heights: 0, engine_program_log_height: 0, max_pending_digests: 0, + state_proof_keys: Vec::new(), markets: vec![perps::MarketSpec { id: 0, symbol: "X-PERP".into(), diff --git a/crates/randprotocol-core/src/ledger/perps.rs b/crates/randprotocol-core/src/ledger/perps.rs index e44f7112..1e968c8f 100644 --- a/crates/randprotocol-core/src/ledger/perps.rs +++ b/crates/randprotocol-core/src/ledger/perps.rs @@ -218,6 +218,128 @@ pub struct PerpsConfig { /// 21), the log grows one digest a block until a proof lands. #[serde(default, skip_serializing_if = "is_zero_u64")] pub max_pending_digests: u64, + /// CON-601 (genesis-gated, default empty = unpinned): the state-proof verifier keys this chain + /// admits, each a shape and the SHA-256 of its precomputed key file. Set, a state proof whose + /// declared shape is not one listed here is refused `ProofRefused` from its header alone, at + /// validate and at apply, **before any verifier key is built**; and a node never builds a + /// listed key either — it loads each from the shipped file whose SHA-256 is listed + /// (`randprotocol-node`'s `perps_key`), and refuses to start without them. That is what lets a + /// 2 GB validator apply a block carrying a tier-18 state proof: the build peaks at ~3.3–4 GB, + /// the loaded key is ~14 KB (`docs/perps.md`, CON-601). Requires `engine_program_log_height`; + /// at most [`MAX_STATE_PROOF_KEYS`], in strictly increasing shape order. Empty (chain 21), + /// keys are built on demand under the CON-60 rules. + #[serde(default, skip_serializing_if = "Vec::is_empty")] + pub state_proof_keys: Vec, +} + +/// CON-601: the most state-proof keys a genesis may pin — the canonical cache's size +/// (`randprotocol-zkvm`'s `PERP_CANONICAL_KEYS`), where the node installs them. A chain's canonical +/// set is four (one per public height of a 1..=64-block window). +pub const MAX_STATE_PROOF_KEYS: usize = 8; + +/// CON-601: one pinned state-proof verifier key — the shape a state proof declares (its tier and +/// the declared table heights a key is built for; no keccak or sha256 table, the engine calls +/// neither) and the SHA-256 of the key file, the vendored machine's `VerifierKeyBlob::to_bytes()` +/// for that shape. Field order is the shape order the list is sorted in. +#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize)] +#[serde(deny_unknown_fields)] +pub struct StateProofKeyPin { + pub tier: u8, + pub program_log_height: u8, + pub input_log_height: u8, + pub public_log_height: u8, + pub poseidon2_log_height: u8, + /// Lowercase hex in the file. + #[serde(with = "sha256_hex")] + pub sha256: [u8; 32], +} + +impl StateProofKeyPin { + /// The proof shape this pin admits (no keccak or sha256 table). + pub fn shape(&self) -> crate::confidential::ProofShape { + crate::confidential::ProofShape { + tier: self.tier, + program_log_height: self.program_log_height, + input_log_height: self.input_log_height, + keccak_log_height: 0, + sha256_log_height: 0, + public_log_height: self.public_log_height, + poseidon2_log_height: self.poseidon2_log_height, + } + } + + /// Whether a proof declaring `shape` is the one this pin admits. + pub fn admits(&self, shape: &crate::confidential::ProofShape) -> bool { + self.shape() == *shape + } + + /// The pin's SHA-256 as lowercase hex. + pub fn sha256_hex(&self) -> String { + self.sha256.iter().map(|b| format!("{b:02x}")).collect() + } + + /// The shape's sort key: the five heights in field order. + fn shape_key(&self) -> [u8; 5] { + [self.tier, self.program_log_height, self.input_log_height, self.public_log_height, self.poseidon2_log_height] + } + + /// What the genesis hash binds per pin: the five heights, then the digest. + fn commit_bytes(&self, out: &mut Vec) { + out.extend_from_slice(&self.shape_key()); + out.extend_from_slice(&self.sha256); + } +} + +/// CON-601: the pinned state-proof shapes of a chain whose max tier is `max_tier` and whose engine +/// image's program height is `engine_program_log_height` — the canonical shapes +/// ([`canonical_input_log_height`]): tier `max_tier`, the tier's full poseidon2 height `t + 2` +/// (`rand perp prove` declares it at a pinned tier), and one per public height a window of +/// `1..=max_window_blocks` recorded blocks declares. The shapes only; the digests come from the key +/// files. What `deploy/cut-chain22-genesis.sh` pins and `rand-node keygen-perp-vk` exports. +pub fn canonical_state_proof_shapes(max_tier: u8, engine_program_log_height: u8, max_window_blocks: u64) -> Vec { + let mut publics: Vec = (1..=max_window_blocks.max(1)).map(|n| segment_public_log_height(state_proof_segment_words(n as usize))).collect(); + publics.dedup(); + publics + .into_iter() + .map(|public_log_height| crate::confidential::ProofShape { + tier: max_tier, + program_log_height: engine_program_log_height, + input_log_height: canonical_input_log_height(max_tier), + keccak_log_height: 0, + sha256_log_height: 0, + public_log_height, + poseidon2_log_height: max_tier.saturating_add(2), + }) + .collect() +} + +/// The fixed head of a state proof's public segment ([`state_proof_segment`]): the version, the +/// two heights, the two roots, the payouts digest, the fees and the block count. +pub const STATE_PROOF_SEGMENT_HEAD_WORDS: usize = 1 + 2 + 2 + 8 + 8 + 8 + 2 + 1; + +/// The length of the public segment of a state proof over `n` recorded blocks +/// ([`state_proof_segment`]): its fixed head and eight words a block. +pub fn state_proof_segment_words(n: usize) -> usize { + STATE_PROOF_SEGMENT_HEAD_WORDS + 8 * n +} + +mod sha256_hex { + use serde::{Deserialize, Deserializer, Serializer}; + pub fn serialize(d: &[u8; 32], s: S) -> Result { + s.serialize_str(&d.iter().map(|b| format!("{b:02x}")).collect::()) + } + pub fn deserialize<'de, D: Deserializer<'de>>(d: D) -> Result<[u8; 32], D::Error> { + let s = String::deserialize(d)?; + let bad = || serde::de::Error::custom(format!("sha256 {s:?} is not 64 lowercase hex characters")); + if s.len() != 64 || !s.bytes().all(|c| c.is_ascii_digit() || (b'a'..=b'f').contains(&c)) { + return Err(bad()); + } + let mut out = [0u8; 32]; + for (i, o) in out.iter_mut().enumerate() { + *o = u8::from_str_radix(&s[2 * i..2 * i + 2], 16).map_err(|_| bad())?; + } + Ok(out) + } } // Audit v10's fields are left out of a written genesis file while at their defaults, so a file this @@ -287,9 +409,60 @@ impl PerpsConfig { out.extend_from_slice(b"max_pending_digests"); out.extend_from_slice(&self.max_pending_digests.to_be_bytes()); } + // CON-601: the pinned state-proof keys, tagged, counted, each shape and digest. + if !self.state_proof_keys.is_empty() { + out.extend_from_slice(b"state_proof_keys"); + out.extend_from_slice(&(self.state_proof_keys.len() as u32).to_be_bytes()); + for k in &self.state_proof_keys { + k.commit_bytes(&mut out); + } + } out } + /// CON-601: the pin admitting a state proof of `shape`, when this chain pins its keys. + pub fn pinned_state_proof_key(&self, shape: &crate::confidential::ProofShape) -> Option<&StateProofKeyPin> { + self.state_proof_keys.iter().find(|k| k.admits(shape)) + } + + /// CON-601: [`PerpsConfig::state_proof_keys`]' own rules (part of [`Self::check`]). + fn check_state_proof_keys(&self) -> Result<(), String> { + let keys = &self.state_proof_keys; + if keys.is_empty() { + return Ok(()); + } + if self.engine_program_log_height == 0 { + return Err("perps.state_proof_keys is set without engine_program_log_height (the keys are for the pinned engine's shape)".into()); + } + if keys.len() > MAX_STATE_PROOF_KEYS { + return Err(format!("perps.state_proof_keys lists {} keys, more than {MAX_STATE_PROOF_KEYS}", keys.len())); + } + let max_public = segment_public_log_height(state_proof_segment_words(self.max_window_blocks as usize)); + for (i, k) in keys.iter().enumerate() { + let at = format!("perps.state_proof_keys[{i}]"); + if !TIERS.contains(&k.tier) || k.tier > self.max_tier { + return Err(format!("{at}: tier {} is not a proof tier at most max_tier {}", k.tier, self.max_tier)); + } + if k.program_log_height != self.engine_program_log_height { + return Err(format!("{at}: program height {} is not the engine's {}", k.program_log_height, self.engine_program_log_height)); + } + if !(1..=k.tier.saturating_add(2).min(16)).contains(&k.input_log_height) { + return Err(format!("{at}: input height {} is outside 1..={}", k.input_log_height, k.tier.saturating_add(2).min(16))); + } + if !(7..=max_public).contains(&k.public_log_height) { + return Err(format!("{at}: public height {} is outside 7..={max_public}, the heights a window of 1..={} blocks declares", k.public_log_height, self.max_window_blocks)); + } + let p2_max = k.tier + 2; + if k.poseidon2_log_height > p2_max || k.poseidon2_log_height < 8 || (p2_max - k.poseidon2_log_height) % 2 != 0 { + return Err(format!("{at}: poseidon2 height {} is not one a tier-{} proof declares (8, 10, …, {p2_max})", k.poseidon2_log_height, k.tier)); + } + if i > 0 && keys[i - 1].shape_key() >= k.shape_key() { + return Err(format!("{at}: the keys are not in strictly increasing shape order (a shape listed twice?)")); + } + } + Ok(()) + } + pub fn check(&self) -> Result<(), String> { if self.initial_collateral >= MAX_NOTE_VALUE { return Err(format!( @@ -330,6 +503,7 @@ impl PerpsConfig { )); } } + self.check_state_proof_keys()?; if self.engine_program_log_height > MAX_ENGINE_PROGRAM_LOG_HEIGHT { return Err(format!( "perps.engine_program_log_height {} is above {MAX_ENGINE_PROGRAM_LOG_HEIGHT}", @@ -521,7 +695,7 @@ pub fn state_proof_segment( fees: u64, digests: &[Word8], ) -> Vec { - let mut w = Vec::with_capacity(32 + 8 * digests.len()); + let mut w = Vec::with_capacity(state_proof_segment_words(digests.len())); w.push(PERP_VERSION); push_u64(&mut w, from); push_u64(&mut w, to); @@ -727,6 +901,17 @@ struct PerpsExt2 { max_pending_digests: u64, } +/// CON-601: the trailer's third version, written instead of the second only when the chain pins +/// its state-proof keys ([`PerpsConfig::state_proof_keys`]): [`PerpsExt2`]'s fields, then the +/// pins. A row without pins keeps writing the first or second version, byte for byte. +pub const PERSISTED_EXT_TAG_3: &[u8; 16] = b"rand-perps-ext-3"; + +#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize)] +struct PerpsExt3 { + v2: PerpsExt2, + state_proof_keys: Vec, +} + /// The owned twin of [`PerpsConfigV0`], for [`PerpsV0`]. #[derive(Serialize, Deserialize)] struct PerpsConfigV0Owned { @@ -819,7 +1004,14 @@ impl Perps { collateral_in: self.collateral_in, collateral_out: self.collateral_out, }; - if c.max_pending_digests != 0 { + if !c.state_proof_keys.is_empty() { + let ext3 = PerpsExt3 { + v2: PerpsExt2 { v1: ext, max_pending_digests: c.max_pending_digests }, + state_proof_keys: c.state_proof_keys.clone(), + }; + out.extend_from_slice(PERSISTED_EXT_TAG_3); + out.extend_from_slice(&bincode::serialize(&ext3).expect("serializes")); + } else if c.max_pending_digests != 0 { let ext2 = PerpsExt2 { v1: ext, max_pending_digests: c.max_pending_digests }; out.extend_from_slice(PERSISTED_EXT_TAG_2); out.extend_from_slice(&bincode::serialize(&ext2).expect("serializes")); @@ -840,15 +1032,17 @@ impl Perps { let v0: PerpsV0 = prefix.deserialize_from(&mut rest)?; let exact = || bincode::DefaultOptions::new().with_fixint_encoding().reject_trailing_bytes(); let ext = if rest.is_empty() { - PerpsExt2::default() + PerpsExt3::default() } else if let Some(body) = rest.strip_prefix(PERSISTED_EXT_TAG.as_slice()) { - PerpsExt2 { v1: exact().deserialize::(body)?, max_pending_digests: 0 } + PerpsExt3 { v2: PerpsExt2 { v1: exact().deserialize::(body)?, max_pending_digests: 0 }, state_proof_keys: Vec::new() } } else if let Some(body) = rest.strip_prefix(PERSISTED_EXT_TAG_2.as_slice()) { - exact().deserialize::(body)? + PerpsExt3 { v2: exact().deserialize::(body)?, state_proof_keys: Vec::new() } + } else if let Some(body) = rest.strip_prefix(PERSISTED_EXT_TAG_3.as_slice()) { + exact().deserialize::(body)? } else { return Err(Box::new(bincode::ErrorKind::Custom("perps row: an unknown trailer".into()))); }; - let PerpsExt2 { v1: ext, max_pending_digests } = ext; + let PerpsExt3 { v2: PerpsExt2 { v1: ext, max_pending_digests }, state_proof_keys } = ext; let c = v0.config; Ok(Perps { config: PerpsConfig { @@ -866,6 +1060,7 @@ impl Perps { max_window_heights: ext.max_window_heights, engine_program_log_height: ext.engine_program_log_height, max_pending_digests, + state_proof_keys, }, accounts: v0.accounts, oracle: v0.oracle, @@ -1606,6 +1801,16 @@ pub(super) fn verify_state_proof( )) .into()); } + // CON-601, under the genesis key pins: the declared shape must be one the chain pinned a + // key for — from the header alone, before the executor touches a key, so no block can + // make a validator build one (a node loads every pinned key from its file at startup). + if !c.state_proof_keys.is_empty() && c.pinned_state_proof_key(&shape).is_none() { + return Err(PerpError::ProofRefused(format!( + "declared shape {shape:?} is not one of the chain's {} pinned state-proof key shapes (perps.state_proof_keys)", + c.state_proof_keys.len() + )) + .into()); + } } let outcome = executor.verify_perp(&c.engine_hc, c.max_tier, segment, proof).map_err(|e| match e { ConfidentialError::CallTierTooHigh { tier, max } => PerpError::TierTooHigh { tier, max }, @@ -2198,6 +2403,7 @@ pub(crate) mod tests { max_window_heights: 0, engine_program_log_height: 0, max_pending_digests: 0, + state_proof_keys: Vec::new(), markets: vec![MarketSpec { id: 0, symbol: "X-PERP".into(), @@ -4191,6 +4397,124 @@ pub(crate) mod tests { assert!(serde_json::to_string(&pinned).unwrap().contains("\"engine_program_log_height\":14")); } + fn pin(shape: &crate::confidential::ProofShape, d: u8) -> StateProofKeyPin { + StateProofKeyPin { + tier: shape.tier, + program_log_height: shape.program_log_height, + input_log_height: shape.input_log_height, + public_log_height: shape.public_log_height, + poseidon2_log_height: shape.poseidon2_log_height, + sha256: [d; 32], + } + } + + /// CON-601: under the genesis' pinned state-proof keys a proof declaring any shape not listed + /// — another input height, another tier — is refused from its header at validate and at + /// apply, before the executor is asked (the stub counts the key builds verifying would cost: + /// none); a pinned shape is verified as before. Without the field (chain 21) the same proofs + /// verify, as before. + #[test] + fn con601_under_pinned_keys_an_unpinned_shape_is_refused_before_any_key() { + use crate::confidential::{stub_perp_key_builds, STUB_PERP_PROGRAM_LOG_HEIGHT as PLH}; + let (mut l, request) = withdrawn(5); + let payouts = vec![PerpPayout { request, amount: 5 }]; + let seg = segment_on(&l, 0, 2, &[7; 8], &payouts, 0); + let at = |tier: u8, h: [u8; 4]| proof_tx(0, 2, [7; 8], payouts.clone(), 0, StubExecutor::make_perp_proof_shaped(&ENGINE, tier, outs(2), &seg, h)); + let pinned_shape = StubExecutor.perp_proof_shape(&StubExecutor::make_perp_proof_shaped(&ENGINE, 16, outs(2), &seg, [PLH, 3, 0, 0])).unwrap(); + l.perps_mut().unwrap().config.engine_program_log_height = PLH; + let unpinned = [(16, [PLH, 4, 0, 0]), (14, [PLH, 3, 0, 0])]; + for (t, h) in unpinned { + assert_eq!(l.validate(&at(t, h), &StubExecutor), Ok(()), "no pins: {t} {h:?} verifies"); + } + l.perps_mut().unwrap().config.state_proof_keys = vec![pin(&pinned_shape, 1)]; + assert_eq!(l.validate(&at(16, [PLH, 3, 0, 0]), &StubExecutor), Ok(()), "the pinned shape verifies"); + let builds = stub_perp_key_builds(); + for (t, h) in unpinned { + match refusal(&l, &at(t, h)) { + TxError::Perps(PerpError::ProofRefused(why)) => assert!(why.contains("pinned state-proof key shapes"), "{why}"), + e => panic!("{t} {h:?}: {e:?}"), + } + } + assert_eq!(stub_perp_key_builds(), builds, "refused before the executor: no key build"); + // And at apply: refused, nothing written. + l.set_height(3); + let before = l.clone(); + assert!(apply(&mut l, &at(16, [PLH, 4, 0, 0])).is_err()); + assert!(l == before); + assert_eq!(stub_perp_key_builds(), builds); + } + + /// CON-601: the `state_proof_keys` field — checked, written to the file and bound into the + /// section's commit (so the genesis hash) only when set, round-tripped through JSON and the + /// node's persisted row; the chain-21 section's bytes do not move. + #[test] + fn con601_state_proof_keys_are_checked_and_bound_only_when_set() { + let mut c = sample_config(); + c.max_tier = 18; + c.max_window_blocks = 64; + let base = c.commit_bytes(); + let json = serde_json::to_value(&c).unwrap(); + assert!(!json.as_object().unwrap().contains_key("state_proof_keys"), "written only when set"); + assert_eq!(serde_json::from_value::(json).unwrap(), c, "absent means unpinned"); + let shapes = canonical_state_proof_shapes(18, 14, 64); + assert_eq!(shapes.iter().map(|s| (s.tier, s.input_log_height, s.public_log_height, s.poseidon2_log_height)).collect::>(), + vec![(18, 16, 7, 20), (18, 16, 8, 20), (18, 16, 9, 20), (18, 16, 10, 20)]); + let mut pinned = c.clone(); + pinned.state_proof_keys = shapes.iter().enumerate().map(|(i, s)| pin(s, i as u8 + 1)).collect(); + assert!(pinned.check().unwrap_err().contains("without engine_program_log_height")); + pinned.engine_program_log_height = 14; + let eplh = pinned.commit_bytes(); + assert_eq!(pinned.check(), Ok(())); + let mut want = [base.clone(), b"engine_program_log_height".to_vec(), vec![14], b"state_proof_keys".to_vec(), 4u32.to_be_bytes().to_vec()].concat(); + for (i, s) in shapes.iter().enumerate() { + want.extend_from_slice(&[18, 14, 16, s.public_log_height, 20]); + want.extend_from_slice(&[i as u8 + 1; 32]); + } + assert_eq!(eplh, want); + // Every byte of a pin moves the commit. + let mut other = pinned.clone(); + other.state_proof_keys[3].sha256[31] ^= 1; + assert_ne!(other.commit_bytes(), pinned.commit_bytes()); + // JSON: lowercase hex, round trip; a bad digest does not parse. + let text = serde_json::to_string(&pinned).unwrap(); + assert!(text.contains(&format!("\"sha256\":\"{}\"", "01".repeat(32))), "{text}"); + assert_eq!(serde_json::from_str::(&text).unwrap(), pinned); + assert!(serde_json::from_str::(&text.replace(&"01".repeat(32), &"0G".repeat(32))).is_err()); + assert!(serde_json::from_str::(&text.replace(&"01".repeat(32), &"01".repeat(31))).is_err()); + // The rules. + let bad = |f: &dyn Fn(&mut PerpsConfig)| { + let mut b = pinned.clone(); + f(&mut b); + b.check().unwrap_err() + }; + assert!(bad(&|b| b.state_proof_keys[0].tier = 20).contains("tier 20")); + assert!(bad(&|b| b.state_proof_keys[0].program_log_height = 15).contains("not the engine's 14")); + assert!(bad(&|b| b.state_proof_keys[0].public_log_height = 11).contains("public height 11")); + assert!(bad(&|b| b.state_proof_keys[0].poseidon2_log_height = 19).contains("poseidon2 height 19")); + assert!(bad(&|b| b.state_proof_keys[0].input_log_height = 17).contains("input height 17")); + assert!(bad(&|b| b.state_proof_keys.swap(0, 1)).contains("strictly increasing")); + assert!(bad(&|b| b.state_proof_keys[1] = b.state_proof_keys[0]).contains("strictly increasing")); + assert!(bad(&|b| { + let k = b.state_proof_keys[0]; + b.state_proof_keys = (0..9).map(|i| StateProofKeyPin { poseidon2_log_height: 4 + 2 * i, ..k }).collect(); + }) + .contains("more than 8")); + // The persisted row carries it (ext-3), and a row without it keeps its old trailer. + let (l, _) = withdrawn(5); + let mut p = l.perps().unwrap().clone(); + let old_row = p.encode_persisted(); + p.config.engine_program_log_height = 14; + p.config.state_proof_keys = pinned.state_proof_keys.clone(); + let row = p.encode_persisted(); + assert!(row.windows(16).any(|w| w == PERSISTED_EXT_TAG_3)); + assert_eq!(Perps::decode_persisted(&row).unwrap().config, p.config); + p.config.max_pending_digests = 64; + assert_eq!(Perps::decode_persisted(&p.encode_persisted()).unwrap().config, p.config); + p.config.state_proof_keys.clear(); + assert!(!p.encode_persisted().windows(16).any(|w| w == PERSISTED_EXT_TAG_3)); + assert!(!old_row.windows(16).any(|w| w == PERSISTED_EXT_TAG_3)); + } + /// CON-60: the canonical shape's formula, and its four public heights over 1..=64 blocks. #[test] fn the_canonical_shape_is_the_documented_formula() { diff --git a/crates/randprotocol-node/src/agg_executor.rs b/crates/randprotocol-node/src/agg_executor.rs index 049d13bd..42815b5f 100644 --- a/crates/randprotocol-node/src/agg_executor.rs +++ b/crates/randprotocol-node/src/agg_executor.rs @@ -701,6 +701,18 @@ impl ConfidentialExecutor for AggExecutor { self.inner.set_perp_config(max_tier, engine_program_log_height) } + fn set_perp_pinned_keys(&self, pins: &[(randprotocol_core::confidential::ProofShape, [u8; 32])]) { + self.inner.set_perp_pinned_keys(pins) + } + + fn install_perp_vk(&self, blob: &[u8]) -> Result { + self.inner.install_perp_vk(blob) + } + + fn perp_pinned_keys_installed(&self) -> usize { + self.inner.perp_pinned_keys_installed() + } + /// The keys an `Invoke` verifies under are these too: its segment sits in the hardened /// call's public table (`program_state::segment_fits`), so it declares no shape a call to /// the same program does not. diff --git a/crates/randprotocol-node/src/lib.rs b/crates/randprotocol-node/src/lib.rs index 89087777..5c2468b9 100644 --- a/crates/randprotocol-node/src/lib.rs +++ b/crates/randprotocol-node/src/lib.rs @@ -14,6 +14,7 @@ pub mod rlimit; pub mod keyfile; pub mod mempool; pub mod msauth_key; +pub mod perps_key; pub mod network; pub mod node; pub mod peer_bindings; diff --git a/crates/randprotocol-node/src/main.rs b/crates/randprotocol-node/src/main.rs index 78a5c70a..6b8130af 100644 --- a/crates/randprotocol-node/src/main.rs +++ b/crates/randprotocol-node/src/main.rs @@ -1066,6 +1066,12 @@ enum Cmd { /// (~80 s, ~4 GB at production) instead of refusing to start. Never set by a deploy script. #[arg(long)] build_msauth_key: bool, + /// CON-601: the directory holding the pinned perps state-proof key files (read only on a + /// chain whose genesis lists `perps.state_proof_keys`). Default: `$RAND_PERPS_KEY_DIR`, + /// else this binary's own directory (`/usr/local/bin` on the fleet). A missing or unpinned + /// file refuses the start; a pinned key is never built. + #[arg(long, value_name = "DIR")] + perps_key_dir: Option, }, /// Verify the chain in a data directory without running the node. Verify { @@ -1082,6 +1088,9 @@ enum Cmd { /// `hc_auth_multisig`; a missing or unpinned file refuses the verify — it never builds). #[arg(long, value_name = "PATH")] msauth_vk: Option, + /// CON-601: the pinned perps state-proof key files' directory, as for `run`. + #[arg(long, value_name = "DIR")] + perps_key_dir: Option, }, /// Database maintenance on a stopped node's data directory. Db { @@ -1236,6 +1245,34 @@ enum Cmd { #[arg(long, value_name = "PROFILE", conflicts_with_all = ["profile", "out"])] print_pinned: Option, }, + /// CON-601: the pinned perps state-proof verifier keys. `--profile P --out-dir DIR` builds + /// each canonical shape's key for `--max-tier` / `--engine-program-log-height` / + /// `--max-window-blocks` (chain 22's 18 / 14 / 64 by default; a big host: ~3.3–4 GB a tier-18 + /// key) and writes `DIR/perp-vk--t…-p2h….bin`, printing ` sha256 bytes + /// ` per key; `--check FILE` prints a file's SHA-256; `--print-pinned P` prints this build's + /// chain-22 files and digests; `--genesis-json DIR` prints the `perps.state_proof_keys` list + /// for the files in DIR. A validator loads the files from beside its binary and never builds. + KeygenPerpVk { + #[arg(long, requires = "out_dir")] + profile: Option, + #[arg(long, requires = "profile")] + out_dir: Option, + #[arg(long, default_value_t = randprotocol_zkvm::executor::perp_vk::CHAIN22_MAX_TIER)] + max_tier: u8, + #[arg(long, default_value_t = randprotocol_zkvm::executor::perp_vk::CHAIN22_ENGINE_PROGRAM_LOG_HEIGHT)] + engine_program_log_height: u8, + #[arg(long, default_value_t = randprotocol_zkvm::executor::perp_vk::CHAIN22_MAX_WINDOW_BLOCKS)] + max_window_blocks: u64, + /// Only the shape with this public height (with `--out-dir`; one key per run). + #[arg(long)] + public_log_height: Option, + #[arg(long, conflicts_with_all = ["profile", "out_dir", "print_pinned", "genesis_json"])] + check: Option, + #[arg(long, value_name = "PROFILE", conflicts_with_all = ["profile", "out_dir", "genesis_json"])] + print_pinned: Option, + #[arg(long, value_name = "DIR", conflicts_with_all = ["profile", "out_dir"])] + genesis_json: Option, + }, /// Benchmarks of the node's own paths; no network, no database. Bench { #[command(subcommand)] @@ -2792,6 +2829,32 @@ async fn main() -> Result<()> { anyhow::bail!("keygen-msauth-vk: give --profile P --out FILE, --check FILE or --print-pinned P"); } } + Cmd::KeygenPerpVk { profile, out_dir, max_tier, engine_program_log_height, max_window_blocks, public_log_height, check, print_pinned, genesis_json } => { + use randprotocol_node::perps_key; + use randprotocol_zkvm::executor::perp_vk; + let shapes = randprotocol_core::ledger::perps::canonical_state_proof_shapes(max_tier, engine_program_log_height, max_window_blocks); + if let Some(p) = print_pinned { + let profile = randprotocol_node::msauth_key::parse_profile(&p)?; + for (shape, pin) in perp_vk::chain22_pins(profile) { + println!("{} {pin}", perp_vk::file_name(profile, &shape)); + } + } else if let Some(f) = check { + println!("{}", randprotocol_node::msauth_key::check_file(&f)?); + } else if let Some(dir) = genesis_json { + println!("{}", serde_json::to_string(&perps_key::genesis_json(randprotocol_zkvm::machine::FriProfile::Production, &shapes, &dir)?)?); + } else if let (Some(p), Some(out)) = (profile, out_dir) { + let profile = randprotocol_node::msauth_key::parse_profile(&p)?; + let shapes: Vec<_> = shapes.into_iter().filter(|s| public_log_height.is_none_or(|h| s.public_log_height == h)).collect(); + anyhow::ensure!(!shapes.is_empty(), "keygen-perp-vk: no canonical shape has public height {public_log_height:?}"); + let t0 = std::time::Instant::now(); + for (name, digest, bytes) in perps_key::keygen(profile, &shapes, &out)? { + println!("{name} sha256 {digest} bytes {bytes}"); + } + eprintln!("wrote {} keys into {} in {:.1?}", shapes.len(), out.display(), t0.elapsed()); + } else { + anyhow::bail!("keygen-perp-vk: give --profile P --out-dir DIR, --check FILE, --print-pinned P or --genesis-json DIR"); + } + } Cmd::Keygen { out } => { let kp = Keypair::generate(); // Never over an existing file (VK-7): the key at `out` may be the only copy of a seed. @@ -3228,7 +3291,7 @@ async fn main() -> Result<()> { println!("initialised {} at genesis {} (chain id {})", datadir.display(), gs.hash(), gs.chain_id); println!("{}", gas_summary(gs.ledger.gas())); } - Cmd::Verify { datadir, mode, repair, msauth_vk } => { + Cmd::Verify { datadir, mode, repair, msauth_vk, perps_key_dir } => { let mode: VerifyMode = mode.parse().map_err(|e: String| anyhow::anyhow!(e))?; let (gs, executor) = node::load_genesis(&datadir)?; refuse_test_fri_profile(&gs.fri_profile, test_profile_allowed)?; @@ -3245,6 +3308,9 @@ async fn main() -> Result<()> { ); // The pinned msauth key, loaded as `run` loads it: a replay must never build it. randprotocol_node::msauth_key::verify_startup(&gs, msauth_vk, executor.as_ref()).map_err(|e| anyhow::anyhow!("{e:#}; refusing to verify"))?; + // CON-601: and the pinned perps state-proof keys, loaded as `run` loads them. + randprotocol_node::perps_key::startup(&gs, &randprotocol_node::perps_key::PerpsKeyOptions { dir: perps_key_dir }, executor.as_ref()) + .map_err(|e| anyhow::anyhow!("{e:#}; refusing to verify"))?; let storage = Storage::open(&datadir)?; let check = node::verify_store(&storage, &gs, mode, executor.as_ref())?; match &check.problem { @@ -3281,6 +3347,7 @@ async fn main() -> Result<()> { Cmd::Run { msauth_vk, build_msauth_key, + perps_key_dir, datadir, key, listen, @@ -3396,6 +3463,7 @@ async fn main() -> Result<()> { prune_history, gas_policy: randprotocol_core::gas::GasPolicy::from_prices(gas_price, byte_price), msauth: randprotocol_node::msauth_key::MsauthKeyOptions { path: msauth_vk, build: build_msauth_key }, + perps_keys: randprotocol_node::perps_key::PerpsKeyOptions { dir: perps_key_dir }, }, rpc_options, node::NetOptions { reserved_peers: reserved_peer, strict_gossip, diff --git a/crates/randprotocol-node/src/msauth_key.rs b/crates/randprotocol-node/src/msauth_key.rs index cc52faed..caf125bd 100644 --- a/crates/randprotocol-node/src/msauth_key.rs +++ b/crates/randprotocol-node/src/msauth_key.rs @@ -440,6 +440,7 @@ mod tests { prune_history: None, gas_policy: None, msauth, + perps_keys: Default::default(), } } diff --git a/crates/randprotocol-node/src/node.rs b/crates/randprotocol-node/src/node.rs index b9306407..15e608a8 100644 --- a/crates/randprotocol-node/src/node.rs +++ b/crates/randprotocol-node/src/node.rs @@ -101,6 +101,9 @@ pub struct NodeConfig { /// Where the precomputed msauth verifier key is read from, and whether a missing one may be /// built here (plan Task 2b; consulted only on a chain naming `hc_auth_multisig`). pub msauth: crate::msauth_key::MsauthKeyOptions, + /// CON-601: where the pinned perps state-proof key files are read from (consulted only on a + /// chain whose genesis lists `perps.state_proof_keys`). + pub perps_keys: crate::perps_key::PerpsKeyOptions, } /// Handles returned by `Node::start` so tests and the CLI can observe the node. @@ -186,6 +189,9 @@ pub fn load_genesis(datadir: &std::path::Path) -> Result<(GenesisState, Arc`, else +//! `RAND_PERPS_KEY_DIR`, else the running binary's own directory (`/usr/local/bin` on the fleet) +//! — one file per pinned shape, named by +//! `randprotocol_zkvm::executor::perp_vk::file_name`. A missing file or one whose SHA-256 is not +//! the genesis' pin refuses the start. There is no build fallback at all: a pinned key is never +//! built by a node (`rand-node keygen-perp-vk` builds the files, on a big host). +//! +//! Only a developer's binary, run from this tree's `target/`, falls back to the committed files in +//! `crates/randprotocol-zkvm/keys/` (a debug build, or `RAND_PERPS_KEY_DEV_FALLBACK=1`), as the +//! msauth key does. + +use anyhow::{anyhow, bail, Context, Result}; +use randprotocol_core::confidential::{ConfidentialExecutor, ProofShape}; +use randprotocol_core::ledger::perps::StateProofKeyPin; +use randprotocol_zkvm::executor::perp_vk; +use randprotocol_zkvm::machine::FriProfile; +use serde::Serialize; +use std::path::{Path, PathBuf}; + +/// The environment variable that overrides the key directory (after `--perps-key-dir`). +pub const ENV_DIR: &str = "RAND_PERPS_KEY_DIR"; +/// The environment variable that lets a release build run from a checkout's `target/` read the +/// committed files (debug builds there need no flag). +pub const ENV_DEV_FALLBACK: &str = "RAND_PERPS_KEY_DEV_FALLBACK"; + +/// How `run` (and `verify`) find the pinned key files. +#[derive(Clone, Debug, Default)] +pub struct PerpsKeyOptions { + /// `--perps-key-dir `; `None` falls back to `RAND_PERPS_KEY_DIR`, then to the directory + /// of the running binary. + pub dir: Option, +} + +/// Where this node's state-proof keys come from: `rand_status.perps_keys`. +#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Serialize)] +pub struct PerpsKeyStatus { + /// `"loaded"` — every pinned key installed from its file — or `"absent"`: the chain pins no + /// state-proof key (no perps, or chain 21's on-demand builds). + pub source: PerpsKeySource, + /// How many pinned keys this node holds (the genesis' count when `loaded`). + pub keys: usize, +} + +#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Serialize)] +#[serde(rename_all = "snake_case")] +pub enum PerpsKeySource { + /// Every pinned key installed from its file. + Loaded, + /// The chain pins no state-proof key. + #[default] + Absent, +} + +/// The chain's pinned keys (`perps.state_proof_keys`), empty on a chain without them. +pub fn chain_pins(gs: &randprotocol_core::genesis::GenesisState) -> Vec { + gs.ledger.perps().map(|p| p.config.state_proof_keys.clone()).unwrap_or_default() +} + +/// `node::load_genesis`'s step: tell the bare executor the pins, so it is in pinned mode (never a +/// state-proof key build) before any caller sees it. +pub fn set_pins(gs: &randprotocol_core::genesis::GenesisState, executor: &dyn ConfidentialExecutor) { + let pins: Vec<(ProofShape, [u8; 32])> = chain_pins(gs).iter().map(|k| (k.shape(), k.sha256)).collect(); + executor.set_perp_pinned_keys(&pins); +} + +/// The directory this node reads: `--perps-key-dir`, else `RAND_PERPS_KEY_DIR`, else the running +/// binary's directory — and for a developer's binary under this tree's `target/` (a debug build, +/// or `RAND_PERPS_KEY_DEV_FALLBACK=1`), the committed `crates/randprotocol-zkvm/keys/` when the +/// binary's directory lacks `first`'s file. +pub fn resolve_dir(opts: &PerpsKeyOptions, first: Option<&str>) -> Result { + if let Some(d) = &opts.dir { + return Ok(d.clone()); + } + if let Some(d) = std::env::var_os(ENV_DIR).filter(|d| !d.is_empty()) { + return Ok(PathBuf::from(d)); + } + let exe = std::env::current_exe().context("locating the running binary for the perps key files")?; + let opted_in = cfg!(debug_assertions) || std::env::var_os(ENV_DEV_FALLBACK).is_some_and(|v| v == "1"); + Ok(default_dir(&exe, first, opted_in)) +} + +/// [`resolve_dir`]'s default for an executable at `exe`. +pub fn default_dir(exe: &Path, first: Option<&str>, opted_in: bool) -> PathBuf { + let beside = exe.parent().map(Path::to_path_buf).unwrap_or_else(|| PathBuf::from(".")); + if let Some(name) = first { + if opted_in && !beside.join(name).exists() && in_source_target(exe) && source_tree_dir().join(name).exists() { + return source_tree_dir(); + } + } + beside +} + +fn source_root() -> PathBuf { + Path::new(env!("CARGO_MANIFEST_DIR")).join("../..") +} + +fn in_source_target(exe: &Path) -> bool { + let (Ok(exe), Ok(target)) = (exe.canonicalize(), source_root().join("target").canonicalize()) else { + return false; + }; + exe.starts_with(target) +} + +/// The committed key files in a source tree: `crates/randprotocol-zkvm/keys/`. +pub fn source_tree_dir() -> PathBuf { + source_root().join("crates/randprotocol-zkvm/keys") +} + +/// The startup obligation: on a chain without pins, `Absent` and nothing is read. Otherwise each +/// pin's file in `dir` is read and installed through `executor` (which checks the bytes' SHA-256 +/// against the pins before decoding, then the profile and the shape); every pin must load, or the +/// error names the file, the digest it has and the one the genesis pins. +pub fn load_keys( + pins: &[StateProofKeyPin], + profile: FriProfile, + dir: &Path, + executor: &dyn ConfidentialExecutor, +) -> Result { + if pins.is_empty() { + return Ok(PerpsKeyStatus::default()); + } + for pin in pins { + let shape = pin.shape(); + let path = dir.join(perp_vk::file_name(profile, &shape)); + let want = pin.sha256_hex(); + let bytes = std::fs::read(&path).map_err(|e| { + anyhow!( + "perps state-proof key: {} missing ({e}) (genesis perps.state_proof_keys pins sha256 {want} for {shape:?}); install the release's perp-vk files beside rand-node, or point --perps-key-dir at them", + path.display() + ) + })?; + let got = perp_vk::digest(&bytes); + if got != want { + bail!( + "perps state-proof key: {} has sha256 {got}, not the {want} genesis perps.state_proof_keys pins for {shape:?}; install the release's perp-vk files", + path.display() + ); + } + let installed = executor + .install_perp_vk(&bytes) + .map_err(|e| anyhow!("perps state-proof key: {} (sha256 {got}) was refused: {e}", path.display()))?; + if installed != shape { + bail!("perps state-proof key: {} installed as {installed:?}, not the pinned {shape:?}", path.display()); + } + } + let keys = executor.perp_pinned_keys_installed(); + if keys != pins.len() { + bail!("perps state-proof keys: {keys} of the {} pinned keys are installed", pins.len()); + } + tracing::info!("perps state-proof keys: {keys} pinned keys loaded from {}", dir.display()); + Ok(PerpsKeyStatus { source: PerpsKeySource::Loaded, keys }) +} + +/// `node::start_with`'s step (and `rand-node verify`'s): [`resolve_dir`] and [`load_keys`] into +/// `executor` (the bare one). An `Err` is a startup failure. +pub fn startup( + gs: &randprotocol_core::genesis::GenesisState, + opts: &PerpsKeyOptions, + executor: &dyn ConfidentialExecutor, +) -> Result { + let pins = chain_pins(gs); + if pins.is_empty() { + return Ok(PerpsKeyStatus::default()); + } + let profile = crate::msauth_key::parse_profile(&gs.fri_profile)?; + let first = perp_vk::file_name(profile, &pins[0].shape()); + let dir = resolve_dir(opts, Some(&first))?; + load_keys(&pins, profile, &dir, executor) +} + +/// `rand-node keygen-perp-vk --profile

--out-dir

[--max-tier T --engine-program-log-height H --max-window-blocks N]`: +/// build each canonical shape's key (a big host at tier 18) and write `/` (never +/// over an existing file). Returns `(file name, sha256, size)` per shape, in shape order — what +/// `perps.state_proof_keys` lists. +pub fn keygen(profile: FriProfile, shapes: &[ProofShape], out_dir: &Path) -> Result> { + let mut out = Vec::new(); + for shape in shapes { + let name = perp_vk::file_name(profile, shape); + let path = out_dir.join(&name); + if path.exists() { + bail!("{} exists; refusing to overwrite a key file", path.display()); + } + let t0 = std::time::Instant::now(); + let blob = perp_vk::blob(profile, shape).map_err(|e| anyhow!("building the state-proof key: {e}"))?; + let mut f = std::fs::OpenOptions::new() + .write(true) + .create_new(true) + .open(&path) + .with_context(|| format!("creating {}", path.display()))?; + std::io::Write::write_all(&mut f, &blob).with_context(|| format!("writing {}", path.display()))?; + tracing::info!("{name}: built in {:.1} s", t0.elapsed().as_secs_f64()); + out.push((name, perp_vk::digest(&blob), blob.len())); + } + Ok(out) +} + +/// The `state_proof_keys` JSON for `shapes` and their files' digests in `dir` — what the cut +/// splices into the genesis (`rand-node keygen-perp-vk --genesis-json `). +pub fn genesis_json(profile: FriProfile, shapes: &[ProofShape], dir: &Path) -> Result { + let mut keys = Vec::new(); + for s in shapes { + let path = dir.join(perp_vk::file_name(profile, s)); + let bytes = std::fs::read(&path).with_context(|| format!("reading {}", path.display()))?; + keys.push(serde_json::json!({ + "tier": s.tier, + "program_log_height": s.program_log_height, + "input_log_height": s.input_log_height, + "public_log_height": s.public_log_height, + "poseidon2_log_height": s.poseidon2_log_height, + "sha256": perp_vk::digest(&bytes), + })); + } + Ok(serde_json::Value::Array(keys)) +} + +#[cfg(test)] +mod tests { + use super::*; + use randprotocol_core::confidential::ConfidentialError; + use randprotocol_core::ledger::perps::canonical_state_proof_shapes; + use randprotocol_zkvm::executor::{prove_perp, ZkExecutor}; + + /// A tier-10 perps-shaped proof (the fib guest standing in for the engine) and the canonical + /// pinned shapes of a `max_tier` 10 chain at its program height, with their key blobs + /// exported from a separate machine. + type Fixture = (Vec, [u32; 8], Vec, ProofShape, Vec<(ProofShape, Vec)>); + + fn fixture() -> Fixture { + let program = randprotocol_zkvm::guests::fib(10); + let segment: Vec = (0..40).collect(); + let (bytes, _, _) = prove_perp(FriProfile::Test, &program, &[], &segment, Some(10)).unwrap(); + let shape = randprotocol_zkvm::executor::proof_shape(&bytes).unwrap(); + let shapes = canonical_state_proof_shapes(10, shape.program_log_height, 64) + .into_iter() + .map(|s| ProofShape { input_log_height: shape.input_log_height, ..s }) + .collect::>(); + assert!(shapes.contains(&shape), "{shape:?} among {shapes:?}"); + let blobs = shapes.iter().map(|s| (*s, perp_vk::blob(FriProfile::Test, s).unwrap())).collect(); + (bytes, program.digest(), segment, shape, blobs) + } + + fn pins_of(blobs: &[(ProofShape, Vec)]) -> Vec { + blobs + .iter() + .map(|(s, b)| StateProofKeyPin { + tier: s.tier, + program_log_height: s.program_log_height, + input_log_height: s.input_log_height, + public_log_height: s.public_log_height, + poseidon2_log_height: s.poseidon2_log_height, + sha256: randprotocol_zkvm::sha256::sha256(b), + }) + .collect() + } + + fn pinned_executor(pins: &[StateProofKeyPin]) -> ZkExecutor { + let ex = ZkExecutor::new(FriProfile::Test); + ex.set_perp_config(10, pins[0].program_log_height); + ex.set_perp_pinned_keys(&pins.iter().map(|k| (k.shape(), k.sha256)).collect::>()); + ex + } + + fn write_blobs(dir: &Path, blobs: &[(ProofShape, Vec)]) { + for (s, b) in blobs { + std::fs::write(dir.join(perp_vk::file_name(FriProfile::Test, s)), b).unwrap(); + } + } + + /// A pinned shape verifies under the key loaded from its file — through the node's loader — + /// with no state-proof key built. + #[test] + fn a_pinned_shape_verifies_under_the_loaded_blob_with_no_build() { + let (bytes, hc, segment, _, blobs) = fixture(); + let pins = pins_of(&blobs); + let dir = tempfile::tempdir().unwrap(); + write_blobs(dir.path(), &blobs); + let ex = pinned_executor(&pins); + let status = load_keys(&pins, FriProfile::Test, dir.path(), &ex).unwrap(); + assert_eq!(status, PerpsKeyStatus { source: PerpsKeySource::Loaded, keys: pins.len() }); + ex.verify_perp(&hc, 10, &segment, &bytes).expect("the pinned shape verifies"); + assert!(ex.perp_proof_admissible(&bytes, &hc, 10, &segment, pins[0].program_log_height)); + assert_eq!(ex.perp_key_builds(), 0, "verified under the loaded key: nothing built"); + } + + /// A shape the genesis does not pin is refused before any key is built — by the verify path + /// and the pool's pre-screen alike — even on an executor holding every pinned key. + #[test] + fn an_unpinned_shape_is_refused_with_no_build() { + let (bytes, hc, segment, shape, blobs) = fixture(); + // Pin every canonical shape but the proof's own. + let others: Vec<_> = blobs.iter().filter(|(s, _)| *s != shape).cloned().collect(); + let pins = pins_of(&others); + let dir = tempfile::tempdir().unwrap(); + write_blobs(dir.path(), &others); + let ex = pinned_executor(&pins); + load_keys(&pins, FriProfile::Test, dir.path(), &ex).unwrap(); + match ex.verify_perp(&hc, 10, &segment, &bytes) { + Err(ConfidentialError::InvalidProof(why)) => assert!(why.contains("not one of the chain's"), "{why}"), + other => panic!("{other:?}"), + } + assert!(!ex.perp_proof_admissible(&bytes, &hc, 10, &segment, shape.program_log_height)); + // Neither a warm nor a keep builds it either. + ex.warm_perp(&shape); + ex.keep_perp_key(&shape); + assert_eq!(ex.perp_key_builds(), 0); + // And a pinned shape whose file was never installed is refused, not built. + let ex = pinned_executor(&pins_of(&blobs)); + match ex.verify_perp(&hc, 10, &segment, &bytes) { + Err(ConfidentialError::InvalidProof(why)) => assert!(why.contains("is not loaded on this node"), "{why}"), + other => panic!("{other:?}"), + } + assert_eq!(ex.perp_key_builds(), 0); + } + + /// A missing file and a file whose SHA-256 is not the pin both fail the load, naming the file + /// and the expected digest, and install nothing; so does a pinned digest whose bytes are for + /// another shape (a genesis pinning shape A with B's file's digest). + #[test] + fn a_missing_or_mismatched_blob_is_refused() { + let (_, _, _, _, blobs) = fixture(); + let pins = pins_of(&blobs); + let dir = tempfile::tempdir().unwrap(); + let ex = pinned_executor(&pins); + let e = format!("{:#}", load_keys(&pins, FriProfile::Test, dir.path(), &ex).unwrap_err()); + let first = dir.path().join(perp_vk::file_name(FriProfile::Test, &pins[0].shape())); + assert!(e.contains(&first.display().to_string()) && e.contains("missing") && e.contains(&pins[0].sha256_hex()), "{e}"); + // A flipped byte: its digest is not the pin. + write_blobs(dir.path(), &blobs); + let mut bad = blobs[0].1.clone(); + *bad.last_mut().unwrap() ^= 1; + std::fs::write(&first, &bad).unwrap(); + let e = format!("{:#}", load_keys(&pins, FriProfile::Test, dir.path(), &ex).unwrap_err()); + assert!(e.contains(&perp_vk::digest(&bad)) && e.contains(&pins[0].sha256_hex()), "{e}"); + assert_eq!(ex.perp_pinned_keys_installed(), 0); + // The executor itself refuses unpinned bytes before decoding them. + assert!(ex.install_perp_vk(b"junk").unwrap_err().contains("none of the")); + // Swapped digests: shape 0 pinned with shape 1's file's digest and vice versa. + let mut swapped = pins.clone(); + let (a, b) = (swapped[0].sha256, swapped[1].sha256); + swapped[0].sha256 = b; + swapped[1].sha256 = a; + let ex = pinned_executor(&swapped); + std::fs::write(&first, &blobs[1].1).unwrap(); + let e = format!("{:#}", load_keys(&swapped, FriProfile::Test, dir.path(), &ex).unwrap_err()); + assert!(e.contains("not the pinned shape"), "{e}"); + assert_eq!(ex.perp_key_builds(), 0); + } + + /// A chain without pins reads nothing and keeps chain 21's behaviour: an executor never told + /// pins builds a key on demand, as before. + #[test] + fn a_chain_without_pins_reads_nothing_and_builds_on_demand() { + let (bytes, hc, segment, _, _) = fixture(); + let ex = ZkExecutor::new(FriProfile::Test); + let status = load_keys(&[], FriProfile::Test, Path::new("/nonexistent"), &ex).unwrap(); + assert_eq!(status, PerpsKeyStatus::default()); + ex.set_perp_pinned_keys(&[]); + ex.verify_perp(&hc, 10, &segment, &bytes).expect("verifies, built on demand"); + assert_eq!(ex.perp_key_builds(), 1); + assert!(ex.install_perp_vk(b"x").is_err(), "no pins, nothing to install"); + } + + /// The directory order: `--perps-key-dir`, then (absent the file beside the binary) the + /// committed keys for a developer's binary only. + #[test] + fn the_flag_wins_and_a_fleet_binary_reads_beside_itself() { + let flag = PerpsKeyOptions { dir: Some(PathBuf::from("/x/keys")) }; + assert_eq!(resolve_dir(&flag, None).unwrap(), PathBuf::from("/x/keys")); + let fleet = Path::new("/usr/local/bin/rand-node"); + assert_eq!(default_dir(fleet, Some("perp-vk-production-t18-pg14-in16-pub7-p2h20.bin"), true), PathBuf::from("/usr/local/bin")); + } + + /// The committed chain-22 files are this build's pins, and the in-tree fallback finds them. + #[test] + fn the_committed_chain22_files_are_this_builds_pins() { + let pins = perp_vk::chain22_pins(FriProfile::Production); + assert_eq!(pins.len(), 4); + for (shape, want) in pins { + let path = source_tree_dir().join(perp_vk::file_name(FriProfile::Production, &shape)); + let bytes = std::fs::read(&path).unwrap_or_else(|e| panic!("{}: {e}", path.display())); + assert_eq!(perp_vk::digest(&bytes), want, "{}", path.display()); + let blob = randprotocol_zkvm::machine::VerifierKeyBlob::from_bytes(&bytes).unwrap(); + assert_eq!(blob.shape, perp_vk::key_shape(&shape)); + assert_eq!(blob.profile, FriProfile::Production); + } + let exe = std::env::current_exe().unwrap(); + let name = perp_vk::file_name(FriProfile::Production, &perp_vk::chain22_shapes()[0]); + assert_eq!(default_dir(&exe, Some(&name), true), source_tree_dir()); + assert_ne!(default_dir(&exe, Some(&name), false), source_tree_dir()); + } + + /// No deploy script and no node source names a perps key build flag: there is none. + #[test] + fn the_node_has_no_perps_key_build_path() { + let src = Path::new(env!("CARGO_MANIFEST_DIR")).join("src"); + for e in std::fs::read_dir(&src).unwrap() { + let p = e.unwrap().path(); + if p.extension().is_some_and(|x| x == "rs") { + let s = std::fs::read_to_string(&p).unwrap(); + assert!(!s.contains(concat!("--build-", "perps-key")), "{}", p.display()); + } + } + } +} diff --git a/crates/randprotocol-node/src/rpc.rs b/crates/randprotocol-node/src/rpc.rs index 19a5da98..58522cd6 100644 --- a/crates/randprotocol-node/src/rpc.rs +++ b/crates/randprotocol-node/src/rpc.rs @@ -339,6 +339,10 @@ pub struct NodeStatus { /// `hc_auth_multisig`. A multisig chain never runs without the key: a node that could not /// load it refused to start. pub msauth_key: crate::msauth_key::MsauthKeySource, + /// CON-601: this node's pinned perps state-proof keys — `{"source": "loaded", "keys": 4}` on + /// a chain whose genesis pins them (a node that could not load every one refused to start), + /// `{"source": "absent", "keys": 0}` elsewhere. + pub perps_keys: crate::perps_key::PerpsKeyStatus, } /// [`NodeStatus::gas_prices`]'s two amounts, decimal strings like every other RAND amount on the @@ -3452,6 +3456,9 @@ async fn dispatch(st: &RpcState, req: &Request) -> Result { // CON-60: the genesis engine program-height pin, 0 when unset (chain 21); a // prover proves at the canonical shape by default only when it is set. "engine_program_log_height": c.engine_program_log_height, + // CON-601: the genesis' pinned state-proof keys (shape and file SHA-256 each), + // empty when unset (chain 21); a state proof of any other shape is refused. + "state_proof_keys": c.state_proof_keys, // PERP-5: the genesis cap on unproved digests, 0 when unset (chain 21). "max_pending_digests": c.max_pending_digests, "max_block_inputs": c.max_block_inputs, @@ -8715,6 +8722,7 @@ pub(crate) mod tests { "max_window_heights": 0, "engine_program_log_height": 0, "max_pending_digests": 0, + "state_proof_keys": [], "max_block_inputs": 8, "min_deposit": "1000", "engine_hc": word8_to_hex(&cfg.engine_hc), diff --git a/crates/randprotocol-node/src/storage.rs b/crates/randprotocol-node/src/storage.rs index 066d2787..071aba56 100644 --- a/crates/randprotocol-node/src/storage.rs +++ b/crates/randprotocol-node/src/storage.rs @@ -6058,6 +6058,7 @@ pub(crate) mod fixtures { max_window_heights: 0, engine_program_log_height: 0, max_pending_digests: 0, + state_proof_keys: Vec::new(), markets: vec![randprotocol_core::ledger::perps::MarketSpec { id: 0, symbol: "BTC-PERP".into(), diff --git a/crates/randprotocol-node/src/verify_cache.rs b/crates/randprotocol-node/src/verify_cache.rs index f87707ae..37b0af2d 100644 --- a/crates/randprotocol-node/src/verify_cache.rs +++ b/crates/randprotocol-node/src/verify_cache.rs @@ -371,6 +371,18 @@ impl ConfidentialExecutor for CachingExecutor { self.inner.set_perp_config(max_tier, engine_program_log_height) } + fn set_perp_pinned_keys(&self, pins: &[(randprotocol_core::confidential::ProofShape, [u8; 32])]) { + self.inner.set_perp_pinned_keys(pins) + } + + fn install_perp_vk(&self, blob: &[u8]) -> Result { + self.inner.install_perp_vk(blob) + } + + fn perp_pinned_keys_installed(&self) -> usize { + self.inner.perp_pinned_keys_installed() + } + fn warm(&self, program: &ProgramRecord) { self.inner.warm(program) } diff --git a/crates/randprotocol-node/tests/burst_memory.rs b/crates/randprotocol-node/tests/burst_memory.rs index 71d39787..ae710db7 100644 --- a/crates/randprotocol-node/tests/burst_memory.rs +++ b/crates/randprotocol-node/tests/burst_memory.rs @@ -187,6 +187,7 @@ async fn start_node(gen: &Genesis, key: &Keypair, budget: usize) -> (NodeHandle, prune_history: None, gas_policy: None, msauth: Default::default(), + perps_keys: Default::default(), }, RpcOptions { admission_budget: Some(budget), ..RpcOptions::default() }, NetOptions::default(), diff --git a/crates/randprotocol-node/tests/cluster.rs b/crates/randprotocol-node/tests/cluster.rs index f3aca5dc..26761679 100644 --- a/crates/randprotocol-node/tests/cluster.rs +++ b/crates/randprotocol-node/tests/cluster.rs @@ -920,6 +920,7 @@ async fn a_build_whose_bundle_guest_differs_from_genesis_refuses_to_start() { prune_history: None, gas_policy: None, msauth: Default::default(), + perps_keys: Default::default(), }) .await; // `NodeHandle` is not `Debug`, so unwrap the error by hand rather than via `expect_err`. diff --git a/crates/randprotocol-node/tests/common/cluster.rs b/crates/randprotocol-node/tests/common/cluster.rs index c120e062..f385900f 100644 --- a/crates/randprotocol-node/tests/common/cluster.rs +++ b/crates/randprotocol-node/tests/common/cluster.rs @@ -150,6 +150,7 @@ pub async fn start_in_verify( prune_history, gas_policy: None, msauth: Default::default(), + perps_keys: Default::default(), }) .await .expect("node starts"); diff --git a/crates/randprotocol-node/tests/common/mod.rs b/crates/randprotocol-node/tests/common/mod.rs index 32930bb0..4e31af58 100644 --- a/crates/randprotocol-node/tests/common/mod.rs +++ b/crates/randprotocol-node/tests/common/mod.rs @@ -163,6 +163,7 @@ pub async fn start_one_validator_shaped(edit: impl FnOnce(&mut Genesis)) -> Test prune_history: None, gas_policy: None, msauth: Default::default(), + perps_keys: Default::default(), }) .await .expect("node starts"); diff --git a/crates/randprotocol-node/tests/dandelion.rs b/crates/randprotocol-node/tests/dandelion.rs index 24fd1750..e265be38 100644 --- a/crates/randprotocol-node/tests/dandelion.rs +++ b/crates/randprotocol-node/tests/dandelion.rs @@ -67,6 +67,7 @@ async fn start_on_lanes(gen: &Genesis, seed: u8, bootstrap: Vec*Ytxl3l(uxCBuy-ZW)jm@wr=doT163AJhben zC?NalayXnL0$Qq~fCwmxR&n896&FBIK}10j>b>`O-^{!>OBRwIkB4c`{k``s_ulV* z_uKCG;+pD;D#vlkrj);UsFlR#NKnC-P3*lQ`cSpY-GtEuP&D8+wkVp#g}?_Z=ZE- z!>suyb+5kg?j12w#W7AKW=u3@+(fP8L~OJqW{o#AJh*naXTa1OE`k5;^3Wl)Q)rja z8A7{-&J;RJ=xm{Lgw7Q@Pv`+c=L=mR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kvm/keys/perp-vk-production-t18-pg14-in16-pub7-p2h20.bin b/crates/randprotocol-zkvm/keys/perp-vk-production-t18-pg14-in16-pub7-p2h20.bin new file mode 100644 index 0000000000000000000000000000000000000000..4579fdde15ec59266b270dd51dc5addd0c5ca3b4 GIT binary patch literal 13685 zcmeHOd30Q56@TBGZ}Kw9Op-~OG)a>*Ytxl3l(uxCBuy-ZW)jm@wr=doT163AJhben zC?NalayXnL0$Qq~fCwmxR&n896&FBIK}10j>b>`O-^{!>OBRwIkB4c`{k``s_ulV* z_uKCG;+pD;D#vlWDdjJoYV0NR-g)V*!yj3C>g}I=?TzzVT3)>ToR?mIbN(}r#-BfX z!^T%@?|FFk8ILDVZhK(w>2>>7?tW-(;_6jT-4Wk=Z}+)RUUPDH-<4l}EOOrqFPwHk z@7pInvG?3(_jKR?)OFWC8(Ff)tBWQ2HavZCd+eT}=*t%#wm$aoEjQm?@ul9~+h<+d zFl+uv-K#IWdq<2^af}m*854~eH&N?25gRRuS>p{253U{V88G#ROW=RIJah={6xt

u`K6MBHq`9c>6T_|*s&;x}o7J87-B|?`9U1nU?W_g5Fa!g$H z+;-&PaG!Cd2$VG_xPlAPzi99Jbt%8Z=~C_tBd~)C2D8tU^s~TV2Qe@ar!#C4RJKwy zDzrqXC$v;(OlX25MDnhb=j3Qnr@HLvm&my*?{6h^Hv zW#!b8I5id4tTPprCdySsbut;a)f+d$<}fA0J*l<*%RD3>1Xu!C3RnhM30MU<#1n?9 zm2$0Ot}INoQsdUJZHy5yM4!$v9lk-uG+DMv33hK!8VH z=NgL%=@!?Nc;cke8kTySa=Tse4#hha z?^67N;upswH5Qio4dwPt#cwG-r1)*c?AJu$0Icnmii0j z_DjWIDL$+Cvf`f=|1t`xzeAs=!K(;M{i||&Me$X|zbU?^_;7ec%)W^rT#~`y{-6;;y%TTT$pR8;w~36V)51m4d5liQZH6+ zmndGUc$wnmidQIJIUcFiVX0Rsw-2I89|D{TI1O+*;0(W&vXxKq8nuUV`1nDO6Zr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@ma+m}(+4Wf^4-`0 zack&P9Xm95w3Mbh4L=ye z(-fbEIFGK`{LqWfTDZ-cL`m!_{nq=WUBDRH{FHM z!iv(h6k?cy557yYHW&>Qa;Tpsn#3GS*IFpuOd*J->5^RLSo%&I$!)a#Z|#uea>vp- zkK`^o4s>=)ay;`TgPk?on3;1VIpJ73yrT5H1B{uAFZL@OOBZ!WUbx7Z1qVuLx&@$Z z9+K&n!z{-4`c;|Eum>+UW*JT8WWl6k>B0u3R~=%^%GHuw?bvERxu@5dL)T!i!!-WK z@Dh|+MrR*7TIiSi8jdc<2%vttDRS^)et;8l_dE^%O*3S;m@!Jvc~5R)htMA;^0M6e+K?u13ECYVP9if}2q za^zCJIy(4rifPP?V{;B|83KO-0Y~O&Ib~8jA(V|Zm0QEvthFWGa&Da(r8->Ezc}L> zEs_pjY?bFWrZ5S1$GGT1)XvDCCg9UDBUg`xE~S}~G?5;lyY_OsaO{A6v6Jh<3vHgM z(hSm<-b(|$%snCXq+~Fzs9|Ux;GsG+b1+BlmQaoc0bSNG5M$SVr&_E(nju|42ZP+} zM!%R`w2Jl-iHuU1kUk_1bQ$hsHI^FZ15zN{|1%R|66Y@S_M-`c(eYw7$a9@KxkmUe DMe-Zc literal 0 HcmV?d00001 diff --git a/crates/randprotocol-zkvm/keys/perp-vk-production-t18-pg14-in16-pub9-p2h20.bin b/crates/randprotocol-zkvm/keys/perp-vk-production-t18-pg14-in16-pub9-p2h20.bin new file mode 100644 index 0000000000000000000000000000000000000000..5f63b67fe898042367b4f1ca26d0499a33f3b5cf GIT binary patch literal 13685 zcmeHOd30Q56@TBGZ}Kw9Op-~OG)a>*Ytxl3l(uxCBuy-ZW)jm@wr=doT163AJhben zC?NalayXnL0$Qq~fCwmxR&n896&FBIK}10j>b>`O-^{!>OBRwIkB4c`{k``s_ulV* z_uKCG;+pD;D#vkRQ_5dF)!0ksz4Ovrhd;9P)Z0J#+8gJ!w7huvIWN8b=KNsL#_l_8;;ut3qGbS1{Zlcz4A~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8j!mpCv@g)w-dU{FE~h)EO+qHGg0B3KZAcful76U?IlMYt4Q zIdUmq9UXi*#Wd!{u{npf41qs^fFpCXoH8k%5X#1y%B|sS*4mP8Ik!%YQXQ`7Uz~A` z7Dq66Yy!7k*h~Tm(t8gnn(}OU3 Vec { + randprotocol_core::ledger::perps::canonical_state_proof_shapes(CHAIN22_MAX_TIER, CHAIN22_ENGINE_PROGRAM_LOG_HEIGHT, CHAIN22_MAX_WINDOW_BLOCKS) + } + + /// No blob hashes to this: the value a pin holds until its blob exists. + pub const PIN_PENDING: &str = super::msauth_vk::PIN_PENDING; + + /// SHA-256 of each chain-22 key file at the Production profile, in [`chain22_shapes`]' + /// order (public height 7, 8, 9, 10). Consensus-critical once a genesis names them (a crafted + /// preprocessed commitment could let a forged state proof verify): `deploy/cut-chain22-genesis.sh` + /// pins these into `perps.state_proof_keys`, and `tests/perp_vk.rs` regenerates them. + pub const CHAIN22_SHA256_PRODUCTION: [&str; 4] = [ + "4dc1f18bdd6d9104ba1622710cf2c146f71759676dbdcb70dad036152242e8b4", + "6392e5e9b7348f3729ba2031e0e3ec9788d6ed62a14521526482c92615f55106", + "c31636aa281004163e6fe0debd81854f11d7bca6c8062a91b1501c7e593e5bf0", + "ae3d0dc276061fd2a87b2e91b239f6dcccb746b49dedeecfdb2aab977c95c370", + ]; + + /// This build's digests of the chain-22 key files for `profile`, as `(shape, sha256)`; Test + /// has none (its tier-18 build costs as much as Production's; tests pin their own small keys). + pub fn chain22_pins(profile: FriProfile) -> Vec<(ProofShape, &'static str)> { + match profile { + FriProfile::Production => chain22_shapes().into_iter().zip(CHAIN22_SHA256_PRODUCTION).collect(), + FriProfile::Test => Vec::new(), + } + } + + fn profile_name(profile: FriProfile) -> &'static str { + match profile { + FriProfile::Production => "production", + FriProfile::Test => "test", + } + } + + /// The fixed file name of `shape`'s key for `profile`: + /// `perp-vk--t-pg-in-pub-p2h.bin`. + pub fn file_name(profile: FriProfile, shape: &ProofShape) -> String { + format!( + "perp-vk-{}-t{}-pg{}-in{}-pub{}-p2h{}.bin", + profile_name(profile), + shape.tier, + shape.program_log_height, + shape.input_log_height, + shape.public_log_height, + shape.poseidon2_log_height + ) + } + + /// The SHA-256 of `bytes`, lowercase hex ([`super::msauth_vk::digest`], the same function). + pub fn digest(bytes: &[u8]) -> String { + super::msauth_vk::digest(bytes) + } + + /// The machine's key shape for a state proof's shape (no modq table). + pub fn key_shape(shape: &ProofShape) -> VerifierKeyShape { + super::perp_key_shape(shape) + } + + /// The key file for `shape` at `profile`: the full build on a fresh machine, exported (the + /// `rand-node keygen-perp-vk` body; a big host at tier 18 — ~3.3–4 GB). Refused for a shape + /// the verifier would refuse or one with a hash table (the engine calls neither). + pub fn blob(profile: FriProfile, shape: &ProofShape) -> Result, String> { + if shape.keccak_log_height != 0 || shape.sha256_log_height != 0 { + return Err(format!("{shape:?}: a state-proof key has no keccak or sha256 table")); + } + let ks = key_shape(shape); + if !crate::machine::TIERS.contains(&(shape.tier as usize)) { + return Err(format!("{shape:?}: tier {} is not one of {:?}", shape.tier, crate::machine::TIERS)); + } + ks.check().map_err(|e| format!("{shape:?}: {e:?}"))?; + Ok(Machine::new(profile).export_verifier_key(ks).to_bytes()) + } + + /// The checks a pinned blob passes before the machine installs it: its SHA-256 is + /// `want_digest` (on the raw bytes, first), it decodes, its profile is `profile`, and its shape + /// is `shape`'s key shape. The machine's install repeats the digest check and adds format, + /// constraint set, structure and lookups. + pub fn check(blob: &[u8], want_digest: &[u8; 32], profile: FriProfile, shape: &ProofShape) -> Result { + let got = crate::sha256::sha256(blob); + if &got != want_digest { + return Err(format!("has sha256 {}, not the pinned {}", hex(&got), hex(want_digest))); + } + let b = VerifierKeyBlob::from_bytes(blob).map_err(|e| format!("does not decode: {e:?}"))?; + if b.profile != profile { + return Err(format!("is for the {:?} profile; this node runs {profile:?}", b.profile)); + } + let want = key_shape(shape); + if b.shape != want { + return Err(format!("holds the key for {:?}, not the pinned shape {want:?}", b.shape)); + } + Ok(b) + } + + pub fn hex(d: &[u8; 32]) -> String { + d.iter().map(|b| format!("{b:02x}")).collect() + } +} + /// The highest tier a *call* proof may declare (deep scan 2026-09-24, zkvm), enforced by /// `verify_call` before any verifier key is built, so it is a validity rule (admission and block /// apply both run `verify_call`). It is the highest tier `warm` pre-builds, and that is the @@ -811,6 +938,15 @@ pub struct ZkExecutor { /// installs), each with whether the pin is in `perp_lineage_machine` (true) or `perp_machine` /// (false) — counted per machine against its own cap. perp_pinned: std::sync::Mutex, + /// CON-601: the genesis `perps.state_proof_keys` — each pinned shape and its key file's + /// SHA-256 — set once by [`ConfidentialExecutor::set_perp_pinned_keys`]. Set, a state proof + /// verifies only under a key installed from its pinned file + /// ([`ConfidentialExecutor::install_perp_vk`], into `perp_lineage_machine`), and no state-proof + /// key is ever built: an unpinned shape, or a pinned one whose file was not installed, is + /// refused before any key. + perp_key_pins: std::sync::OnceLock>, + /// CON-601: the pinned shapes whose keys were installed from their files. + perp_keys_installed: std::sync::Mutex>, /// The tier-18 msauth verifier key, built once (spec §3.5, pre-flight finding 3): measured at /// Production on the 48 GB laptop at 78.6 s and ~4.0 GB peak (and resident after, on macOS's /// allocator — the key itself is a commitment and lookups), on 2–4 GB validators, so four @@ -877,6 +1013,8 @@ impl ZkExecutor { perp_engine_plh: std::sync::atomic::AtomicU8::new(0), perp_max_tier: std::sync::atomic::AtomicU8::new(0), perp_pinned: std::sync::Mutex::new(PerpPins::default()), + perp_key_pins: std::sync::OnceLock::new(), + perp_keys_installed: std::sync::Mutex::new(std::collections::BTreeSet::new()), msauth_key: std::sync::OnceLock::new(), msauth_key_builds: std::sync::atomic::AtomicUsize::new(0), msauth_key_source: std::sync::OnceLock::new(), @@ -1845,11 +1983,24 @@ impl ZkExecutor { ) -> Result { let proof = if verify { let proof = self.perp_pre_key(engine_hc, max_tier, segment, bytes)?; - // CON-60: the engine's own machines — the canonical one for the chain's canonical - // shapes, the general one otherwise; whichever already holds the key first. - self.perp_machine_for(&shape_of(&proof)) - .verify_public(engine_hc, segment, &proof) - .map_err(|e| ConfidentialError::InvalidProof(format!("{e:?}")))?; + let shape = shape_of(&proof); + // CON-601: under pinned keys the key is the one installed from its file, never a + // build — `perp_pre_key` refused an unpinned shape; one pinned but not installed (a + // node started without its file, which `node::start` refuses) is refused here. + let machine = if self.perp_key_pins.get().is_some() { + if !Self::perp_cached_in(&self.perp_lineage_machine, &shape) { + return Err(ConfidentialError::InvalidProof(format!( + "the pinned state-proof key for {shape:?} is not loaded on this node (its key file, {}); a pinned key is never built", + perp_vk::file_name(self.profile, &shape) + ))); + } + &self.perp_lineage_machine + } else { + // CON-60: the engine's own machines — the canonical one for the chain's canonical + // shapes, the general one otherwise; whichever already holds the key first. + self.perp_machine_for(&shape) + }; + machine.verify_public(engine_hc, segment, &proof).map_err(|e| ConfidentialError::InvalidProof(format!("{e:?}")))?; proof } else { let proof = self.perp_header(max_tier, segment.len(), bytes)?; @@ -1891,6 +2042,18 @@ impl ZkExecutor { if let Some(why) = fri_structure_violation(&proof, self.profile.num_queries()) { return Err(ConfidentialError::InvalidProof(why)); } + // CON-601: under the genesis key pins, only a pinned shape — the ledger refuses the rest + // from the header before it asks; this is the executor's own guard, so no caller of + // `verify_perp` (the pool's pre-screen included) can reach a key for another shape. + if let Some(pins) = self.perp_key_pins.get() { + let shape = shape_of(&proof); + if !pins.contains_key(&shape) { + return Err(ConfidentialError::InvalidProof(format!( + "state proof shape {shape:?} is not one of the chain's {} pinned state-proof key shapes", + pins.len() + ))); + } + } Ok(proof) } @@ -2519,6 +2682,39 @@ impl ConfidentialExecutor for ZkExecutor { self.perp_engine_plh.store(engine_program_log_height, std::sync::atomic::Ordering::SeqCst); } + /// CON-601: pinned mode, set once and only for a non-empty list (a second call is ignored). + fn set_perp_pinned_keys(&self, pins: &[(randprotocol_core::confidential::ProofShape, [u8; 32])]) { + if !pins.is_empty() { + let _ = self.perp_key_pins.set(pins.iter().copied().collect()); + } + } + + /// CON-601: [`perp_vk::check`] against the pin whose digest the bytes have (on the raw bytes, + /// before any decode), then the machine's own pinned install into the canonical machine, + /// where the key is pinned (never evicted). + fn install_perp_vk(&self, blob: &[u8]) -> Result { + let Some(pins) = self.perp_key_pins.get() else { + return Err("this chain pins no state-proof keys (no perps.state_proof_keys)".into()); + }; + let got = crate::sha256::sha256(blob); + let Some((shape, want)) = pins.iter().find(|(_, d)| **d == got) else { + return Err(format!( + "has sha256 {}, which is none of the {} pinned state-proof key digests ({})", + perp_vk::hex(&got), + pins.len(), + pins.values().map(perp_vk::hex).collect::>().join(", ") + )); + }; + perp_vk::check(blob, want, self.profile, shape)?; + self.perp_lineage_machine.install_verifier_key_pinned(blob, want).map_err(|e| format!("the machine refused the key: {e:?}"))?; + self.perp_keys_installed.lock().unwrap().insert(*shape); + Ok(*shape) + } + + fn perp_pinned_keys_installed(&self) -> usize { + self.perp_keys_installed.lock().unwrap().len() + } + /// CON-60: pin `shape`'s key where it is built, once a proof of it verified — only when the /// key is built already (this never builds) and while that machine has a pin left /// ([`PERP_CANONICAL_PINS`] in the canonical machine, [`PERP_GENERAL_PINS`] in the general @@ -2531,6 +2727,10 @@ impl ConfidentialExecutor for ZkExecutor { /// keep can take the same last pin meanwhile, and the lock the pool's lineage check reads is /// never held across a key operation. fn keep_perp_key(&self, shape: &randprotocol_core::confidential::ProofShape) { + // CON-601: pinned keys are installed (and pinned in their machine) from their files. + if self.perp_key_pins.get().is_some() { + return; + } let canonical = if Self::perp_cached_in(&self.perp_lineage_machine, shape) { true } else if Self::perp_cached_in(&self.perp_machine, shape) { @@ -2569,6 +2769,10 @@ impl ConfidentialExecutor for ZkExecutor { /// proofs used) where a proof of it would verify, and pin it. A shape the header rules /// refuse — a tier outside `TIERS`, heights out of range — is skipped, never built. fn warm_perp(&self, shape: &randprotocol_core::confidential::ProofShape) { + // CON-601: under pinned keys nothing is ever built; the keys come from their files. + if self.perp_key_pins.get().is_some() { + return; + } // Constraint set 11: the poseidon2 height is ranged with the rest (`VerifierKeyShape::check`). if !TIERS.contains(&(shape.tier as usize)) || perp_key_shape(shape).check().is_err() { return; diff --git a/crates/randprotocol-zkvm/tests/perp_vk.rs b/crates/randprotocol-zkvm/tests/perp_vk.rs new file mode 100644 index 00000000..7e504f77 --- /dev/null +++ b/crates/randprotocol-zkvm/tests/perp_vk.rs @@ -0,0 +1,63 @@ +//! CON-601: the chain-22 pinned state-proof verifier keys (`executor::perp_vk`). Node-local (the +//! sync excludes `perp_vk.rs`). The default run checks the committed files against this build's +//! pins without building anything; the ignored test regenerates them on a big host. + +use randprotocol_zkvm::executor::perp_vk; +use randprotocol_zkvm::machine::FriProfile; + +fn keys_dir() -> std::path::PathBuf { + std::path::Path::new(env!("CARGO_MANIFEST_DIR")).join("keys") +} + +fn unhex(s: &str) -> [u8; 32] { + let mut d = [0u8; 32]; + for (i, b) in d.iter_mut().enumerate() { + *b = u8::from_str_radix(&s[2 * i..2 * i + 2], 16).unwrap(); + } + d +} + +#[test] +fn chain22_pins_are_four_canonical_tier18_shapes_none_pending() { + let pins = perp_vk::chain22_pins(FriProfile::Production); + let got: Vec<_> = pins + .iter() + .map(|(s, _)| (s.tier, s.program_log_height, s.input_log_height, s.public_log_height, s.poseidon2_log_height, s.keccak_log_height, s.sha256_log_height)) + .collect(); + assert_eq!(got, vec![(18, 14, 16, 7, 20, 0, 0), (18, 14, 16, 8, 20, 0, 0), (18, 14, 16, 9, 20, 0, 0), (18, 14, 16, 10, 20, 0, 0)]); + for (shape, sha) in &pins { + assert!(sha.len() == 64 && sha.bytes().all(|c| c.is_ascii_hexdigit() && !c.is_ascii_uppercase()), "{shape:?}: {sha}"); + assert_ne!(*sha, perp_vk::PIN_PENDING, "{shape:?} is still pending"); + } + assert!(perp_vk::chain22_pins(FriProfile::Test).is_empty()); +} + +/// Every committed key file hashes to its pin and passes the pre-install checks (decode, profile, +/// shape) — no machine, no build. +#[test] +fn the_committed_chain22_files_match_the_pins_and_their_shapes() { + for (shape, sha) in perp_vk::chain22_pins(FriProfile::Production) { + let name = perp_vk::file_name(FriProfile::Production, &shape); + let bytes = std::fs::read(keys_dir().join(&name)).unwrap_or_else(|e| panic!("{name}: {e}")); + assert_eq!(perp_vk::digest(&bytes), sha, "{name}"); + perp_vk::check(&bytes, &unhex(sha), FriProfile::Production, &shape).unwrap_or_else(|e| panic!("{name} {e}")); + // and one of them is not another's key + let other = perp_vk::chain22_shapes().into_iter().find(|s| *s != shape).unwrap(); + assert!(perp_vk::check(&bytes, &unhex(sha), FriProfile::Production, &other).unwrap_err().contains("not the pinned shape")); + assert!(perp_vk::check(&bytes, &unhex(sha), FriProfile::Test, &shape).unwrap_err().contains("profile")); + } +} + +/// The keygen is deterministic: a fresh Production export regenerates each committed file byte for +/// byte. Keygen-scale (four tier-18 key builds, ~21 s and ~1.7 GB each with `parallel`): +/// `cargo +1.98.1 test --release -p randprotocol-zkvm --features parallel --test perp_vk -- --ignored` +#[test] +#[ignore = "builds the four tier-18 Production state-proof keys"] +fn the_chain22_files_regenerate_byte_for_byte() { + for (shape, sha) in perp_vk::chain22_pins(FriProfile::Production) { + let name = perp_vk::file_name(FriProfile::Production, &shape); + let blob = perp_vk::blob(FriProfile::Production, &shape).unwrap(); + assert_eq!(perp_vk::digest(&blob), sha, "{name}"); + assert_eq!(blob, std::fs::read(keys_dir().join(&name)).unwrap(), "{name}"); + } +} diff --git a/deploy/cut-chain22-genesis.sh b/deploy/cut-chain22-genesis.sh index ef9d25ff..be01f116 100755 --- a/deploy/cut-chain22-genesis.sh +++ b/deploy/cut-chain22-genesis.sh @@ -528,6 +528,20 @@ PERPS_MAX_PENDING_DIGESTS=65536 # OPEN 8, decided 2 NODE_VERSION_FLOOR=0.8.5 # the first release with perps.max_pending_digests (436c1af0) EXPECT_ENGINE_PROGRAM_LOG_HEIGHT=${EXPECT_ENGINE_PROGRAM_LOG_HEIGHT:-$ENGINE_PROGRAM_LOG_HEIGHT_DECIDED} ENGINE_PROGRAM_LOG_HEIGHT= # set by the cut (`rand perp image-hc` stderr), never the environment; the selftest sets a fixture +# - state_proof_keys (CON-601, monorepo#23) — DECIDED 2026-11-19 (item 9 above): the pinned, +# precomputed state-proof verifier keys validators LOAD instead of building (a block carrying a +# tier-18 state proof made every validator build a ~1.7–4 GB key). Four keys, the canonical +# shapes of max_tier 18 over the engine's program height 14 — input 16, poseidon2 20, public +# 7, 8, 9, 10 (windows of 1..=11, 12..=27, 28..=59, 60..=64 blocks) — each written with the +# SHA-256 of its shipped file in PERPS_KEY_DIR (default this tree's crates/randprotocol-zkvm/keys, +# the release's perp-vk-production-*.bin), and each file held to this rand-node's own pin +# (`rand-node keygen-perp-vk --print-pinned production`) before it is written. Not overridable +# but for the directory; the probe node loads them from there (RAND_PERPS_KEY_DIR). +PERPS_KEY_DIR=${PERPS_KEY_DIR:-crates/randprotocol-zkvm/keys} +# [tier, program, input, public, poseidon2] per key, in the field's order. +PERPS_STATE_PROOF_SHAPES_DECIDED='[[18, 14, 16, 7, 20], [18, 14, 16, 8, 20], [18, 14, 16, 9, 20], [18, 14, 16, 10, 20]]' +PERPS_STATE_PROOF_KEYS_JSON= # set by the cut from the files (`keygen-perp-vk --genesis-json`), never the environment +PERPS_KEY_PINS= # set by the cut: this rand-node's `keygen-perp-vk --print-pinned production` (" " lines) # ── chain 21's `multisig` section (docs/multisig.md): create_fee 1 RAND, ONE account — the treasury, # now 5 of 6 (the owner's rule: a multisig is always 5 of 6, decided for chain 22 on 2026-11-19), # six NEW signers (none of chain 21's), a fresh salt, its balance CARRIED from chain 21's multisig @@ -605,6 +619,7 @@ export CHAIN_ID CHAIN21_GENESIS CHAIN21_HASH CHAIN21_GENESIS_SHA256 CHAIN21_TREA PROGRAM_STATE_CELL_FEE BALANCES_RESCAN BRIDGE_MINT_BPS BRIDGE_BURN_BPS FEE_RECIPIENT \ FEE_RECIPIENT_FINGERPRINT FEES_JSON PERPS_JSON ENGINE_HC_DECIDED EXPECT_ENGINE_HC PERP_GENESIS_ROOT \ PERPS_SKIPPED PERPS_V10_JSON PERPS_MAX_WINDOW_HEIGHTS EXPECT_ENGINE_PROGRAM_LOG_HEIGHT ENGINE_PROGRAM_LOG_HEIGHT PERPS_MAX_PENDING_DIGESTS \ + PERPS_KEY_DIR PERPS_STATE_PROOF_SHAPES_DECIDED PERPS_STATE_PROOF_KEYS_JSON PERPS_KEY_PINS \ MULTISIG_CREATE_FEE TREASURY_THRESHOLD TREASURY_SIGNERS TREASURY MULTISIG_MAX_ACCOUNTS \ PROGRAM_STATE_REFUSE_PANICS TOKENS_INCREMENTAL_ROOT AUDIT_V10_SKIPPED EXPECT_HC_AUTH_MULTISIG \ REFERENCE_BLOCK_WINDOW BEACON_COMMIT_DELAY_BLOCKS BEACON_TSV BLOCK_CONTEXT_SKIPPED @@ -1127,7 +1142,8 @@ PY # and PERP_GENESIS_ROOT, in PerpsConfig's field order, then — unless AUDIT_V10_SKIPPED — the new # fields: bound_payouts, sparse_windows, max_window_heights (PERPS_MAX_WINDOW_HEIGHTS), # engine_program_log_height (ENGINE_PROGRAM_LOG_HEIGHT, from `rand perp image-hc`) and -# max_pending_digests (PERPS_MAX_PENDING_DIGESTS, OPEN 8); never initial_collateral (OPEN 4). py_splice puts it into the file. +# max_pending_digests (PERPS_MAX_PENDING_DIGESTS, OPEN 8) and state_proof_keys (PERPS_STATE_PROOF_KEYS_JSON, +# CON-601); never initial_collateral (OPEN 4). py_splice puts it into the file. py_perps() { python3 - <<'PY' import json, os, re, sys @@ -1153,6 +1169,14 @@ if not E.get("AUDIT_V10_SKIPPED"): sys.exit(f"cut-chain22: PERPS_MAX_PENDING_DIGESTS {mpd!r} is not in max_window_blocks..=1048576 (PERP-5)") section.update(bound_payouts=v10["bound_payouts"], sparse_windows=v10["sparse_windows"], max_window_heights=int(mwh), engine_program_log_height=int(eplh), max_pending_digests=int(mpd)) + # CON-601: the pinned state-proof keys, as perps_keys_step read them off the shipped files. + try: + spk = json.loads(E.get("PERPS_STATE_PROOF_KEYS_JSON") or "null") + except ValueError: + spk = None + if not (isinstance(spk, list) and spk): + sys.exit("cut-chain22: PERPS_STATE_PROOF_KEYS_JSON is not a list of keys — the perps_keys_step (CON-601) did not run") + section.update(state_proof_keys=spk) json.dump(section, open(os.path.join(E["TMP"], "perps.json"), "w"), indent=1) PY } @@ -1583,7 +1607,7 @@ PERPS_DECIDED = {"collateral_asset": 1, "max_tier": 18, "max_window_blocks": 64, "markets": [{"id": 0, "symbol": "BTC-PERP", "lot": 100000, "tick": 100000000, "max_leverage": 20, "maintenance_bps": 250, "taker_fee_bps": 5, "maker_fee_bps": 2}]} ENGINE_HC_DECIDED = "f286a61171e274278ec8d18d7853e5f36799ed8dc5a3e31e0077ad89ef1d1573" -V10_FIELDS = ("bound_payouts", "sparse_windows", "max_window_heights", "engine_program_log_height", "max_pending_digests") +V10_FIELDS = ("bound_payouts", "sparse_windows", "max_window_heights", "engine_program_log_height", "max_pending_digests", "state_proof_keys") need(same_json(json.loads(E["PERPS_JSON"]), PERPS_DECIDED), "PERPS_JSON is not chain 21's perps section (BTC-PERP on zUSD, 20x / 250 bps, tier 18, 24 inputs)") need(same_json(json.loads(E["PERPS_V10_JSON"]), {"bound_payouts": True, "sparse_windows": True}), "PERPS_V10_JSON is not the decided {bound_payouts: true, sparse_windows: true} (PERP-6, PERP-101)") @@ -1613,11 +1637,32 @@ else: f"that {m['max_leverage']}x implies (perp-core: ⌈notional / max_leverage⌉) — a max-leverage position would open liquidatable") need(perps["max_tier"] == 18, f"perps.max_tier is {perps['max_tier']!r}, not 18 (the production sizing; owner 2026-11-19: tier 18 " f"stays, CON-601 met by a pinned precomputed state-proof key — tier 16 cannot prove a mass liquidation)") - # TODO(CON-601, owner 2026-11-19): once the pinned tier-18 state-proof key PR lands (the key - # built once, its hash a chain-22 genesis field, validators loading it as they load the - # msauth key), assert that field here: present, equal to the hash of the shipped key file - # (as RAND_MSAUTH_VK is checked), and add it to the field probe and to check-limits. The - # field does not exist yet — no name is assumed here. + # CON-601 (owner 2026-11-19): the pinned state-proof keys validators load instead of building — + # perps.state_proof_keys, exactly the four canonical tier-18 shapes, each with the SHA-256 of its + # shipped file in PERPS_KEY_DIR, which is also this rand-node's own pin (PERPS_KEY_PINS, from + # `keygen-perp-vk --print-pinned production`). The field probe and check-limits cover it too. + if not v10_skipped: + import hashlib + spk = perps.get("state_proof_keys") + SPK_SHAPE = ["tier", "program_log_height", "input_log_height", "public_log_height", "poseidon2_log_height"] + shapes = json.loads(E["PERPS_STATE_PROOF_SHAPES_DECIDED"]) + need(isinstance(spk, list) and all(isinstance(k, dict) and list(k) == SPK_SHAPE + ["sha256"] for k in spk) + and [[k[f] for f in SPK_SHAPE] for k in spk] == shapes, + f"perps.state_proof_keys is {spk!r}, not the four canonical tier-18 shapes {shapes} (tier, program, input, public, " + f"poseidon2 — CON-601, owner 2026-11-19)") + pins = dict(l.split() for l in E.get("PERPS_KEY_PINS", "").splitlines() if l.strip()) + names = [] + for k in spk if isinstance(spk, list) else []: + name = (f"perp-vk-production-t{k['tier']}-pg{k['program_log_height']}-in{k['input_log_height']}" + f"-pub{k['public_log_height']}-p2h{k['poseidon2_log_height']}.bin") + names.append(name) + path = os.path.join(E["PERPS_KEY_DIR"], name) + got = hashlib.sha256(open(path, "rb").read()).hexdigest() if os.path.isfile(path) else None + need(got is not None, f"perps.state_proof_keys: no key file {path} (PERPS_KEY_DIR: the release's perp-vk-production-*.bin)") + need(k["sha256"] == got, f"perps.state_proof_keys: {name} is pinned as {k['sha256']}, but the shipped file {path} has sha256 {got}") + need(pins.get(name) == got, f"perps.state_proof_keys: {name} has sha256 {got}, not this rand-node's pin {pins.get(name)} " + f"(`keygen-perp-vk --print-pinned production`) — a key file of another build or constraint set") + need(sorted(pins) == sorted(names), f"this rand-node pins the key files {sorted(pins)}, not the genesis' {sorted(names)}") need(perps["max_block_inputs"] == 24, f"perps.max_block_inputs is {perps['max_block_inputs']!r}, not 24 — the production sizing at tier 18 " f"(durian.market's gated case block-24-14liq); nothing measured more") need(perps["engine_hc"] == E["EXPECT_ENGINE_HC"] == ENGINE_HC_DECIDED == p21["engine_hc"], @@ -1906,13 +1951,47 @@ for w in warnings: PY } +# ══ the cut, step 1e: the pinned state-proof keys (CON-601) — the shipped files → PERPS_STATE_PROOF_KEYS_JSON ═ +# This rand-node's own pins (`keygen-perp-vk --print-pinned production`: four " " +# lines, none pending) name the files; each must be in PERPS_KEY_DIR with exactly that SHA-256 (by +# shasum and by the node's own `--check`). Then `--genesis-json` writes the field from the files, +# and RAND_PERPS_KEY_DIR points the loopback probe node at them. py_splice asserts the field again. +perps_keys_step() { + local pins name want got n=0 + "$NODE" keygen-perp-vk --help >/dev/null 2>&1 \ + || { echo "cut-chain22: $NODE has no keygen-perp-vk — a build before CON-601's pinned state-proof keys; chain 22 pins them (owner, 2026-11-19)" >&2; exit 1; } + pins=$("$NODE" keygen-perp-vk --print-pinned production 2>/dev/null) \ + || { echo "cut-chain22: \`$NODE keygen-perp-vk --print-pinned production\` failed" >&2; exit 1; } + [ -d "$PERPS_KEY_DIR" ] || { echo "cut-chain22: PERPS_KEY_DIR $PERPS_KEY_DIR is not a directory (the release's perp-vk-production-*.bin)" >&2; exit 1; } + while read -r name want; do + [ -n "$name" ] || continue + n=$((n + 1)) + [[ $want =~ ^[0-9a-f]{64}$ ]] && [[ ! $want =~ ^0+$ ]] \ + || { echo "cut-chain22: $NODE pins $name as '$want' — no key file yet (a build before the keys were generated)" >&2; exit 1; } + [ -f "$PERPS_KEY_DIR/$name" ] || { echo "cut-chain22: no key file $PERPS_KEY_DIR/$name (PERPS_KEY_DIR: the release's perp-vk-production-*.bin)" >&2; exit 1; } + got=$(shasum -a 256 "$PERPS_KEY_DIR/$name" | cut -c1-64) + [ "$got" = "$want" ] || { echo "cut-chain22: $PERPS_KEY_DIR/$name has sha256 $got, not this rand-node's pin $want" >&2; exit 1; } + [ "$("$NODE" keygen-perp-vk --check "$PERPS_KEY_DIR/$name" 2>/dev/null)" = "$want" ] \ + || { echo "cut-chain22: \`$NODE keygen-perp-vk --check $PERPS_KEY_DIR/$name\` is not $want" >&2; exit 1; } + done <<<"$pins" + [ "$n" -eq 4 ] || { echo "cut-chain22: $NODE pins $n state-proof key files, not the four of chain 22 (tier 18, public heights 7–10)" >&2; exit 1; } + PERPS_KEY_PINS=$pins + PERPS_STATE_PROOF_KEYS_JSON=$("$NODE" keygen-perp-vk --genesis-json "$PERPS_KEY_DIR") \ + || { echo "cut-chain22: \`$NODE keygen-perp-vk --genesis-json $PERPS_KEY_DIR\` failed" >&2; exit 1; } + RAND_PERPS_KEY_DIR=$(cd "$PERPS_KEY_DIR" && pwd) + export PERPS_KEY_PINS PERPS_STATE_PROOF_KEYS_JSON RAND_PERPS_KEY_DIR + echo "cut-chain22: perps state-proof keys: $n files in $PERPS_KEY_DIR, each this rand-node's pin → perps.state_proof_keys (CON-601)" +} + # ══ the field probe: the new fields are part of this rand-node's genesis hash ═══════════════════ # Copies of the finished file each without one new thing, every one still a valid genesis (each # field is optional, with chain 21's meaning when absent): without `program_state.refuse_panics`, # without `multisig.max_accounts`, without `perps.bound_payouts`, without `perps.sparse_windows`, # `perps.max_window_heights` and `perps.max_pending_digests` together (the last two are refused # without the first), with `perps.max_window_heights` at another value in range (it cannot be -# dropped alone), without `perps.engine_program_log_height`, without `perps.max_pending_digests`, +# dropped alone), without `perps.engine_program_log_height` (and the pinned keys, refused without +# it), without `perps.state_proof_keys`, with one of its digests changed (CON-601), without +# `perps.max_pending_digests`, # and without `tokens.incremental_root`; and (#168 / #189) without `program_state.reference_block_window` # and the beacon together (the beacon is refused without the window), with the window at another # value in range, without the beacon alone, with `beacon.commit_delay_blocks` at another value, and @@ -1955,7 +2034,15 @@ if "sparse_windows" in p: variant("perps.max_window_heights=" + str(mwh + 1 if mwh < 4096 else mwh - 1), ["perps", "max_window_heights"], set_to=mwh + 1 if mwh < 4096 else mwh - 1) if "engine_program_log_height" in p: - variant("perps.engine_program_log_height", ["perps", "engine_program_log_height"]) + # CON-601: the pinned keys are refused without the engine pin, so they go with it. + variant("perps.engine_program_log_height" + ("+state_proof_keys" if "state_proof_keys" in p else ""), + ["perps", "engine_program_log_height"], *([["perps", "state_proof_keys"]] if "state_proof_keys" in p else [])) +if "state_proof_keys" in p: + # CON-601: without the pinned keys, and with one pinned digest changed (its last nibble). + variant("perps.state_proof_keys", ["perps", "state_proof_keys"]) + d0 = p["state_proof_keys"][0]["sha256"] + variant("perps.state_proof_keys.0.sha256", ["perps", "state_proof_keys", 0, "sha256"], + set_to=d0[:-1] + "0123456789abcdef"[(int(d0[-1], 16) + 1) % 16]) if "max_pending_digests" in p: variant("perps.max_pending_digests", ["perps", "max_pending_digests"]) if "incremental_root" in g["tokens"]: @@ -2006,11 +2093,12 @@ probe_fields() { # ok=$((ok + 1)) done [ "$ok" -eq "$want" ] || { echo "cut-chain22: the field probe ran $ok variant(s), expected $want" >&2; exit 1; } - # The full set: the audit-v10 eight, plus (#168 / #189) the window with the beacon, the window at - # another value, the beacon, its delay at another value, and one per commitment (VALIDATOR_COUNT, 25). - local full=$((8 + 4 + VALIDATOR_COUNT)) + # The full set: the audit-v10 eight and CON-601's two, plus (#168 / #189) the window with the + # beacon, the window at another value, the beacon, its delay at another value, and one per + # commitment (VALIDATOR_COUNT, 25). + local full=$((8 + 2 + 4 + VALIDATOR_COUNT)) [ -n "${PERPS_SKIPPED:-}${AUDIT_V10_SKIPPED:-}${BLOCK_CONTEXT_SKIPPED:-}" ] || [ "$ok" -eq "$full" ] \ - || { echo "cut-chain22: the field probe ran $ok variant(s), expected $full (program_state.refuse_panics, multisig.max_accounts, perps.bound_payouts, perps.sparse_windows+max_window_heights+max_pending_digests, perps.max_window_heights at another value, perps.engine_program_log_height, perps.max_pending_digests, tokens.incremental_root; program_state.reference_block_window+beacon, the window at another value, beacon, beacon.commit_delay_blocks at another value, and each of the $VALIDATOR_COUNT commitments changed)" >&2; exit 1; } + || { echo "cut-chain22: the field probe ran $ok variant(s), expected $full (program_state.refuse_panics, multisig.max_accounts, perps.bound_payouts, perps.sparse_windows+max_window_heights+max_pending_digests, perps.max_window_heights at another value, perps.engine_program_log_height+state_proof_keys, perps.state_proof_keys, a pinned key digest changed, perps.max_pending_digests, tokens.incremental_root; program_state.reference_block_window+beacon, the window at another value, beacon, beacon.commit_delay_blocks at another value, and each of the $VALIDATOR_COUNT commitments changed)" >&2; exit 1; } echo "cut-chain22: the new fields ($ok variants probed) are part of this rand-node's genesis hash" } @@ -2091,6 +2179,12 @@ else: want("perps max_window_heights (PERP-101)", P.get("max_window_heights"), gp.get("max_window_heights", 0)) want("perps engine_program_log_height (CON-60)", P.get("engine_program_log_height"), gp.get("engine_program_log_height", 0)) want("perps max_pending_digests (PERP-5)", P.get("max_pending_digests"), gp.get("max_pending_digests", 0)) + # CON-601: the pinned state-proof keys, as the genesis lists them, and this node holding every one + # (loaded from its file at startup — a node that could not load one refused to start). + want("perps state_proof_keys (CON-601)", P.get("state_proof_keys"), gp.get("state_proof_keys", [])) + nk = len(gp.get("state_proof_keys", [])) + want("status perps_keys (CON-601)", (rpc("rand_status") or {}).get("perps_keys"), + {"source": "loaded" if nk else "absent", "keys": nk}) # multisig — the create fee, the treasury seeded at genesis (its RAND carried from chain 21's register; # the node counts it as `multisig_issued`), 5 of 6, and the account cap (MSA-4; absent from # the served limits when the genesis has none, i.e. a DRY_RUN that skipped audit v10) @@ -2423,7 +2517,8 @@ json.dump({**{k: d[k] for k in ("collateral_asset", "max_tier", "max_window_bloc "engine_hc": E["EXPECT_ENGINE_HC"], "genesis_root": E["PERP_GENESIS_ROOT"], "markets": d["markets"], "bound_payouts": v10["bound_payouts"], "sparse_windows": v10["sparse_windows"], "max_window_heights": int(E["PERPS_MAX_WINDOW_HEIGHTS"]), "engine_program_log_height": int(E["ENGINE_PROGRAM_LOG_HEIGHT"]), - "max_pending_digests": int(E["PERPS_MAX_PENDING_DIGESTS"])}, + "max_pending_digests": int(E["PERPS_MAX_PENDING_DIGESTS"]), + "state_proof_keys": json.loads(E["PERPS_STATE_PROOF_KEYS_JSON"])}, open(f"{st}/tmp/perps.json", "w")) open(f"{st}/faucet-recipients-changed.txt", "w").write("someone rand1SELFTESTfaucetrecipientchanged\n") with open(f"{st}/tmp/token-notes.jsonl", "w") as f: @@ -2487,8 +2582,22 @@ if [ "${SELFTEST:-}" = 1 ]; then # happy path is the real cut's (OPEN 3, OPEN 4 — the exchange is empty, carried). PERPS_MAX_WINDOW_HEIGHTS=256 MULTISIG_MAX_ACCOUNTS=1 ENGINE_PROGRAM_LOG_HEIGHT=14 TREASURY_SALT=$(printf '5a%.0s' $(seq 32)) + # CON-601: the pinned state-proof keys from this tree's committed files — what `keygen-perp-vk + # --genesis-json` and `--print-pinned production` print for them (the cut asks the rand-node). + read -r -d '' SPK_PY <<'PY' || true +import hashlib, json, os, sys +d, shapes = os.environ["PERPS_KEY_DIR"], json.loads(os.environ["PERPS_STATE_PROOF_SHAPES_DECIDED"]) +keys, pins = [], [] +for t, pg, i, pub, p2 in shapes: + name = f"perp-vk-production-t{t}-pg{pg}-in{i}-pub{pub}-p2h{p2}.bin" + h = hashlib.sha256(open(os.path.join(d, name), "rb").read()).hexdigest() + keys.append({"tier": t, "program_log_height": pg, "input_log_height": i, "public_log_height": pub, "poseidon2_log_height": p2, "sha256": h}) + pins.append(f"{name} {h}") +print(json.dumps(keys) if sys.argv[1] == "json" else "\n".join(pins)) +PY + PERPS_STATE_PROOF_KEYS_JSON=$(python3 -c "$SPK_PY" json); PERPS_KEY_PINS=$(python3 -c "$SPK_PY" pins) export ST FIXTURE_MODE=selftest FEE_RECIPIENT PERP_GENESIS_ROOT PERPS_MAX_WINDOW_HEIGHTS MULTISIG_MAX_ACCOUNTS ENGINE_PROGRAM_LOG_HEIGHT \ - TREASURY_SALT FIXTURE_ROOT_OK=1 + TREASURY_SALT FIXTURE_ROOT_OK=1 PERPS_STATE_PROOF_KEYS_JSON PERPS_KEY_PINS py_fixtures NEW_EMITTER=$(printf '0%.0s' $(seq 63))1 export SNAPSHOT_FILE=$ST/snap/chain21-state.json BALANCES_FILE=$ST/snap/balances.json CHAIN21_GENESIS=$ST/genesis-chain21.json \ @@ -2536,8 +2645,11 @@ assert g["fees"] == g21["fees"] == {"burn_base": True, "burn_floor": True} assert g["hc_auth_multisig"] == "41db73c507ab1f24ebe76d9c425b42a08ed9a02b4b1284d410502729ce6b9cd1" != g21["hc_auth_multisig"] == "9705f8e2f1bc8561848b29cb8efd57c37e3e39788fa58a5f03304d8019668247" and g["hc_auth_multisig"] != g["hc_auth"] p = g["perps"] assert list(p) == ["collateral_asset", "max_tier", "max_window_blocks", "max_block_inputs", "min_deposit", "engine_hc", "genesis_root", "markets", - "bound_payouts", "sparse_windows", "max_window_heights", "engine_program_log_height", "max_pending_digests"], list(p) -assert {k: v for k, v in p.items() if k not in ("genesis_root", "bound_payouts", "sparse_windows", "max_window_heights", "engine_program_log_height", "max_pending_digests")} \ + "bound_payouts", "sparse_windows", "max_window_heights", "engine_program_log_height", "max_pending_digests", "state_proof_keys"], list(p) +assert [(k["tier"], k["program_log_height"], k["input_log_height"], k["public_log_height"], k["poseidon2_log_height"]) for k in p["state_proof_keys"]] \ + == [(18, 14, 16, 7, 20), (18, 14, 16, 8, 20), (18, 14, 16, 9, 20), (18, 14, 16, 10, 20)] +assert [k["sha256"] for k in p["state_proof_keys"]] == [l.split()[1] for l in E["PERPS_KEY_PINS"].splitlines()] +assert {k: v for k, v in p.items() if k not in ("genesis_root", "bound_payouts", "sparse_windows", "max_window_heights", "engine_program_log_height", "max_pending_digests", "state_proof_keys")} \ == {k: v for k, v in g21["perps"].items() if k != "genesis_root"} assert p["genesis_root"] == "ab" * 32 assert p["bound_payouts"] is True and p["sparse_windows"] is True and p["max_window_heights"] == 256 and p["engine_program_log_height"] == 14 @@ -2570,23 +2682,24 @@ assert sum(n["amount"] for n in g["alloc"] if n["opening"].get("asset", 0) == 0) assert sum(n["amount"] for n in g["alloc"] if n["opening"].get("asset", 0) == 1) == 10000199900 assert all(sum(len(v) // 2 for v in n["envelope"].values()) == 1860 for n in g["alloc"]) PY - then ok "the chain-21 fixture assembles into a chain-22 genesis: chain 21's keys in chain 21's order and every section chain 21's, plus program_state.refuse_panics true (PST-1), perps bound_payouts true (PERP-6), sparse_windows true + max_window_heights 256 (PERP-101), engine_program_log_height 14 (CON-60), max_pending_digests 65536 (PERP-5), no initial_collateral, multisig.max_accounts 1 (MSA-4), tokens.incremental_root true, program_state.reference_block_window 256 (#168), the beacon last with 25 commitments and delay 256 (#189); 25 validators, archive2 dropped; the treasury 5 of 6 with six new signers (none of chain 21's), fresh salt, 100000 RAND carried from chain 21's multisig register (= multisig_rand_held), perps carried (empty) with no override; floors 3/5/3/7, burn sequence 14, 100.001999 zUSD locked on four backings"; else bad "assembled genesis content"; fi + then ok "the chain-21 fixture assembles into a chain-22 genesis: chain 21's keys in chain 21's order and every section chain 21's, plus program_state.refuse_panics true (PST-1), perps bound_payouts true (PERP-6), sparse_windows true + max_window_heights 256 (PERP-101), engine_program_log_height 14 (CON-60), max_pending_digests 65536 (PERP-5), the four pinned tier-18 state-proof keys at the committed files' digests (CON-601), no initial_collateral, multisig.max_accounts 1 (MSA-4), tokens.incremental_root true, program_state.reference_block_window 256 (#168), the beacon last with 25 commitments and delay 256 (#189); 25 validators, archive2 dropped; the treasury 5 of 6 with six new signers (none of chain 21's), fresh salt, 100000 RAND carried from chain 21's multisig register (= multisig_rand_held), perps carried (empty) with no override; floors 3/5/3/7, burn sequence 14, 100.001999 zUSD locked on four backings"; else bad "assembled genesis content"; fi else bad "the happy path refused"; fi cp "$ST/out.json" "$ST/good.json" export -f py_validators py_splice py_treasury py_variants py_beacon - # The field probe's variants (the probe itself needs a rand-node: DRY_RUN runs it): 37 on the - # finished file — the audit-v10 eight, the window (+ beacon) and the window at 257, the beacon and + # The field probe's variants (the probe itself needs a rand-node: DRY_RUN runs it): 39 on the + # finished file — the audit-v10 eight, CON-601's two, the window (+ beacon) and the window at 257, the beacon and # its delay at 257, each of the 25 commitments changed — each a different file, each still with # chain 21's other fields. rm -rf "$ST/vtmp"; mkdir -p "$ST/vtmp" - if OUT=$ST/good.json TMP=$ST/vtmp bash -c py_variants && [ "$(cat "$ST/vtmp/variants/count")" = 37 ] \ + if OUT=$ST/good.json TMP=$ST/vtmp bash -c py_variants && [ "$(cat "$ST/vtmp/variants/count")" = 39 ] \ && python3 - "$ST/vtmp/variants" "$ST/good.json" <<'PY' import glob, json, os, sys d, g = sys.argv[1], json.load(open(sys.argv[2])) names = sorted(os.path.basename(f)[:-5] for f in glob.glob(d + "/*.json")) assert names == sorted(["program_state.refuse_panics", "multisig.max_accounts", "perps.bound_payouts", "perps.sparse_windows+max_window_heights+max_pending_digests", - "perps.max_window_heights=257", "perps.engine_program_log_height", "perps.max_pending_digests", "tokens.incremental_root", + "perps.max_window_heights=257", "perps.engine_program_log_height+state_proof_keys", "perps.max_pending_digests", "tokens.incremental_root", + "perps.state_proof_keys", "perps.state_proof_keys.0.sha256", "program_state.reference_block_window+beacon", "program_state.reference_block_window=257", "beacon", "beacon.commit_delay_blocks=257"] + [f"beacon.commitments.{i:02d}" for i in range(25)]), names v = json.load(open(d + "/program_state.reference_block_window+beacon.json")) @@ -2606,11 +2719,17 @@ assert not {"sparse_windows", "max_window_heights", "max_pending_digests"} & set v = json.load(open(d + "/perps.max_pending_digests.json")) assert "max_pending_digests" not in v["perps"] and v["perps"]["sparse_windows"] is True and v["perps"]["max_window_heights"] == 256 assert json.load(open(d + "/perps.max_window_heights=257.json"))["perps"]["max_window_heights"] == 257 +v = json.load(open(d + "/perps.engine_program_log_height+state_proof_keys.json"))["perps"] +assert not {"engine_program_log_height", "state_proof_keys"} & set(v) and v["max_pending_digests"] == 65536 +v = json.load(open(d + "/perps.state_proof_keys.json"))["perps"] +assert "state_proof_keys" not in v and v["engine_program_log_height"] == 14 +v = json.load(open(d + "/perps.state_proof_keys.0.sha256.json"))["perps"]["state_proof_keys"] +assert v[1:] == g["perps"]["state_proof_keys"][1:] and v[0]["sha256"] != g["perps"]["state_proof_keys"][0]["sha256"] and v[0]["sha256"][:-1] == g["perps"]["state_proof_keys"][0]["sha256"][:-1] for f in glob.glob(d + "/*.json"): x = json.load(open(f)) assert x != g and set(x) - {"beacon"} == set(g) - {"beacon"}, f # only the beacon's own variants drop a top-level key PY - then ok "the field probe writes its 37 variants (refuse_panics, max_accounts, bound_payouts, sparse_windows+max_window_heights+max_pending_digests, max_window_heights 257, engine_program_log_height, max_pending_digests, incremental_root; reference_block_window+beacon, reference_block_window 257, beacon, commit_delay_blocks 257, and each of the 25 commitments changed alone to a value no validator holds)" + then ok "the field probe writes its 39 variants (refuse_panics, max_accounts, bound_payouts, sparse_windows+max_window_heights+max_pending_digests, max_window_heights 257, engine_program_log_height+state_proof_keys, state_proof_keys, a pinned key digest changed, max_pending_digests, incremental_root; reference_block_window+beacon, reference_block_window 257, beacon, commit_delay_blocks 257, and each of the 25 commitments changed alone to a value no validator holds)" else bad "field probe variants: $(find "$ST/vtmp/variants" -name '*.json' 2>&1 | sed 's|.*/||' | tr '\n' ' ')"; fi # AUDIT_V10_SKIPPED (DRY_RUN's path on a build before v0.8.2): the base and the section files as @@ -2622,7 +2741,7 @@ PY import json, sys b, p, m = (json.load(open(f)) for f in sys.argv[1:4]) del b["program_state"]["refuse_panics"]; b["multisig"] = m -for k in ("bound_payouts", "sparse_windows", "max_window_heights", "engine_program_log_height", "max_pending_digests"): +for k in ("bound_payouts", "sparse_windows", "max_window_heights", "engine_program_log_height", "max_pending_digests", "state_proof_keys"): del p[k] json.dump(b, open(sys.argv[1], "w")); json.dump(p, open(sys.argv[2], "w")) PY @@ -2865,6 +2984,16 @@ PY refuse "maintenance 500 bps at 20x (= initial)" "$PJ" 'd["markets"][0]["maintenance_bps"] = 500' "at or above the initial margin 500 bps" refuse "max_block_inputs 25" "$PJ" 'd["max_block_inputs"] = 25' "max_block_inputs is 25, not 24" refuse "max_tier 20" "$PJ" 'd["max_tier"] = 20' "max_tier is 20, not 18" + # CON-601: the pinned state-proof keys — the four canonical shapes, each at its shipped file's digest + refuse "no perps.state_proof_keys (CON-601)" "$PJ" 'del d["state_proof_keys"]' "perps carries the fields" + refuse "a pinned key digest off its file" "$PJ" 'd["state_proof_keys"][2]["sha256"] = "cd" * 32' "but the shipped file" + refuse "three pinned keys, not four" "$PJ" 'd["state_proof_keys"].pop()' "not the four canonical tier-18 shapes" + refuse "a pinned key at tier 16" "$PJ" 'd["state_proof_keys"][0]["tier"] = 16' "not the four canonical tier-18 shapes" + refuse "a pinned key at poseidon2 height 18" "$PJ" 'd["state_proof_keys"][3]["poseidon2_log_height"] = 18' "not the four canonical tier-18 shapes" + refuse "the pinned keys out of order" "$PJ" 'd["state_proof_keys"].reverse()' "not the four canonical tier-18 shapes" + refuse "a pinned key with a stray field" "$PJ" 'd["state_proof_keys"][0]["note"] = 1' "not the four canonical tier-18 shapes" + refuse "a key file this rand-node does not pin" "$PJ" 'pass' "not this rand-node's pin" PERPS_KEY_PINS="$(sed '1s/ .*/ '"$(printf 'ee%.0s' $(seq 32))"'/' <<<"$PERPS_KEY_PINS")" + refuse "no key file in PERPS_KEY_DIR" "$PJ" 'pass' "no key file" PERPS_KEY_DIR="$ST/no-keys" refuse "a tick at nine decimals (10^9 = \$10)" "$PJ" 'd["markets"][0]["tick"] = 1000000000' "perps is not chain 21's section: ['markets'] differ" refuse "min_deposit at nine decimals (10 zUSD)" "$PJ" 'd["min_deposit"] = 1000000000' "perps is not chain 21's section: ['min_deposit'] differ" refuse "an unknown perps field" "$PJ" 'd["extra"] = 1' "perps carries the fields" @@ -3076,7 +3205,8 @@ bk = ({"enabled": True, "height": 0, "value": "5e" * 32, "commit_delay_blocks": for c in sorted(b["commitments"], key=lambda c: c["validator"])]} if b else {"enabled": False}) json.dump({"rand_getGenesisHash": "ab" * 32, "rand_getBlockContext": ctx, "rand_getBeacon": bk, - "rand_status": {"chain_id": 22, "hc_bundle": g["hc_bundle"], "hc_auth": g["hc_auth"], "hc_auth_multisig": g["hc_auth_multisig"], "fri_profile": "production"}, + "rand_status": {"chain_id": 22, "hc_bundle": g["hc_bundle"], "hc_auth": g["hc_auth"], "hc_auth_multisig": g["hc_auth_multisig"], "fri_profile": "production", + "perps_keys": {"source": "loaded" if p.get("state_proof_keys") else "absent", "keys": len(p.get("state_proof_keys", []))}}, "rand_getLimits": {"proof_window_blocks": 1024, "binding_domain": 1, "testnet": True, "admission_by_vote": True, "slashing": None, "max_gas_price": d["max_gas_price"], "max_byte_price": d["max_byte_price"], "byte_load": "paying", "gas_metering": "circuit", "bundle_gas_limit": 22527, "adjust_bps": 1250, "envelope_bytes": 1860, @@ -3091,6 +3221,7 @@ json.dump({"rand_getGenesisHash": "ab" * 32, "rand_getPerps": {"enabled": True, "collateral_asset": 1, "max_tier": 18, "max_window_blocks": 64, "sparse_windows": p.get("sparse_windows", False), "max_window_heights": p.get("max_window_heights", 0), "engine_program_log_height": p.get("engine_program_log_height", 0), "max_pending_digests": p.get("max_pending_digests", 0), + "state_proof_keys": p.get("state_proof_keys", []), "max_block_inputs": 24, "min_deposit": "100000000", "engine_hc": p["engine_hc"], "genesis_root": p["genesis_root"], "markets": p["markets"], "proved_root": p["genesis_root"], "proved_height": 0, "head_height": 0, "pending_heights": [], "medians": [], @@ -3154,6 +3285,8 @@ json.dump(a, open(p,'w'))" "$ST/answers.json" 'P["accounts"] = 1' 'P["pending_withdrawals"] = 1' 'P["sparse_windows"] = False' 'P["max_window_heights"] = 0' 'P["max_window_heights"] = 64' \ 'P["engine_program_log_height"] = 0' 'P["engine_program_log_height"] = 15' \ 'P["max_pending_digests"] = 0' 'P["max_pending_digests"] = 1048576' 'del P["max_pending_digests"]' \ + 'P["state_proof_keys"] = []' 'del P["state_proof_keys"]' 'P["state_proof_keys"].pop()' 'P["state_proof_keys"][0]["sha256"] = "cd" * 32' \ + 'a["rand_status"]["perps_keys"] = {"source": "absent", "keys": 0}' 'a["rand_status"]["perps_keys"]["keys"] = 3' 'del a["rand_status"]["perps_keys"]' \ 'L["multisig"] = None' 'L["multisig"]["create_fee"] = "0"' 'del L["multisig"]["max_accounts"]' 'L["multisig"]["max_accounts"] = 2' \ 'S["multisig_issued"] = "0"' 'M["threshold"] = 3' 'M["threshold"] = 2' 'M["signers"].reverse()' 'a["rand_getMultisig"] = None' \ 'T["incremental_root"] = False' 'del T["incremental_root"]' 'T["bound_note_value"] = False' \ @@ -3366,6 +3499,29 @@ json.dump(a, open(p,'w'))" "$ST/answers.json" fp_case "a missing fee recipient file is refused" refuse "no fee recipient file" FAKE_WALLET="$ST/fake-rand" FEE_RECIPIENT_FILE="$ST/none.txt" fp_case "a fee recipient file of two lines is refused" refuse "more than one line" FAKE_WALLET="$ST/fake-rand" FEE_RECIPIENT_FILE="$ST/fee-two.txt" fp_case "a wallet that prints no fingerprint is refused" refuse "printed no fingerprint" FAKE_WALLET=/usr/bin/true FEE_RECIPIENT_FILE="$ST/fee-ok.txt" + # CON-601: perps_keys_step against a fake rand-node whose `keygen-perp-vk` answers from the + # committed files (--print-pinned: PERPS_KEY_PINS, or FAKE_PINS; --check: the file's sha256; + # --genesis-json: PERPS_STATE_PROOF_KEYS_JSON), and a copy of the files with one byte changed. + # shellcheck disable=SC2016 # the fake's own source + printf '#!/usr/bin/env bash\n[ "$1" = keygen-perp-vk ] || exit 1\n[ -z "${FAKE_NO_PVK:-}" ] || exit 2\ncase "$2" in\n --help) echo usage;;\n --print-pinned) printf "%%s\\n" "${FAKE_PINS:-$PERPS_KEY_PINS}";;\n --check) shasum -a 256 "$3" 2>/dev/null | cut -c1-64;;\n --genesis-json) printf "%%s\\n" "$FAKE_SPK_JSON";;\n *) exit 1;;\nesac\n' > "$ST/fake-pvk-node"; chmod +x "$ST/fake-pvk-node" + mkdir -p "$ST/pvk-bad"; cp "$PERPS_KEY_DIR"/perp-vk-production-*.bin "$ST/pvk-bad/" + f=$(ls "$ST/pvk-bad"/perp-vk-production-t18-pg14-in16-pub8-p2h20.bin); printf '\001' | dd of="$f" bs=1 seek=100 conv=notrunc 2>/dev/null + export -f perps_keys_step + pk_case() { # + local what=$1 want=$2 phrase=$3; shift 3 + # shellcheck disable=SC2016 # expanded by the child bash + if env NODE="$ST/fake-pvk-node" FAKE_SPK_JSON="$PERPS_STATE_PROOF_KEYS_JSON" PERPS_STATE_PROOF_KEYS_JSON= RAND_PERPS_KEY_DIR= "$@" bash -c 'perps_keys_step && [ -n "$PERPS_STATE_PROOF_KEYS_JSON" ] && [ -d "$RAND_PERPS_KEY_DIR" ] && echo "json $PERPS_STATE_PROOF_KEYS_JSON"' >"$ST/log" 2>&1; then r=ok; else r=refuse; fi + if [ "$r" = "$want" ] && grep -qF -- "$phrase" "$ST/log"; then ok "perps_keys_step: $what — $(grep -o 'cut-chain22: .*' "$ST/log" | tail -1 | cut -c1-110)" + else bad "perps_keys_step: $what — got $r: $(tail -1 "$ST/log")"; fi + } + pk_case "the committed files, each this rand-node's pin" ok "4 files in" + pk_case "a file with one byte changed" refuse "not this rand-node's pin" PERPS_KEY_DIR="$ST/pvk-bad" + pk_case "a rand-node whose pins are pending (no key files yet)" refuse "no key file yet" FAKE_PINS="$(sed 's/ .*/ '"$(printf '0%.0s' $(seq 64))"'/' <<<"$PERPS_KEY_PINS")" + pk_case "a rand-node pinning three files" refuse "pins 3 state-proof key files, not the four" FAKE_PINS="$(head -3 <<<"$PERPS_KEY_PINS")" + pk_case "a missing PERPS_KEY_DIR" refuse "is not a directory" PERPS_KEY_DIR="$ST/no-keys" + mkdir -p "$ST/pvk-three"; cp "$PERPS_KEY_DIR"/perp-vk-production-t18-pg14-in16-pub{7,8,9}-p2h20.bin "$ST/pvk-three/" + pk_case "a PERPS_KEY_DIR without one of the files" refuse "no key file" PERPS_KEY_DIR="$ST/pvk-three" + pk_case "a rand-node without keygen-perp-vk (before CON-601)" refuse "has no keygen-perp-vk" FAKE_NO_PVK=1 # A fake rand-node: `genesis --help` lists every flag the cut needs but FAKE_DROP (one flag left # out) and --program-state-refuse-panics only unless FAKE_V10_FLAG is set empty; `--version` says # FAKE_VERSION (default 0.8.5); nothing else answers (init prints no hash). A fake perp-prover and engine image. @@ -3639,8 +3795,8 @@ require_cut_record_mentions "$CUT_RECORD" 'PERP-101|sparse.windows|max_window_he # build that key (3.56 GB resident measured; docs/perps.md "the node's tier cap"), and no node # policy can refuse a valid block. Decided 2026-11-19 (OPEN 9): validators load the pinned # tier-18 state-proof key (genesis pin), never build it; the record says so. -# TODO(CON-601): when the pinned-key genesis field exists, the cut asserts it (py_splice, at the -# perps max_tier check); until then this record line is the only CON-601 gate. +# The field itself, perps.state_proof_keys, is asserted by py_splice (at the perps max_tier check) +# from the shipped files (perps_keys_step), probed in the hash and read back by check-limits. require_cut_record_mentions "$CUT_RECORD" 'CON-601|pinned.*state.proof.key|validator.memory|key.build' "CON-601 (validators load the pinned tier-18 state-proof key, genesis pin, never build it: monorepo#23)" reason carries clients # The two features the owner added on 2026-11-18: the record says the chain carries them. require_cut_record_mentions "$CUT_RECORD" '#168|#184|reference.block|block.context' "the EVM block context (#168, program_state.reference_block_window)" reason carries @@ -3817,6 +3973,9 @@ T21=$(treasury_id_of "$CHAIN21_GENESIS") [ "$T21" = "$CHAIN21_TREASURY_ID" ] || { echo "cut-chain22: $NODE derives chain 21's treasury id '${T21:-nothing}', not CHAIN21_TREASURY_ID $CHAIN21_TREASURY_ID" >&2; exit 1; } echo "cut-chain22: chain 21's treasury id ${T21:0:12}… (rand-node multisig id over its genesis account)" +# CON-601: the pinned state-proof keys, from the shipped files (before the perps section is written). +[ -n "${PERPS_SKIPPED:-}${AUDIT_V10_SKIPPED:-}" ] || perps_keys_step + py_validators # The beacon (#189): BEACON_TSV joined by name with the validators, at the addresses their public @@ -3990,7 +4149,7 @@ cut-chain22: block context: $([ -n "${BLOCK_CONTEXT_SKIPPED:-}" ] && echo "SKIPP cut-chain22: beacon: $([ -n "${BLOCK_CONTEXT_SKIPPED:-}" ] && echo "SKIPPED — NOT what chain 22 will be" || echo "$VALIDATOR_COUNT commitments from $BEACON_TSV, commit_delay_blocks $BEACON_COMMIT_DELAY_BLOCKS (#189) — OWNER VALUE TO CONFIRM (OPEN 10); $BC_RECORDED") cut-chain22: fees: $FEES_JSON (no subsidy_net_of_fees: aggregation is refused until re-measured) cut-chain22: perps: $([ -n "${PERPS_SKIPPED:-}" ] && echo "SKIPPED (no PERP_PROVER) — NOT what chain 22 will be" || echo "BTC-PERP on zUSD (asset 1), lot 100000, tick 100000000, 20x, maintenance 250 bps, fees 5/2 bps; max_tier 18, 24 inputs a block, 64 blocks a proof, min deposit 100000000 (1 zUSD)") -cut-chain22: perps audit v10: $([ -n "${PERPS_SKIPPED:-}${AUDIT_V10_SKIPPED:-}" ] && echo "SKIPPED — NOT what chain 22 will be" || echo "bound_payouts true (PERP-6), initial_collateral absent (0), sparse_windows true + max_window_heights $PERPS_MAX_WINDOW_HEIGHTS (PERP-101), engine_program_log_height $ENGINE_PROGRAM_LOG_HEIGHT (CON-60), max_pending_digests $PERPS_MAX_PENDING_DIGESTS (PERP-5, decided 2026-11-05)") +cut-chain22: perps audit v10: $([ -n "${PERPS_SKIPPED:-}${AUDIT_V10_SKIPPED:-}" ] && echo "SKIPPED — NOT what chain 22 will be" || echo "bound_payouts true (PERP-6), initial_collateral absent (0), sparse_windows true + max_window_heights $PERPS_MAX_WINDOW_HEIGHTS (PERP-101), engine_program_log_height $ENGINE_PROGRAM_LOG_HEIGHT (CON-60), max_pending_digests $PERPS_MAX_PENDING_DIGESTS (PERP-5, decided 2026-11-05), state_proof_keys: the four tier-18 keys from $PERPS_KEY_DIR (CON-601)") cut-chain22: perps engine_hc: $([ -n "${PERPS_SKIPPED:-}" ] && echo "SKIPPED" || echo "$EXPECT_ENGINE_HC ($PERP_IMAGE)") cut-chain22: PERPS GENESIS ROOT ${PERP_GENESIS_ROOT:-SKIPPED} cut-chain22: multisig: create_fee $MULTISIG_CREATE_FEE (1 RAND)$([ -n "${AUDIT_V10_SKIPPED:-}" ] && echo ", max_accounts SKIPPED" || echo ", max_accounts $MULTISIG_MAX_ACCOUNTS (MSA-4)"); the treasury $TREASURY_THRESHOLD of $TREASURY_SIGNERS (six new signers, none of chain 21's), $(python3 -c 'import os,sys; exec(os.environ["UNITS_PY"]); print(fmt(int(open(sys.argv[1]).read())))' "$TMP/treasury-balance") RAND carried from chain 21's multisig register (= its multisig_rand_held), salt $(python3 -c 'import json,sys; print(json.load(open(sys.argv[1]))["accounts"][0]["salt"])' "$TMP/multisig.json") @@ -4005,7 +4164,7 @@ cut-chain22: CONSTRAINT-SET ROW — OPEN (issue #166): add this line to CHAIN_CO $CS_ROW cut-chain22: before each validator's node starts, ON ITS HOST: deploy/check-beacon-seed.sh --genesis $OUT --datadir --key (its beacon.seed.json opens its genesis commitment); after the start, the same with --rpc 127.0.0.1:8545 cut-chain22: after launch: NODE=… $0 check-limits $OUT (before the first bundle, deposit and state proof) -cut-chain22: operations: msauth-vk-production.bin (sha256 168d79a8…71b3, constraint set 11) beside rand-node on every chain-22 node; NTP on every validator (perps block time is consensus input); a perp-view service and a prover host (~22 GB a proof) whose perp-prover builds sparse jobs (durian 28cebfb+); token collateral is outside the supply audit (M6). +cut-chain22: operations: msauth-vk-production.bin (sha256 168d79a8…71b3, constraint set 11) and the four perp-vk-production-t18-*.bin (perps.state_proof_keys, CON-601) beside rand-node on every chain-22 node; NTP on every validator (perps block time is consensus input); a perp-view service and a prover host (~22 GB a proof) whose perp-prover builds sparse jobs (durian 28cebfb+); token collateral is outside the supply audit (M6). ⚠ Stamped $AGE s ago; the chain's clock starts there. Launch within MINUTES, or delete $OUT and re-cut. EOF diff --git a/deploy/roll-all.sh b/deploy/roll-all.sh index b5ac5e65..c74f54b9 100755 --- a/deploy/roll-all.sh +++ b/deploy/roll-all.sh @@ -17,6 +17,15 @@ # /usr/local/bin/msauth-vk-production.bin, beside the binary, before anything restarts. Node A # on this Mac (when its launchd job is installed) gets the same file beside its own binary. # +# The perps state-proof verifier keys (CON-601, chain 22's `perps.state_proof_keys`) are the +# directory PERPS_VK_DIR holding the release's four perp-vk-production-*.bin. A node whose genesis +# names state_proof_keys refuses to start without every one, so a roll without PERPS_VK_DIR is +# refused when any droplet's genesis names it (or cannot be read). Each host holds every file +# the new build pins (`rand-node.new keygen-perp-vk --print-pinned production`: " " +# lines) to that pin, by sha256sum and by `--check`; a mismatch or a missing file skips the +# host's install, binaries included. Installed in /usr/local/bin beside the binary. With +# RELEASE_SUMS each file must also be the one the signed SHA256SUMS lists. +# # 1. copies both binaries to every droplet in deploy/nodes.env and installs them only when each # copy's sha256 equals the expected one (the release tag's), keeping the previous rand-node # beside it as /root/rand-node.prev; nothing restarts yet; @@ -48,6 +57,12 @@ if [ -n "$MSAUTH_VK" ]; then elif [ "${NO_MSAUTH_VK:-}" != 1 ]; then echo "no msauth-vk-production.bin (fifth argument or MSAUTH_VK): a v0.8.0+ node on a chain naming hc_auth_multisig refuses to start without it; pass it, or NO_MSAUTH_VK=1 for a chain without multisig"; exit 1 fi +PERPS_VK_DIR=${PERPS_VK_DIR:-} +PERPS_VKS=() +if [ -n "$PERPS_VK_DIR" ]; then + for f in "$PERPS_VK_DIR"/perp-vk-production-*.bin; do [ -f "$f" ] && PERPS_VKS+=("$f"); done + [ "${#PERPS_VKS[@]}" -eq 4 ] || { echo "PERPS_VK_DIR $PERPS_VK_DIR holds ${#PERPS_VKS[@]} perp-vk-production-*.bin, not the release's four"; exit 1; } +fi . deploy/lib/verify-release.sh . deploy/lib/unit-limits.sh if [ -n "${RELEASE_SUMS:-}" ] || [ -n "${RELEASE_SIG:-}" ]; then @@ -58,6 +73,7 @@ if [ -n "${RELEASE_SUMS:-}" ] || [ -n "${RELEASE_SIG:-}" ]; then [ "$WANT" = "$(release_sha "$RELEASE_SUMS" rand-node)" ] || { echo "the expected rand-node sha256 given here is not the one the signed SHA256SUMS lists — not rolling"; exit 1; } [ "$WANT_WALLET" = "$(release_sha "$RELEASE_SUMS" rand)" ] || { echo "the expected rand sha256 given here is not the one the signed SHA256SUMS lists — not rolling"; exit 1; } [ -z "$MSAUTH_VK" ] || verify_binary "$MSAUTH_VK" "$RELEASE_SUMS" msauth-vk-production.bin || exit 1 + for f in "${PERPS_VKS[@]}"; do verify_binary "$f" "$RELEASE_SUMS" "$(basename "$f")" || exit 1; done else echo "################################################################################" echo "# UNSIGNED ROLL: no RELEASE_SUMS/RELEASE_SIG. Nothing ties these binaries to a" @@ -91,6 +107,18 @@ if [ -z "$MSAUTH_VK" ]; then done [ -f ~/Library/LaunchAgents/org.randprotocol.node-a.plist ] && echo " note: node A's launchd job is installed and its genesis is not checked under NO_MSAUTH_VK=1" fi +# Without PERPS_VK_DIR: no droplet's genesis may name perps.state_proof_keys (the same read of +# `/genesis.json` as above; serde omits the key when the list is empty). +if [ -z "$PERPS_VK_DIR" ]; then + for ip in $IPS; do + pk=$(ssh -o ConnectTimeout=15 -o BatchMode=yes root@$ip 'D=$(systemctl cat rand-node 2>/dev/null | grep -oE -- "--datadir[= ][^ ]*" | tail -1 | sed -E "s/^--datadir[= ]//"); [ -n "$D" ] && [ -r "$D/genesis.json" ] || { echo "unreadable ${D:-}/genesis.json"; exit 0; }; if grep -q "\"state_proof_keys\"" "$D/genesis.json"; then echo "pinned $D/genesis.json"; else echo "plain"; fi' 2>/dev/null) + case "$pk" in + plain) ;; + pinned*) echo "no PERPS_VK_DIR but $ip's genesis names perps.state_proof_keys (${pk#pinned }): its node refuses to start without the four perp-vk-production-*.bin — pass PERPS_VK_DIR"; exit 1 ;; + *) echo "no PERPS_VK_DIR and $ip's genesis could not be read (${pk:-ssh failed}): cannot confirm it pins no state-proof keys — pass PERPS_VK_DIR, or fix the host first"; exit 1 ;; + esac + done +fi echo "== install (no restart) $(date -u +%H:%M:%S)" # The msauth key blob's check and install, run on the host before the binaries' install (empty # when the roll carries no blob): the copy is intact (sha256) and is the blob the build being @@ -102,6 +130,12 @@ VK_STEP="if [ -f /usr/local/bin/msauth-vk-production.bin ]; then vk_got=\$(/root if [ -n "$MSAUTH_VK" ]; then VK_STEP="[ \"\$(sha256sum /root/msauth-vk-production.bin.new | cut -d' ' -f1)\" = \"$VK_SHA\" ] && vk_got=\$(/root/rand-node.new keygen-msauth-vk --check /root/msauth-vk-production.bin.new) && vk_pin=\$(/root/rand-node.new keygen-msauth-vk --print-pinned production) && [ \"\$vk_got\" = \"\$vk_pin\" ] || { echo \" msauth key blob is not the pinned \${vk_pin:-?} (has \${vk_got:-?}), skipping\"; rm -f /root/rand-node.new /root/rand.new /root/msauth-vk-production.bin.new; exit 1; }; install -m 644 /root/msauth-vk-production.bin.new /usr/local/bin/msauth-vk-production.bin; rm -f /root/msauth-vk-production.bin.new;" fi +# CON-601: the perps key files' check and install (empty without PERPS_VK_DIR): every file the new +# build pins is in /root/perp-vk.new with exactly that sha256, by sha256sum and `--check`. +PVK_STEP= +if [ -n "$PERPS_VK_DIR" ]; then + PVK_STEP="pvk_n=0; while read -r pvk_name pvk_pin; do [ -n \"\$pvk_name\" ] || continue; [ \"\$(sha256sum /root/perp-vk.new/\$pvk_name 2>/dev/null | cut -d' ' -f1)\" = \"\$pvk_pin\" ] && [ \"\$(/root/rand-node.new keygen-perp-vk --check /root/perp-vk.new/\$pvk_name)\" = \"\$pvk_pin\" ] || { echo \" perps key \$pvk_name is not the pinned \$pvk_pin, skipping\"; rm -rf /root/rand-node.new /root/rand.new /root/perp-vk.new; exit 1; }; pvk_n=\$((pvk_n + 1)); done < <(/root/rand-node.new keygen-perp-vk --print-pinned production); [ \"\$pvk_n\" -eq 4 ] || { echo \" this build pins \$pvk_n perps key files, not 4, skipping\"; rm -rf /root/rand-node.new /root/rand.new /root/perp-vk.new; exit 1; }; install -m 644 /root/perp-vk.new/perp-vk-production-*.bin /usr/local/bin/; rm -rf /root/perp-vk.new;" +fi # PROC-601: the limits drop-in, written on the host after the binaries and before the restart. LIMITS_STEP=$(unit_limits_install_script rand-node) for ip in $IPS; do @@ -109,7 +143,11 @@ for ip in $IPS; do if [ -n "$MSAUTH_VK" ]; then scp -q -o ConnectTimeout=15 -o BatchMode=yes "$MSAUTH_VK" root@$ip:/root/msauth-vk-production.bin.new || { echo " $ip: msauth key copy failed"; ssh -o ConnectTimeout=15 -o BatchMode=yes root@$ip 'rm -f /root/rand-node.new /root/rand.new /root/msauth-vk-production.bin.new' 2>/dev/null; continue; } fi - ssh -o ConnectTimeout=15 -o BatchMode=yes root@$ip "set -e; [ \"\$(sha256sum /root/rand-node.new | cut -d' ' -f1)\" = \"$WANT\" ] && [ \"\$(sha256sum /root/rand.new | cut -d' ' -f1)\" = \"$WANT_WALLET\" ] || { echo ' sha mismatch, skipping'; rm -f /root/rand-node.new /root/rand.new /root/msauth-vk-production.bin.new; exit 1; }; chmod 755 /root/rand-node.new; $VK_STEP cp -f /usr/local/bin/rand-node /root/rand-node.prev; install -m 755 /root/rand-node.new /usr/local/bin/rand-node; install -m 755 /root/rand.new /usr/local/bin/rand; rm -f /root/rand-node.new /root/rand.new + if [ -n "$PERPS_VK_DIR" ]; then + { ssh -o ConnectTimeout=15 -o BatchMode=yes root@$ip 'rm -rf /root/perp-vk.new && mkdir -p /root/perp-vk.new' && scp -q -o ConnectTimeout=15 -o BatchMode=yes "${PERPS_VKS[@]}" root@$ip:/root/perp-vk.new/; } \ + || { echo " $ip: perps key copy failed"; ssh -o ConnectTimeout=15 -o BatchMode=yes root@$ip 'rm -rf /root/rand-node.new /root/rand.new /root/msauth-vk-production.bin.new /root/perp-vk.new' 2>/dev/null; continue; } + fi + ssh -o ConnectTimeout=15 -o BatchMode=yes root@$ip "set -e; [ \"\$(sha256sum /root/rand-node.new | cut -d' ' -f1)\" = \"$WANT\" ] && [ \"\$(sha256sum /root/rand.new | cut -d' ' -f1)\" = \"$WANT_WALLET\" ] || { echo ' sha mismatch, skipping'; rm -f /root/rand-node.new /root/rand.new /root/msauth-vk-production.bin.new; exit 1; }; chmod 755 /root/rand-node.new; $VK_STEP $PVK_STEP cp -f /usr/local/bin/rand-node /root/rand-node.prev; install -m 755 /root/rand-node.new /usr/local/bin/rand-node; install -m 755 /root/rand.new /usr/local/bin/rand; rm -f /root/rand-node.new /root/rand.new $LIMITS_STEP echo \" \$(hostname): installed \$(/usr/local/bin/rand-node --version)\"" 2>&1 | tail -1 done diff --git a/deploy/sync-zkvm.sh b/deploy/sync-zkvm.sh index 372895b7..f7c555d3 100755 --- a/deploy/sync-zkvm.sh +++ b/deploy/sync-zkvm.sh @@ -152,6 +152,8 @@ # §4) adds `src/auth.rs` (the auth guest's input layout and `c = H(AUTH, nk, salt)`, node-local tag # 65) and `tests/auth*.rs` (the P2-0 spike and what follows it), both excluded below for the same # reason; the guest itself is `guests::auth()` in the already-excluded `guests.rs`. +# CON-601 adds `tests/perp_vk.rs` (excluded below): the chain-22 pinned state-proof key files' +# checks, against `executor::perp_vk` in the (already excluded) `executor.rs`. # # Audit finding ZKV-2 (circuits 224960c): the Poseidon2 round constants are a committed literal # table, `src/poseidon2_constants.rs`, instead of a seeded `StdRng` draw (`rand` does not promise @@ -261,7 +263,7 @@ rsync -a --delete --exclude target --exclude .git --exclude Cargo.lock --exclude rsync -a --delete --exclude executor.rs --exclude shielded.rs --exclude call_envelope.rs \ --exclude viewing.rs --exclude bundle.rs --exclude hidden_bundle.rs \ --exclude hidden_cheating.rs --exclude hidden_trace_forgery.rs --exclude guest_provenance.rs --exclude 'auth*.rs' --exclude evm_rt.rs --exclude sbpf_rt.rs \ - --exclude perps_vectors.rs --exclude modq_cheating.rs \ + --exclude perps_vectors.rs --exclude modq_cheating.rs --exclude perp_vk.rs \ --exclude counter_rng.rs --exclude decode_memo.rs --exclude agents_counts.rs \ "$SRC/tests/" "$DST/tests/" [ -f "$DST/src/guests.rs" ] || cp "$SRC/src/guests.rs" "$DST/src/guests.rs" diff --git a/docs/deploy.md b/docs/deploy.md index 802f21b5..60dae060 100644 --- a/docs/deploy.md +++ b/docs/deploy.md @@ -120,6 +120,9 @@ rand-node verify --datadir /root/data-- --mode full # stop t On a chain whose genesis names `hc_auth_multisig`, `rand-node verify` loads the pinned msauth verifier key exactly as `run` does (below, "The msauth verifier key") and refuses to verify without it. +On a chain whose genesis names `perps.state_proof_keys` (chain 22), `run` and `verify` load the +pinned perps state-proof keys the same way (below, "The perps state-proof verifier keys") and refuse +without them. ### Reserved peers (audit v6, NET-1) @@ -587,6 +590,65 @@ A node on a chain whose genesis names `hc_auth_multisig` verifies multisig autho It compares against the pin of the binary being installed on that host (`rand-node.new`), not a pin read on the operator's machine, so a blob and a build from different commits never pair. +## The perps state-proof verifier keys (CON-601, chain 22 onward) + +A block carrying a tier-18 perps state proof used to make every validator build that shape's +verifier key on first sight (~1.7 GB peak with `parallel`, ~3.3–4 GB without): a 2 GB validator +could OOM on someone else's proof. Chain 22 pins the keys instead. Validators load them from +shipped files at startup and never build one. + +- **The genesis field.** `perps.state_proof_keys`, a list of up to 8 + `{tier, program_log_height, input_log_height, public_log_height, poseidon2_log_height, sha256}` + (sha256 = lowercase hex of the key file's raw bytes), in strictly increasing shape order. It + needs `perps.engine_program_log_height` and must name only canonical state-proof shapes of the + chain (tier ≤ `max_tier`, program = the engine's height, input ≤ min(tier+2, 16), poseidon2 even + ≤ tier+2, public in 7..= what `max_window_blocks` needs). It is serde-default and omitted when + empty, and bound into the genesis hash only when set, so chain 21's hash does not move. +- **The rule.** When the list is non-empty, a state proof whose declared shape is not in it is + refused before any key is touched, at validate and at apply (`ProofRefused`, "not one of the + chain's N pinned state-proof key shapes"). A pinned shape verifies only against the key loaded + from its file; the node never builds a pinned key. An empty list keeps chain 21's behaviour + (build on demand under `PERP_KEY_BUILD_GATE`). +- **Chain 22's four.** Tier 18 over the engine's program height 14, input 16, poseidon2 20, one + per public height (windows of 1..=11, 12..=27, 28..=59 and 60..=64 recorded blocks). These + are the shapes the engine's prover makes by default on a pinned chain. `--smallest` and + lower tiers are refused there. + + | file | sha256 | bytes | + |---|---|---| + | `perp-vk-production-t18-pg14-in16-pub7-p2h20.bin` | `4dc1f18bdd6d9104ba1622710cf2c146f71759676dbdcb70dad036152242e8b4` | 13 685 | + | `perp-vk-production-t18-pg14-in16-pub8-p2h20.bin` | `6392e5e9b7348f3729ba2031e0e3ec9788d6ed62a14521526482c92615f55106` | 13 685 | + | `perp-vk-production-t18-pg14-in16-pub9-p2h20.bin` | `c31636aa281004163e6fe0debd81854f11d7bca6c8062a91b1501c7e593e5bf0` | 13 685 | + | `perp-vk-production-t18-pg14-in16-pub10-p2h20.bin` | `ae3d0dc276061fd2a87b2e91b239f6dcccb746b49dedeecfdb2aab977c95c370` | 13 685 | + + They are committed in `crates/randprotocol-zkvm/keys/`, and their digests are compiled in + (`executor::perp_vk::CHAIN22_SHA256_PRODUCTION`). `rand-node keygen-perp-vk --print-pinned + production` prints ` ` per key, `--check FILE` prints a file's sha256, and + `--genesis-json DIR` prints the genesis list from the files in DIR. `--profile production + --out-dir DIR` rebuilds them on a big host: 20.6 s and 1.74 GB peak each with `parallel` and + `RAYON_NUM_THREADS=16`. The output is deterministic (`cargo test -p randprotocol-zkvm --test + perp_vk -- --ignored`). +- **The location.** Beside the binary: `/usr/local/bin/perp-vk-production-*.bin` on the fleet. + `--perps-key-dir DIR` or `RAND_PERPS_KEY_DIR` overrides it. A debug build, or + `RAND_PERPS_KEY_DEV_FALLBACK=1`, falls back to the source tree's `keys/`. At startup the node + reads every file the genesis pins, holds each to its genesis sha256 and to its shape, and + installs it. If a file is missing, mismatched or refused, the node does not start, and the + error names the path and the digest. `rand_status.perps_keys` reports `{"source": + "loaded"|"absent", "keys": N}`, and `rand_getPerps.state_proof_keys` serves the list. +- **The cut.** `deploy/cut-chain22-genesis.sh` holds the files in `PERPS_KEY_DIR` (default the + tree's `keys/`) to the cutting `rand-node`'s own pins, writes the field with `--genesis-json`, + asserts it in `py_splice`, probes it in the genesis hash (without it, and with one digest + changed), and reads it back in `check-limits` (`rand_getPerps.state_proof_keys` and + `rand_status.perps_keys` = loaded, 4). +- **The roll.** `deploy/roll-all.sh` takes `PERPS_VK_DIR`, the directory that holds the release's + four files. With `RELEASE_SUMS`, each file must be the one the signed `SHA256SUMS` lists. On + each host it holds every file the `rand-node.new` being installed pins to that pin, with + `sha256sum` and with `--check`, and installs them beside the binary before any restart. A + mismatch skips the host, binaries included. Without `PERPS_VK_DIR`, the roll is refused if + any host's genesis names `state_proof_keys` or cannot be read. The release workflow ships + the four files beside the binaries, in `SHA256SUMS` and in the build attestation, after it + asserts that the built `rand-node` pins each one. + ## Release trust Written 2026-09-30 (audit v6, PROC-4 and PROC-5). Until now every fleet binary was built by hand diff --git a/docs/perps.md b/docs/perps.md index ac651677..db078fb0 100644 --- a/docs/perps.md +++ b/docs/perps.md @@ -558,9 +558,9 @@ bridged one. warm shapes keep verifying. **The build is the memory cost**: its heap peaks at ~0.84 GB at tier 16 and ~3.3–4 GB at tier 18 (4× a tier step; measured with a counting allocator to tier 16, msauth's tier-18 build at 4.0 GB). **A validator with less than 8 GB of memory should run - a chain whose perps `max_tier` is at most 16**, or — a follow-up, not built yet — load a - precomputed, hash-pinned state-proof key (13.7 KB, as the msauth key is loaded) instead of - building it. + a chain whose perps `max_tier` is at most 16**, or run a chain that pins its state-proof + keys (`perps.state_proof_keys`, below; chain 22), where it loads each 13.7 KB key, hash-pinned + as the msauth key is, instead of building it. - **the node's tier cap (CON-601).** Chain 21's `max_tier` is 18 and it has no engine pin, so a proof that passes every pre-key rule — no proving needed — makes a node build a tier-18 key (94 s and 3.56 GB resident measured in a debug build), more than a 2 GB or 4 GB host holds. @@ -601,8 +601,21 @@ bridged one. passes at any tier. **The residual: a block.** Node policy cannot refuse a valid block (that would fork the node off the chain), so a block carrying a tier-18 state proof still makes every validator build its key, and a host under ~8 GB can be killed applying it. Chain 22's - genesis `engine_program_log_height` pin, with a `max_tier` the fleet can build (or the - validators given the memory), is the consensus fix; + genesis `engine_program_log_height` pin, with its pinned state-proof keys, is the consensus + fix (next item); + - **pinned state-proof keys (CON-601, chain 22).** A genesis may list + `perps.state_proof_keys`: up to 8 shapes, each with the SHA-256 of a precomputed key file + (`{tier, program_log_height, input_log_height, public_log_height, poseidon2_log_height, + sha256}`). The list is bound into the genesis hash only when set, and it requires + `engine_program_log_height`. On such a chain, a state proof whose declared shape is not + listed is refused before any key is touched, at validate and at apply. A listed shape + verifies only against the key the node loaded from its file at startup, held to the pinned + digest. The node never builds one, and it does not start without every file. So no block + and no pool entry can make a validator build a state-proof key. Chain 22 pins the four + canonical tier-18 shapes, with public heights 7, 8, 9 and 10 for windows up to 64 blocks + (`docs/deploy.md`, "The perps state-proof verifier keys"). The engine's prover makes those by + default and refuses `--smallest` on a pinned chain. A proof of any other shape (a lower + tier, `--smallest`, another input or poseidon2 height) is invalid on chain 22; - **the FRI transcript's structure, before the key (CON-601).** `perp_pre_key` (the pool's and the verify path's) also refuses a proof whose FRI transcript has commitments, commit-phase openings and commit-phase proof-of-work words of unequal counts, no commit round, a folding