소스 검색

Treat payer as provenance, not part of a transfer's identity

payer was in a both-and-neither state: folded into the content-address
preimage (so two economically identical envelopes differing only in a
payer annotation got different EnvelopeIds, and thus different
idempotency keys) yet dropped from the stored posting. It affected
identity but read as informational.

Decide it is provenance and make one seam honour that: exclude payer
from NewPosting's canonical bytes so an EnvelopeId reflects only
economic content (owner, asset, value). Provenance is still persisted
on the envelope record, where the dashboard reads it for audit; the
posting projection stays purely economic.

This changes EnvelopeId derivation for any envelope carrying a payer, so
addresses computed under the old rule are not reproduced by re-hashing.
Nothing re-derives a stored id to verify it, and no vector pins a
payer-inclusive hash, so the change is self-consistent going forward.
Cesar Rodas 3 달 전
부모
커밋
ff4ab976ee
3개의 변경된 파일과 20개의 추가작업 그리고 8개의 파일을 삭제
  1. 10 0
      crates/kuatia-core/src/hash.rs
  2. 5 7
      crates/kuatia-types/src/canonical.rs
  3. 5 1
      crates/kuatia-types/src/posting.rs

+ 10 - 0
crates/kuatia-core/src/hash.rs

@@ -96,6 +96,16 @@ mod tests {
     }
 
     #[test]
+    fn payer_does_not_affect_envelope_id() {
+        // payer is provenance, not identity: two envelopes differing only in
+        // payer must share an EnvelopeId, and thus one idempotency key.
+        let a = sample_envelope();
+        let mut b = sample_envelope();
+        b.creates[0].payer = Some(AccountId::new(9));
+        assert_eq!(envelope_id(&a), envelope_id(&b));
+    }
+
+    #[test]
     fn to_bytes_sha256_consistency() {
         let t = sample_envelope();
         assert_eq!(double_sha256(&t.to_bytes()), envelope_id(&t).0);

+ 5 - 7
crates/kuatia-types/src/canonical.rs

@@ -120,17 +120,15 @@ impl ToBytes for BookId {
 
 impl ToBytes for NewPosting {
     fn to_bytes(&self) -> Vec<u8> {
+        // `payer` is provenance, not identity: it is deliberately excluded from
+        // the content-address preimage so an EnvelopeId reflects only economic
+        // content (owner, asset, value). Two envelopes that differ only in a
+        // payer annotation share an id, hence one idempotency key. Provenance is
+        // still persisted on the envelope record for audit.
         let mut buf = Vec::new();
         buf.extend(self.owner.to_bytes());
         buf.extend_from_slice(&self.asset.0.to_be_bytes());
         buf.extend(self.value.to_bytes());
-        match &self.payer {
-            Some(p) => {
-                buf.push(1);
-                buf.extend(p.to_bytes());
-            }
-            None => buf.push(0),
-        }
         buf
     }
 }

+ 5 - 1
crates/kuatia-types/src/posting.rs

@@ -95,6 +95,10 @@ pub struct NewPosting {
     pub asset: AssetId,
     /// Signed amount: positive = value controlled by the account, negative = offset position.
     pub value: Cent,
-    /// Informational provenance — who funded this posting.
+    /// Provenance — who funded this posting. Descriptive only: it is excluded
+    /// from the content-address preimage (see [`NewPosting`]'s `ToBytes`), so it
+    /// does not affect the [`EnvelopeId`](crate::EnvelopeId) or the idempotency
+    /// key. Persisted on the envelope record for audit, not on the stored
+    /// [`Posting`].
     pub payer: Option<AccountId>,
 }