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:
parent
7b7d12ea83
commit
36d1d2507d
6 changed files with 147 additions and 10 deletions
|
|
@ -351,3 +351,16 @@ Not taken from the spec's text: the spec's negative pattern `id: CommandId`
|
|||
matches the `command_id: CommandId` parameters of the band draw and derivation
|
||||
(the per-command term the spec keeps); the doc comment said `synchronous`, which
|
||||
`chrono` matches, and now says `single-threaded`.
|
||||
|
||||
Host contracts (AL3a, from Soul's pass):
|
||||
|
||||
- Two byte-equal creations share a `WorldId` and every id under it. A host that
|
||||
wants distinct worlds salts each run or profile into the creation, for example
|
||||
a run seed in the patch.
|
||||
- Truncation and rollback open: 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 keeps the head (revision and state digest from `snapshot()`
|
||||
at export time) and compares after `open`. AL5's C# store owns this.
|
||||
- The band draw is grindable through the command id (it hashes the body, so the
|
||||
text, a magnitude or the revision re-roll it). Only Play submits acts after
|
||||
genesis and Play is trusted, so it is not an authority hole.
|
||||
|
|
|
|||
|
|
@ -1,6 +1,10 @@
|
|||
0 sha256:b3a1da45714cfed622b118ac441f562dcf2c1f45637baff335f08a3efa562e55 sha256:e0e30c081917a00f88268916784d55e0e3ee187b8733a6da5953f9864dbc41cd
|
||||
1 sha256:6315946e2cac6d49e24aae623bb92cdf9c68ac50382c1d27ffec34f78e2ebbb5 sha256:14fa8cbdee9f94944dbc91c9158fb6009c5310e11f57d682a3c17ae3ba4a476e
|
||||
2 sha256:3bc0ba23bdb8afe6782b08f3223e9a501e17a8cfbbfed3b8c0a94cab20d2de64 sha256:e962a73db29fb48e0b303ac2746f85c88e9eca43e70cb3b5efb5527a885516a7
|
||||
3 sha256:cd5930ff97930832f59fb4ad954b0fd9ca94167767a15033011de8ca2b51581d sha256:3c6277ff11415a18376e8c86f1aa742ed8529b216a13492b66e0843dffffdcb4
|
||||
4 sha256:735182443e82f4b21d7b88c82aaca27987266653e6d839ab16556ac10b27d7e4 sha256:b138a16729c1f232c11f0b1a2bc692025856d2803820b05084cefd581af1b001
|
||||
export sha256:bc412d52ed96520d74bc06faead7c7b735573d268a51e2b4ea7d3f31ff4e8ac4
|
||||
3 sha256:1e6fa2e6104ad2cdde11db5f4643a0881f88cdda2cf049e445774ea9a2f36b65 sha256:1e8047a55a7857a19c05e07c9978a8656423de4c1c7fc49151a71abf399e2e2c
|
||||
4 sha256:777d7f85b0c342ba44f51aacc03a615038cc243aa8930adf9c5e5ef7200a4325 sha256:f5ce5f59d767866fb02c76948f6693cda954d712efb6b2ac624b6dfe816cdd4f
|
||||
5 sha256:f08db5b927a98b741cec0aec4d566f376ea283e1057e8a6f5abbff3f5983acb1 sha256:07889d5e1c2958e51b37087acf9784d2274c47a8cf854aadf3ed809a02b5af6e
|
||||
6 sha256:0edc5712426bb23a2773fe7c804c0cccddff5f23d733679c2cd3857f2009dc6b sha256:8cebfbdbf217aad91e76301188095a04fc0cef488e6367eb3fc8a7b3f93e7f77
|
||||
7 sha256:3fdf073544f807ef4ca9928e7c95aaec58982ecb37fdcc758f3bf916914dd215 sha256:c04c37fcc192f208869f396bc2287db76e08527e5d179ffae0ec07a513964cee
|
||||
8 sha256:18c5a5b61bfb8d039f9e38b5ac3a8353024de84c572d019a8af94a9508462e04 sha256:85449a2d63f3383dff2a0813071a76f665d208a77aa954d65b308c2b57657301
|
||||
export sha256:4ba94ec8ee6036e74b2fb28b9cbef97cb5386fea4c3063cf38a08ff47de28910
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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() {
|
||||
|
|
|
|||
|
|
@ -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.
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
Loading…
Reference in a new issue