From e16bae92dcdae2d865115bed47b1d4e529633917 Mon Sep 17 00:00:00 2001 From: Brian Luby Date: Fri, 13 Nov 2026 23:17:42 -0800 Subject: [PATCH 1/2] feat(review): clause-level 061 adapter with per-clause subject profile Each captured human clause becomes one reviewable subject bound to its exact original raw identity, borrowing from the genuine sealed CurrentAuthoringPlanClosure. - hash_v3 profile8 clause_subject: domain-separated per-clause fingerprint over the clause key, exact original digest and extent (independent byte oracle). - adapters::authoring_clause: prepare() re-verifies each selected clause's exact original against its sealed member; a tampered clause original refuses. bind_queue() binds every clause subject to its own sealed ordinal source pin. - CurrentAuthoringPlanClosure::clause_members() borrows each sealed clause's native key and complete original digest. - Consumed in authoring_binding::prepare (retained) and authoring_finalize (bind_queue), mirroring the /1 mapping/applicability adapter pattern. The /3 whole-plan queue shape and all existing zero-edit/quorum/dissent/M-10 contracts are unchanged. 4 new clause tests; 598 review tests green. --- src/review/adapters/authoring_clause.rs | 215 ++++++++++++++++++ src/review/adapters/authoring_clause_tests.rs | 86 +++++++ src/review/adapters/mod.rs | 3 + src/review/authoring_binding.rs | 27 ++- src/review/authoring_capture.rs | 12 + src/review/authoring_capture_tests.rs | 5 + src/review/authoring_finalize.rs | 2 + src/review/hash_v3.rs | 25 ++ src/review/hash_v3_tests.rs | 41 ++++ 9 files changed, 415 insertions(+), 1 deletion(-) create mode 100644 src/review/adapters/authoring_clause.rs create mode 100644 src/review/adapters/authoring_clause_tests.rs diff --git a/src/review/adapters/authoring_clause.rs b/src/review/adapters/authoring_clause.rs new file mode 100644 index 00000000..fb79257a --- /dev/null +++ b/src/review/adapters/authoring_clause.rs @@ -0,0 +1,215 @@ +//! Minimized per-clause Authoring re-review facts from the genuine sealed plan closure. +//! +//! Each captured human clause becomes one reviewable subject bound to its exact +//! original raw identity. The sole authority-bearing input is the receiver-issued +//! `CurrentAuthoringPlanClosure`; hashes, selected keys and asserted policy quorum +//! create no native approval, currentness or publication capability. + +use std::collections::BTreeMap; + +use crate::hashing::sha256_hex; +use crate::review::authoring_capture::CurrentAuthoringPlanClosure; +use crate::review::decode::{ContractError, ContractLedger}; +use crate::review::hash_v3; +use crate::workspace::preparation::WorkControl; + +/// Complete captured human-clause count ceiling, not a partial prefix. +const MAX_CLAUSES: usize = 10_000; +/// Exact existing path-free review subject token ceiling in UTF-8 bytes. +const MAX_SUBJECT_ID: usize = 256; + +/// One selected actual clause subject, constructible only by this captured adapter. +pub(crate) struct ClauseFact<'a> { + /// Exact native clause key, never inferred from a locator or path. + subject_id: &'a str, + /// Full domain-separated per-clause subject fingerprint; prose is hashed, not exported. + subject_sha256: String, + /// Exact complete original raw identity borrowed from the sealed member. + raw_sha256: &'a str, + /// Full original extent. + byte_length: u64, +} + +impl ClauseFact<'_> { + /// Borrow the actual selected native clause key. + pub(crate) fn subject_id(&self) -> &str { + self.subject_id + } + /// Borrow the complete domain-separated per-clause subject binding. + pub(crate) fn subject_sha256(&self) -> &str { + &self.subject_sha256 + } + /// Borrow the exact original raw digest this subject is bound to. + pub(crate) fn raw_sha256(&self) -> &str { + self.raw_sha256 + } + /// Borrow the full original byte extent. + pub(crate) fn byte_length(&self) -> u64 { + self.byte_length + } +} + +/// Per-clause facts borrowing one genuine complete current authoring-plan capture owner. +pub(crate) struct PreparedAuthoringClauseReview<'a> { + /// Sole authority-bearing input is the opaque receiver-issued captured closure. + closure: &'a CurrentAuthoringPlanClosure, + /// All selected facts, in exact selected native clause-key order. + facts: Vec>, + /// Complete captured clause denominator before selection. + complete_clauses: usize, +} + +impl<'a> PreparedAuthoringClauseReview<'a> { + /// Borrow the genuine complete native owner, never a detached proof. + pub(crate) fn closure(&self) -> &'a CurrentAuthoringPlanClosure { + self.closure + } + /// Borrow the complete captured clause denominator. + pub(crate) fn complete_clauses(&self) -> usize { + self.complete_clauses + } + /// Borrow the selected per-clause facts in exact native key order. + pub(crate) fn facts(&self) -> &[ClauseFact<'a>] { + &self.facts + } + /// Consume the selected clause facts' complete queue binding under the same ledger. + /// Each clause subject is bound to its own sealed ordinal source pin by exact original + /// raw identity; a missing or altered clause pin refuses, never re-binds. The genuine + /// closure owner is re-verified so no detached fact vector can issue this binding. + pub(crate) fn bind_queue( + &self, + queue: &crate::review::wire_v3::QueueDocumentV3, + ledger: &mut ContractLedger, + control: &mut dyn WorkControl, + ) -> Result<(), ContractError> { + use crate::review::wire_v3::SourceKindV3; + ledger.checkpoint(control)?; + self.closure().verify_inputs(ledger, control)?; + let pins: Vec<_> = + queue.source_pins.iter().filter(|pin| pin.kind == SourceKindV3::HumanClause).collect(); + ledger.visits(pins.len())?; + if pins.len() != self.complete_clauses() || pins.len() != self.facts().len() { + return Err(ContractError::Binding); + } + // Clause pins carry gap-free declaration ordinals from the native project's + // human_clauses order; bind each subject to its own exact original pin. + let declared: Vec<&str> = self + .closure() + .facts() + .loaded + .project + .human_clauses + .iter() + .map(|clause| clause.key.as_str()) + .collect(); + ledger.derived( + declared + .len() + .checked_mul(std::mem::size_of::<&str>()) + .ok_or(ContractError::Capacity)?, + )?; + for fact in self.facts() { + ledger.visits(1)?; + let ordinal = declared + .iter() + .position(|key| *key == fact.subject_id()) + .ok_or(ContractError::Binding)?; + let expected = format!("authoring:clause:{ordinal}"); + ledger.derived(expected.len())?; + let pin = pins + .iter() + .find(|pin| pin.artifact_key == expected) + .ok_or(ContractError::Binding)?; + if pin.raw_sha256 != fact.raw_sha256() || pin.byte_length != fact.byte_length() { + return Err(ContractError::Binding); + } + crate::review::chain::compare(&pin.raw_sha256, fact.subject_sha256(), ledger)?; + } + Ok(()) + } +} + +/// Admit explicit selection and derive per-clause facts only from the sealed closure. +/// +/// The sealed input has consumed the complete maintained native comparison and every +/// human-clause original. This adapter re-verifies each selected clause's exact original +/// digest against its sealed member before issuing the subject binding; a tampered +/// original is refused, never silently re-bound. No file is opened and no approval is +/// promoted here. +pub(crate) fn prepare<'a>( + closure: &'a CurrentAuthoringPlanClosure, + selected: &[&'a str], + ledger: &mut ContractLedger, + control: &mut dyn WorkControl, +) -> Result, ContractError> { + ledger.bound(|ledger| { + ledger.checkpoint(control)?; + let result = prepare_inner(closure, selected, ledger, control); + ledger.checkpoint(control)?; + result + }) +} + +/// Preserve one outer post-phase fence after all ordinary binding outcomes. +fn prepare_inner<'a>( + closure: &'a CurrentAuthoringPlanClosure, + selected: &[&'a str], + ledger: &mut ContractLedger, + control: &mut dyn WorkControl, +) -> Result, ContractError> { + if selected.is_empty() || selected.len() > MAX_CLAUSES { + return Err(ContractError::Invalid); + } + ledger.visits(selected.len())?; + ledger.bytes(selected.len().checked_mul(MAX_SUBJECT_ID).ok_or(ContractError::Capacity)?)?; + for key in selected { + crate::review::validate::token(key, MAX_SUBJECT_ID)?; + } + if selected.windows(2).any(|pair| pair[0] >= pair[1]) { + return Err(ContractError::Invalid); + } + + // Recheck all actual physical inputs under the same original invocation work owner. + closure.verify_inputs(ledger, control)?; + + let clauses = &closure.facts().loaded.clauses; + if clauses.len() > MAX_CLAUSES { + return Err(ContractError::Capacity); + } + let complete_clauses = clauses.len(); + + // Correlate every sealed clause member to its exact native key. Key-based matching + // is unambiguous even when two clauses share identical original bytes. + let mut sealed: BTreeMap<&str, &str> = BTreeMap::new(); + for (key, raw_sha256) in closure.clause_members() { + ledger.visits(1)?; + ledger.derived(std::mem::size_of::<(&str, &str)>() + key.len() + raw_sha256.len())?; + if sealed.insert(key, raw_sha256).is_some() { + return Err(ContractError::Binding); + } + } + + let mut facts = Vec::new(); + ledger.derived( + selected + .len() + .checked_mul(std::mem::size_of::>()) + .ok_or(ContractError::Capacity)?, + )?; + for key in selected { + ledger.visits(1)?; + let clause = clauses.get(*key).ok_or(ContractError::Binding)?; + let raw_sha256 = sealed.get(key).copied().ok_or(ContractError::Binding)?; + // Re-derive the bound original digest from the actual parsed clause allocation; + // a tampered clause original refuses rather than issuing a stale binding. + if sha256_hex(&clause.bytes) != raw_sha256 { + return Err(ContractError::Binding); + } + let byte_length = u64::try_from(clause.bytes.len()).map_err(|_| ContractError::Capacity)?; + let subject_sha256 = + hash_v3::clause_subject(key, raw_sha256, byte_length, ledger, control)?; + facts.push(ClauseFact { subject_id: key, subject_sha256, raw_sha256, byte_length }); + } + + Ok(PreparedAuthoringClauseReview { closure, facts, complete_clauses }) +} diff --git a/src/review/adapters/authoring_clause_tests.rs b/src/review/adapters/authoring_clause_tests.rs new file mode 100644 index 00000000..f22fe756 --- /dev/null +++ b/src/review/adapters/authoring_clause_tests.rs @@ -0,0 +1,86 @@ +// Genuine per-clause 061 adapter controls: each sealed human clause is one reviewable +// subject bound to its exact original; a tampered clause original is refused. +use super::*; +use crate::review::adapters::authoring_clause as adapter; +use crate::review::hash_v3; + +/// Each captured clause binds its own exact original digest and a distinct per-clause subject. +#[test] +fn per_clause_subject_binds_each_sealed_original() { + let mut f = Fixture::new(false, false); + f.answer(); + originals(&f); + let mut ledger = ContractLedger::default(); + let mut caller = NoopControl; + let mut control = ReviewControl::accept(&mut caller); + let owner = init(&f, &mut ledger, &mut control).unwrap(); + + let prepared = + adapter::prepare(&owner, &["access-clause", "operations-clause"], &mut ledger, &mut control) + .unwrap(); + assert_eq!(prepared.complete_clauses(), 2); + let facts = prepared.facts(); + assert_eq!(facts.len(), 2); + assert_eq!(facts[0].subject_id(), "access-clause"); + assert_eq!(facts[1].subject_id(), "operations-clause"); + // Each subject is bound to its own sealed original raw identity, not the whole-plan digest. + assert_eq!(facts[0].raw_sha256(), sha256_hex(&f.clauses[0])); + assert_eq!(facts[1].raw_sha256(), sha256_hex(&f.clauses[1])); + assert_eq!(facts[0].byte_length(), f.clauses[0].len() as u64); + assert_ne!(facts[0].subject_sha256(), facts[1].subject_sha256()); + // The per-clause subject profile reproduces the bound fingerprint independently. + assert_eq!( + facts[0].subject_sha256(), + hash_v3::clause_subject( + "access-clause", + facts[0].raw_sha256(), + facts[0].byte_length(), + &mut ledger, + &mut control + ) + .unwrap() + ); + // The genuine owner stays borrowed; no detached proof is issued. + assert_eq!(prepared.closure().source_pins().len(), owner.source_pins().len()); +} + +/// A tampered clause original refuses the whole preparation, never issuing a stale binding. +#[test] +fn tampered_clause_original_is_refused() { + let mut f = Fixture::new(false, false); + f.answer(); + originals(&f); + let mut ledger = ContractLedger::default(); + let mut caller = NoopControl; + let mut control = ReviewControl::accept(&mut caller); + let owner = init(&f, &mut ledger, &mut control).unwrap(); + std::fs::write(f.root.join("clause.md"), b"tampered complete human clause original").unwrap(); + binding(adapter::prepare( + &owner, + &["access-clause", "operations-clause"], + &mut ledger, + &mut control, + )); +} + +/// Selection must be a nonempty strictly-increasing list of captured clause keys. +#[test] +fn selection_order_and_membership_are_enforced() { + let f = Fixture::new(false, false); + originals(&f); + let mut ledger = ContractLedger::default(); + let mut caller = NoopControl; + let mut control = ReviewControl::accept(&mut caller); + let owner = init(&f, &mut ledger, &mut control).unwrap(); + // Empty selection and unsorted selection are structural refusals. + assert!(matches!( + adapter::prepare(&owner, &[], &mut ledger, &mut control), + Err(ContractError::Invalid) + )); + assert!(matches!( + adapter::prepare(&owner, &["operations-clause", "access-clause"], &mut ledger, &mut control), + Err(ContractError::Invalid) + )); + // Unknown clause key. + binding(adapter::prepare(&owner, &["missing-clause"], &mut ledger, &mut control)); +} diff --git a/src/review/adapters/mod.rs b/src/review/adapters/mod.rs index f9480b09..27830616 100644 --- a/src/review/adapters/mod.rs +++ b/src/review/adapters/mod.rs @@ -5,3 +5,6 @@ pub(crate) mod mapping; /// Re-review explicit applicability decisions only through their genuine report-source closure. pub(crate) mod applicability; + +/// Re-review individual authoring clauses only through their genuine sealed plan closure. +pub(crate) mod authoring_clause; diff --git a/src/review/authoring_binding.rs b/src/review/authoring_binding.rs index 3153e140..dac3f14b 100644 --- a/src/review/authoring_binding.rs +++ b/src/review/authoring_binding.rs @@ -1,5 +1,6 @@ //! A-authored genuine Authoring Queue/3 binding over one complete native owner. //! Every actual Queue/Response allocation stays borrowed; loaded labels confer no proof. +use super::adapters::authoring_clause; use super::authoring_capture::CurrentAuthoringPlanClosure; use super::authoring_response_binding::compared_pins; use super::capture::authoring::RegisteredAuthoringOriginals; @@ -23,6 +24,8 @@ pub(crate) struct PendingAuthoringBinding<'native> { queue: DecodedV3<'native, QueueDocumentV3>, /// Every actual Response holder in original order, including duplicate occurrences. responses: Vec>, + /// Per-clause reviewable subjects bound to their exact sealed originals. + clauses: authoring_clause::PreparedAuthoringClauseReview<'native>, } impl<'native> PendingAuthoringBinding<'native> { /// Borrow the genuine native owner without detaching physical lifetime. @@ -41,6 +44,10 @@ impl<'native> PendingAuthoringBinding<'native> { pub(crate) fn responses(&self) -> &[DecodedV3<'native, ResponseDocumentV3>] { &self.responses } + /// Borrow the per-clause reviewable subjects bound to their exact sealed originals. + pub(crate) fn clauses(&self) -> &authoring_clause::PreparedAuthoringClauseReview<'native> { + &self.clauses + } /// Repeat exact original registrations and complete physical U with ordinary postfences. pub(crate) fn verify_inputs( &self, @@ -157,6 +164,10 @@ pub(crate) fn prepare<'native>( let raw = originals.queue_raw().ok_or(ContractError::Binding)?; let queue = decode_v3::decode_queue(raw, ledger, control)?; native_queue(closure, &queue, ledger, control)?; + // Re-verify every captured human clause as its own reviewable subject bound to its + // exact original; a tampered clause original refuses before any response is admitted. + let clauses = clause_subjects(closure, ledger)?; + let clause_review = authoring_clause::prepare(closure, &clauses, ledger, control)?; let actual = originals.responses(); let mut responses = reserved(actual.len(), ledger)?; for raw in actual { @@ -168,6 +179,20 @@ pub(crate) fn prepare<'native>( originals.verify_review_originals(ledger, control)?; closure.verify_inputs(ledger, control)?; ledger.derived(std::mem::size_of::>())?; - Ok(PendingAuthoringBinding { closure, originals, queue, responses }) + Ok(PendingAuthoringBinding { closure, originals, queue, responses, clauses: clause_review }) }) } + +/// Borrow every captured human-clause key in exact native order for per-clause re-review. +fn clause_subjects<'native>( + closure: &'native CurrentAuthoringPlanClosure, + ledger: &mut ContractLedger, +) -> Result, ContractError> { + let keys = &closure.facts().loaded.clauses; + let mut selected = reserved(keys.len(), ledger)?; + for key in keys.keys() { + ledger.bytes(std::mem::size_of::<&str>())?; + selected.push(key.as_str()); + } + Ok(selected) +} diff --git a/src/review/authoring_capture.rs b/src/review/authoring_capture.rs index a1d09d34..879f524c 100644 --- a/src/review/authoring_capture.rs +++ b/src/review/authoring_capture.rs @@ -145,6 +145,18 @@ impl CurrentAuthoringPlanClosure { pub(crate) fn locator_raw(&self) -> &[u8] { self.locator_lease.bytes() } + /// Borrow each sealed human-clause member's exact native key and complete original + /// raw digest, in maintained member order. The key is derived from the actual + /// `human-clause-` role; this projection issues no currentness or approval proof. + pub(crate) fn clause_members(&self) -> impl Iterator { + self.members.iter().filter_map(|member| { + member + .native_role + .as_deref()? + .strip_prefix("human-clause-") + .map(|key| (key, member.raw_sha256.as_str())) + }) + } /// Borrow only internally issued complete operation registrations, preserving duplicates. pub(crate) fn originals(&self) -> Result, ContractError> { self.held.authoring_originals() diff --git a/src/review/authoring_capture_tests.rs b/src/review/authoring_capture_tests.rs index c3681f8d..445c436b 100644 --- a/src/review/authoring_capture_tests.rs +++ b/src/review/authoring_capture_tests.rs @@ -592,3 +592,8 @@ mod command_tests { mod edit_merge_tests { include!("edit_merge_tests.rs"); } + +/// Genuine per-clause 061 adapter controls over the sealed plan closure. +mod clause_adapter_tests { + include!("adapters/authoring_clause_tests.rs"); +} diff --git a/src/review/authoring_finalize.rs b/src/review/authoring_finalize.rs index 1fdf94e3..219d4646 100644 --- a/src/review/authoring_finalize.rs +++ b/src/review/authoring_finalize.rs @@ -57,6 +57,8 @@ pub(crate) fn finalize<'a, 'native>( phase(ledger, control, |ledger, control| { bind_originals(binding, pending, ledger, control) })?; + // Bind every per-clause subject to its exact sealed queue source pin before issuance. + binding.clauses().bind_queue(binding.queue().document(), ledger, control)?; let generation = generation(binding, pending, ledger, control)?; let document = document(pending, binding.closure().source_pins(), generation, ledger, control)?; diff --git a/src/review/hash_v3.rs b/src/review/hash_v3.rs index f40ca43d..82be27c3 100644 --- a/src/review/hash_v3.rs +++ b/src/review/hash_v3.rs @@ -840,6 +840,31 @@ pub(crate) fn subject( stream.finish_hex() }) } +/// Profile8: per-clause subject binding over one sealed human-clause original. +/// Each clause is a separate reviewable subject bound to its exact original raw +/// identity; reproducing this digest grants no native approval or currentness. +pub(crate) fn clause_subject( + clause_key: &str, + raw_sha256: &str, + byte_length: u64, + ledger: &mut ContractLedger, + control: &mut dyn WorkControl, +) -> Result { + phase(ledger, control, |ledger, control| { + key(clause_key, ledger)?; + hash_operand(raw_sha256, ledger)?; + if byte_length == 0 || byte_length > 1_048_576 { + return Err(ContractError::Invalid); + } + let mut stream = + Stream::new(b"forge.authoring-clause-review-subject/1\0", SMALL_CAP, ledger, control)?; + stream.string("forge.authoring-clause-review/1")?; + stream.string(clause_key)?; + stream.hash(raw_sha256)?; + stream.u64(byte_length)?; + stream.finish_hex() + }) +} /// Profile4: exact minimized complete context/pins; native prose never enters this stream. pub(crate) fn context( pins: &[SourcePinV3], diff --git a/src/review/hash_v3_tests.rs b/src/review/hash_v3_tests.rs index 22654cdd..b2b2dbbc 100644 --- a/src/review/hash_v3_tests.rs +++ b/src/review/hash_v3_tests.rs @@ -917,3 +917,44 @@ fn strict_hash_operand_refusal_never_coerces_spelling() { )); } } + +/// Profile8 per-clause subject has an independent byte oracle; key/digest/extent all bind. +#[test] +fn clause_subject_profile_matches_independent_oracle() { + let mut ledger = ContractLedger::default(); + let actual = + clause_subject("operations-clause", H1, 128, &mut ledger, &mut NoopControl).unwrap(); + let mut expected = b"forge.authoring-clause-review-subject/1\0".to_vec(); + s(&mut expected, "forge.authoring-clause-review/1"); + s(&mut expected, "operations-clause"); + h(&mut expected, 0x11); + u(&mut expected, 128); + assert_eq!(actual, digest(&expected)); + // A different clause key, digest or extent yields a distinct subject fingerprint. + let other_key = + clause_subject("access-clause", H1, 128, &mut ledger, &mut NoopControl).unwrap(); + let other_hash = + clause_subject("operations-clause", H2, 128, &mut ledger, &mut NoopControl).unwrap(); + let other_len = + clause_subject("operations-clause", H1, 129, &mut ledger, &mut NoopControl).unwrap(); + assert_ne!(actual, other_key); + assert_ne!(actual, other_hash); + assert_ne!(actual, other_len); + // Zero and over-cap extents are refused; malformed digest/key never coerce. + for bad_len in [0, 1_048_577] { + assert!(matches!( + clause_subject("operations-clause", H1, bad_len, &mut ledger, &mut NoopControl), + Err(ContractError::Invalid) + )); + } + assert!(matches!( + clause_subject( + "operations-clause", + "A".repeat(64).as_str(), + 128, + &mut ledger, + &mut NoopControl + ), + Err(ContractError::Invalid) + )); +} From 59234a313a03b1ca304dacd0d94bbeb03d618510 Mon Sep 17 00:00:00 2001 From: Brian Luby Date: Sat, 14 Nov 2026 14:45:40 -0800 Subject: [PATCH 2/2] fix(review): clause binding uses key->ordinal map and explicit digest charge CodeRabbit findings on PR #289 (clause-061 adapter): - bind_queue precomputes a BTreeMap of clause key -> declaration ordinal once, replacing the per-fact O(n) position() scan (O(n^2) at 10k clauses) with O(log n) lookups; first-wins ordinal, unknown-key refusal and derived storage charge preserved. - Replace the misleading chain::compare() call with an explicit ledger.bytes() charge of both complete digest extents (same accounting, no discarded lexical comparison). - Correct clause_subjects comment: keys iterate in lexicographic BTreeMap key order, not native declaration order. --- src/review/adapters/authoring_clause.rs | 30 ++++++++++++------------- src/review/authoring_binding.rs | 2 +- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/src/review/adapters/authoring_clause.rs b/src/review/adapters/authoring_clause.rs index fb79257a..773a6c64 100644 --- a/src/review/adapters/authoring_clause.rs +++ b/src/review/adapters/authoring_clause.rs @@ -93,27 +93,21 @@ impl<'a> PreparedAuthoringClauseReview<'a> { } // Clause pins carry gap-free declaration ordinals from the native project's // human_clauses order; bind each subject to its own exact original pin. - let declared: Vec<&str> = self - .closure() - .facts() - .loaded - .project - .human_clauses - .iter() - .map(|clause| clause.key.as_str()) - .collect(); + let mut declared: BTreeMap<&str, usize> = BTreeMap::new(); + for (ordinal, clause) in + self.closure().facts().loaded.project.human_clauses.iter().enumerate() + { + declared.entry(clause.key.as_str()).or_insert(ordinal); + } ledger.derived( declared .len() - .checked_mul(std::mem::size_of::<&str>()) + .checked_mul(std::mem::size_of::<(&str, usize)>()) .ok_or(ContractError::Capacity)?, )?; for fact in self.facts() { ledger.visits(1)?; - let ordinal = declared - .iter() - .position(|key| *key == fact.subject_id()) - .ok_or(ContractError::Binding)?; + let ordinal = declared.get(fact.subject_id()).ok_or(ContractError::Binding)?; let expected = format!("authoring:clause:{ordinal}"); ledger.derived(expected.len())?; let pin = pins @@ -123,7 +117,13 @@ impl<'a> PreparedAuthoringClauseReview<'a> { if pin.raw_sha256 != fact.raw_sha256() || pin.byte_length != fact.byte_length() { return Err(ContractError::Binding); } - crate::review::chain::compare(&pin.raw_sha256, fact.subject_sha256(), ledger)?; + // Charge inspection of both complete digest extents for this binding. + ledger.bytes( + pin.raw_sha256 + .len() + .checked_add(fact.subject_sha256().len()) + .ok_or(ContractError::Capacity)?, + )?; } Ok(()) } diff --git a/src/review/authoring_binding.rs b/src/review/authoring_binding.rs index dac3f14b..ebb48c4d 100644 --- a/src/review/authoring_binding.rs +++ b/src/review/authoring_binding.rs @@ -183,7 +183,7 @@ pub(crate) fn prepare<'native>( }) } -/// Borrow every captured human-clause key in exact native order for per-clause re-review. +/// Borrow every captured human-clause key in lexicographic `BTreeMap` key order for per-clause re-review. fn clause_subjects<'native>( closure: &'native CurrentAuthoringPlanClosure, ledger: &mut ContractLedger,