Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 19 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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:
Expand All @@ -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:
Expand Down Expand Up @@ -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
17 changes: 17 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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):

Expand Down
29 changes: 29 additions & 0 deletions crates/randprotocol-client/src/perps.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<u64>,
/// 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<randprotocol_core::confidential::ProofShape>,
}

impl PerpsState {
Expand Down Expand Up @@ -170,6 +174,17 @@ impl PerpsState {
Some(a) => a.iter().map(|h| u64_of(h, "pending_heights")).collect::<Result<_>>()?,
None => Vec::new(),
},
state_proof_keys: match v["state_proof_keys"].as_array() {
Some(a) => a
.iter()
.map(|k| {
serde_json::from_value::<randprotocol_core::ledger::perps::StateProofKeyPin>(k.clone())
.map(|k| k.shape())
.map_err(|e| anyhow!("rand_getPerps.state_proof_keys: {e}"))
})
.collect::<Result<_>>()?,
None => Vec::new(),
},
})
}

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -1013,6 +1041,7 @@ mod tests {
max_window_heights: 16,
engine_program_log_height: 0,
pending_heights: pending,
state_proof_keys: Vec::new(),
}
}

Expand Down
1 change: 1 addition & 0 deletions crates/randprotocol-client/tests/wallet_flow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
21 changes: 20 additions & 1 deletion crates/randprotocol-core/src/confidential.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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<ProofShape, String> {
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.
Expand Down
33 changes: 33 additions & 0 deletions crates/randprotocol-core/src/genesis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down Expand Up @@ -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.
Expand Down
1 change: 1 addition & 0 deletions crates/randprotocol-core/src/ledger/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
Loading
Loading