aetherlight: pin the digest and genesis clauses, record a band draw in the golden, document host contracts

A stored digest flipped without re-sealing, and each genesis clause rewritten
and re-sealed on a lone genesis, are now refused by tests that only that clause
can satisfy. The golden session declares a two-band toss and uses it three
times, so band selection is pinned (golden.digests regenerated). The
BandPreimage doc no longer claims the payload cannot reach the draw; WorldId
byte-equality, and truncation or rollback of an export, are documented as host
contracts in the code and PROVENANCE.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
soul 2026-11-20 03:06:59 +01:00
commit 36d1d2507d
6 changed files with 147 additions and 10 deletions

View file

@ -113,10 +113,14 @@ pub enum ActionMismatch {
},
}
/// The band draw's whole preimage. Five fields, none of them from the
/// invocation's payload: the proposer varies the attempt and cannot vary the
/// draw. `affordance` is the id carried by the kernel-verified grant, so the
/// draw cannot be steered by an affordance the actor does not hold.
/// The band draw's whole preimage. Five fields. `command_id` is derived from
/// the world, the expected revision, the caller and the whole body, so the
/// payload does reach the draw through it: changing the speech or display text,
/// a magnitude or the revision re-rolls the band, and a proposer who can vary
/// those can grind for a band. That is not an authority hole: only Play submits
/// an act after genesis, and Play is trusted. `affordance` is the id carried by
/// the kernel-verified grant, so the draw cannot be steered by an affordance the
/// actor does not hold.
#[derive(Serialize)]
struct BandPreimage {
world_id: WorldId,

View file

@ -9,16 +9,21 @@ use crate::tests::{
affordance_named, auth_principal, command, creation, first_grant, operations, owner,
play_caller, play_command, speak, subject_by_label, submit_play, tick_body,
};
use crate::patch::{
AffordanceDeclaration, AffordanceKindName, AudienceSpec, Declaration, DraftHandle,
OutcomeBand, Precondition,
};
use crate::{
AuthenticatedCaller, CommandBody, CommitmentKind, ComponentOp, DecisionInvocation,
FictionalMinutes, KernelError, KnowledgeSource, Ref, Statement, TickMinutes, WorldEffect,
WorldKernel,
WorldKernel, WorldPatch,
};
use sha2::{Digest, Sha256};
use std::time::Instant;
/// The script: The Human speaks to The Witness, The Human shows a gesture, a
/// Routine is placed on The Witness, thirty minutes roll it, and The Human
/// two-band `toss` is declared, granted to The Human and used three times (so
/// the band draw is recorded), a Routine is placed on The Witness, thirty minutes roll it, and The Human
/// invokes `convene`, which it does not hold.
fn golden_session() -> (WorldKernel, String) {
let (mut kernel, _) = WorldKernel::create(creation("Golden"), &auth_principal(owner()))
@ -66,6 +71,54 @@ fn golden_session() -> (WorldKernel, String) {
},
);
// A two-band entry: the one place the golden records a band draw.
let snapshot = kernel.snapshot().unwrap();
submit_play(
&mut kernel,
&snapshot,
CommandBody::AdmitPatch {
patch: WorldPatch {
declarations: vec![Declaration::Affordance(AffordanceDeclaration {
handle: DraftHandle::new("toss"),
kind: AffordanceKindName("toss".into()),
roles: Vec::new(),
preconditions: vec![Precondition::CanBroadcast {
via: AudienceSpec::Colocated,
}],
effect_slots: Vec::new(),
outcome_bands: vec![
OutcomeBand { weight: 1, effects: Vec::new() },
OutcomeBand { weight: 1, effects: Vec::new() },
],
carries_speech: true,
})],
operations: vec![ComponentOp::GrantAffordance {
subject: Ref::Existing(human),
affordance: Ref::Draft(DraftHandle::new("toss")),
}],
evidence: Vec::new(),
},
},
);
for _ in 0..3 {
let snapshot = kernel.snapshot().unwrap();
let toss = affordance_named(&snapshot, "toss");
submit_play(
&mut kernel,
&snapshot,
CommandBody::Act {
actor: human,
invocation: DecisionInvocation {
affordance: toss,
bindings: Vec::new(),
proposed: Vec::new(),
speech: Some(Statement::new("Heads or tails.").unwrap()),
display: None,
},
},
);
}
let snapshot = kernel.snapshot().unwrap();
submit_play(
&mut kernel,
@ -107,7 +160,7 @@ fn golden_session() -> (WorldKernel, String) {
);
assert!(matches!(refused, Err(KernelError::AffordanceDenied)), "{refused:?}");
assert_eq!(kernel.snapshot().unwrap(), before);
assert_eq!(kernel.journal.commit_count(), 5);
assert_eq!(kernel.journal.commit_count(), 9);
let mut file = String::new();
for commit in kernel.journal.commits_for_test() {

View file

@ -55,6 +55,11 @@ impl WorldJournal {
/// Decode canonically, then replay: the head state is whatever the chain
/// derives, and a chain that does not verify is not a world.
///
/// A chain verifies as a prefix, so an export with its tail dropped, or an
/// older export, opens as a valid shorter world. The holder of the bytes
/// owns the head: it keeps the revision and state digest from `snapshot()`
/// at export time and compares them after `open` (AL5's C# store).
pub(super) fn open(bytes: &[u8]) -> Result<(Self, WorldState), JournalError> {
let export: Export = decode(bytes)?;
if export.schema != JOURNAL_SCHEMA {
@ -958,6 +963,61 @@ mod tests {
));
}
/// A stored digest is checked against the commit it seals, on its own:
/// flipping one character of any commit's digest, with nothing re-sealed,
/// leaves only the digest clause to refuse it (the last commit and a lone
/// genesis have no successor whose previous-digest could).
#[test]
fn a_stored_digest_flipped_without_resealing_is_refused() {
let kernel = clock_history();
let honest = kernel.journal.commits.clone();
let flip = |digest: &str| {
let mut flipped = digest.to_owned();
let last = flipped.pop().unwrap();
flipped.push(if last == '0' { '1' } else { '0' });
flipped
};
for upto in 1..=honest.len() {
let mut chain = honest[..upto].to_vec();
let tail = chain.last_mut().unwrap();
tail.digest = flip(&tail.digest);
assert!(
matches!(reopen(&chain), Err(JournalError::Corrupt(_))),
"a flipped digest on commit {} of {upto} was admitted",
upto - 1
);
}
}
/// Each clause of the genesis condition refuses alone: a lone genesis,
/// re-sealed after one field is rewritten, so nothing else can object.
#[test]
fn each_genesis_clause_refuses_on_its_own() {
let kernel = clock_history();
let genesis = kernel.journal.commits[0].clone();
let forgeries: [(&str, &dyn Fn(&mut WorldCommit)); 5] = [
("schema", &|commit| commit.schema = "ghostlight.world_commit.consumer.v10".into()),
("a previous revision", &|commit| commit.previous_revision = Some(0)),
("a nonzero revision", &|commit| commit.resulting_revision = 1),
("a previous state digest", &|commit| {
commit.previous_state_digest = Some("sha256:00".into())
}),
("a previous commit digest", &|commit| {
commit.previous_commit_digest = Some("sha256:00".into())
}),
];
reopen(std::slice::from_ref(&genesis)).expect("a lone honest genesis opens");
for (what, forge) in forgeries {
let mut forged = genesis.clone();
forge(&mut forged);
forged.digest = commit_digest(&forged).unwrap();
assert!(
matches!(reopen(&[forged]), Err(JournalError::Corrupt(_))),
"a genesis with {what} was admitted"
);
}
}
/// Position `i` holds resulting revision `i`: a commit that names a later
/// revision than its place, with a state digest honestly computed for that
/// revision, is still not the chain's next commit.

View file

@ -245,6 +245,9 @@ struct CreateWorld {
impl CreateWorld {
/// The creation is named by its own bytes: equal creations are one command.
/// Host contract: two byte-equal creations share a `WorldId` and every id
/// derived under it, so a host that wants distinct worlds salts each run or
/// profile into the creation (for example a run seed in the patch).
fn id(&self) -> CommandId {
let mut hasher = Sha256::new();
hasher.update(CREATE_DOMAIN);