Terms and Evidence¶
Terms are the agreement¶
The terms define the escrow. They include the chain, asset, amount, signers, threshold, policies, payouts, deadlines, confirmation policy, and fee policy.
Terms are immutable and canonical. terms_hash is a deterministic hash of the
canonical terms. Any change to the terms produces a different hash.
The store is not a trust anchor¶
A record contains its own terms and its own terms_hash. The hash is a
consistency value. It is not authentication.
If an attacker can rewrite the store, the attacker can rewrite both the terms and the hash. Loading a record and trusting its embedded hash is unsafe.
Keep the expected terms hash outside the mutable store. Good locations include:
- A signed terms manifest delivered to each party
- A configuration system with change control
- A hardware backed secret store
- An independent append only log
- A contract or settlement agreement reference
The anchor must be available before the escrow is funded and on every reload.
Safe reload pattern¶
from multisig_escrow import BitcoinEscrow
trusted_terms_hash = load_trusted_hash_from_signed_manifest(escrow_id)
escrow = BitcoinEscrow.load(
escrow_id,
store=store,
clock=clock,
trusted_terms_hash=trusted_terms_hash,
)
The same parameter exists on EvmEscrow.load and MoneroEscrow.load.
If you already have a loaded record, use the helper:
The helper uses a constant time comparison and raises TermsError when the hash
does not match. It does not make the store trusted. It only makes the external
anchor explicit.
Loading without an anchor¶
trusted_terms_hash is optional. Loading without it is possible for migration,
tests, and inspection. It is unsafe for production operation.
If your application cannot obtain a trusted terms hash, stop. Do not create, fund, approve, or settle an escrow from an unanchored record.
Evidence context¶
Some chains require fresh context.
from multisig_escrow import ChainTip, EvidenceContext
context = EvidenceContext(
now=now,
tip=ChainTip(
height=height,
hash=block_hash,
timestamp=block_time,
),
)
now is the application time. tip is the chain tip claimed by your trusted
data source.
EVM funding and Monero funding and settlement require a tip. A tip in the future
is rejected with FreshnessError. A tip older than one hour is rejected with
FreshnessError.
Freshness limits replay and stale state. They do not prove that the tip is true.
Funding evidence¶
Funding evidence is chain specific.
Bitcoin: BitcoinFundingEvidence contains raw transaction bytes, transaction
ID, output index, amount, confirmations, and optional block height. The library
parses the raw transaction and checks the output script and amount.
EVM: SafeFundingEvidence contains the Safe address, chain ID, asset,
transaction ID, amount, confirmations, and optional block height. The library
checks the target, asset, amount, confirmation policy, and block depth.
Monero: MoneroFundingEvidence contains transaction ID, output index, output
key, commitment, amount, confirmations, block height, proof or attestation, and
mode. The library checks the target, amount, confirmation policy, block depth,
view key policy, and the external funding verifier.
Funding evidence is caller supplied. The library cannot query the chain.
Settlement evidence¶
Settlement evidence is the final artifact produced by the chain adapter.
Bitcoin: final raw transaction and transaction ID.
EVM: Safe execTransaction calldata and the Safe address.
Monero: signed transaction set, transaction ID, key images, outputs, fee, and unlock time.
finalize verifies the artifact against the proposal and approval tokens. It
does not broadcast.
Broadcast evidence¶
Broadcast evidence proves that a specific payload was submitted.
from multisig_escrow import BroadcastEvidence
evidence = BroadcastEvidence(
txid=txid,
payload_hash=payload_hash,
raw_tx=raw_tx,
)
For EVM, either provide the raw outer transaction or provide the Safe execution log. For Bitcoin and Monero, provide the raw transaction set where supported.
mark_broadcast verifies the payload binding and the artifact. It cannot prove
that the transaction is in the best chain.
Confirmation evidence¶
Confirmation evidence is also caller supplied. The library checks the declared count against the settlement confirmation policy. It cannot query the chain.
Use a trusted node or independent verifier to confirm:
- Transaction inclusion
- Block depth
- Chain reorganization status
- Finality for the selected chain
- Monero key image status
Evidence freshness¶
Evidence can be correct at one moment and stale at the next.
- Reject future timestamps.
- Reject tips older than your policy allows.
- Reject confirmations that exceed the declared block depth.
- Recheck evidence before each state transition that depends on it.
- Do not cache funding or settlement evidence longer than your policy allows.
The default EVM and Monero tip freshness limit is one hour. A stricter limit is allowed. A looser limit requires an explicit risk decision.
Store contract¶
Implement the Store protocol for production:
Requirements:
- Durable writes
- Atomic compare and set on
expected_revision - Immutable terms for a given escrow
- No silent merge on conflict
- Authentication and access control
- Backup and recovery
- Append only change history if you need non repudiation
- Payload persistence if you reload between approval and finalization
MemoryStore stores approval payloads through save_payload and
load_payload. A custom store should implement those optional methods and
persist the signed payloads. If it does not, a reloaded facade cannot finalize
an earlier approval. Keep the facade instance alive or reapprove after reload.
MemoryStore is for development and tests. It is not durable and not tamper
evident.
Concurrency¶
The store uses optimistic revision checks. A concurrent writer can receive
StoreConflictError. The library fails closed.
Use one writer per escrow, a per escrow lock or queue, or a retry loop after reloading the latest record. Do not share a mutable facade across threads without external serialization.
Clock¶
The facade accepts a Clock with a now() method. The default is
SystemClock, which returns the current UTC time.
Use a controlled clock in tests. In production, use a reliable time source and monitor clock drift. Deadlines and freshness checks depend on it.
Retention¶
Keep:
- The trusted terms anchor
- The escrow record history
- Funding evidence
- Approval payloads
- Final settlement artifacts
- Broadcast evidence
- Confirmation evidence
- Operator checklist records
Retain records for the dispute and legal period that applies to your jurisdiction. Do not store private keys, seed phrases, or private view keys.