Bonded warehouse — no duty, no exit
A customs bonded warehouse holds imported goods on which duty has NOT yet been paid. The whole institution rests on one rule: bonded goods leave for the domestic market only after duty is settled, or leave the country entirely (re-export, duty never owed). "Bond leakage" — goods slipping into commerce duty-unpaid — is a perennial fraud; the UK lost hundreds of millions of pounds a year to bonded alcohol diversion in the 1990s "London City Bond" scandal, where paperwork showed exports that never left the island. Structurally: `domestic_market` is reachable ONLY through `duty_paid`, `re_exported` is terminal, and the duty ledger refuses a release whose payment doesn't cover the assessment. The diversion has no path.
A Soma program from the logistics part of the verified corpus: 125 lines, cells BondedWarehouse, NoBondLeakage. It passes soma check with soma 3.2.4.
How it is built
The cell BondedWarehouse declares 5 signals in its face: admit_goods(consignment: String, duty_owed_cents: Int) -> Map, pay_duty(consignment: String, cents: Int) -> Map, release_domestic(consignment: String) -> Map, re_export(consignment: String) -> Map and bond_status(consignment: String) -> Map; keeps 2 memory slots: owed (Map<String, Int>, persistent and consistent) under the invariant owed >= 0 and paid (Map<String, Int>, persistent and consistent) under the invariant paid >= 0. Its state machine bond starts in in_bond and allows 3 transitions: in_bond -> duty_paid, in_bond -> re_exported and duty_paid -> domestic_market. domestic_market and re_exported are terminal. Handlers: admit_goods (line 45), pay_duty (line 52), release_domestic (line 68), re_export (line 76) and bond_status (line 82).
The file also holds 1 test cell (NoBondLeakage) with 17 assertions, run by soma test.
The source
bonded_warehouse.cell
// ============================================================================
// BONDED WAREHOUSE — no duty, no exit
// ============================================================================
//
// A customs bonded warehouse holds imported goods on which duty has NOT
// yet been paid. The whole institution rests on one rule: bonded goods
// leave for the domestic market only after duty is settled, or leave the
// country entirely (re-export, duty never owed). "Bond leakage" — goods
// slipping into commerce duty-unpaid — is a perennial fraud; the UK lost
// hundreds of millions of pounds a year to bonded alcohol diversion in
// the 1990s "London City Bond" scandal, where paperwork showed exports
// that never left the island.
//
// Structurally: `domestic_market` is reachable ONLY through `duty_paid`,
// `re_exported` is terminal, and the duty ledger refuses a release whose
// payment doesn't cover the assessment. The diversion has no path.
// ============================================================================
cell BondedWarehouse {
face {
signal admit_goods(consignment: String, duty_owed_cents: Int) -> Map
signal pay_duty(consignment: String, cents: Int) -> Map
signal release_domestic(consignment: String) -> Map
signal re_export(consignment: String) -> Map
signal bond_status(consignment: String) -> Map
}
memory {
owed: Map<String, Int> [persistent, consistent]
invariant owed >= 0
paid: Map<String, Int> [persistent, consistent]
invariant paid >= 0
}
// No edge in_bond -> domestic_market. Duty first, always.
// Both exits are terminal: goods leave the bond exactly once.
state bond {
initial: in_bond
in_bond -> duty_paid
in_bond -> re_exported
duty_paid -> domestic_market
}
on admit_goods(consignment: String, duty_owed_cents: Int) {
if duty_owed_cents <= 0 { return map("ok", false, "reason", "assessment must be positive") }
owed.set(consignment, duty_owed_cents)
paid.set(consignment, 0)
return map("ok", true, "consignment", consignment, "owed_cents", duty_owed_cents)
}
on pay_duty(consignment: String, cents: Int) {
if cents <= 0 { return map("ok", false, "reason", "payment must be positive") }
let assessment = owed.get(consignment)
if assessment == () { return map("ok", false, "reason", "unknown consignment") }
let total = (paid.get(consignment) ?? 0) + cents
paid.set(consignment, total)
if total < assessment {
let short = assessment - total
return map("ok", true, "settled", false, "short_cents", short)
}
// settled in full — NOW the gate opens
let r = try { transition(consignment, "duty_paid") }
if r.error != () { return map("ok", false, "reason", "{r.error}") }
return map("ok", true, "settled", true, "state", "duty_paid")
}
on release_domestic(consignment: String) {
let r = try { transition(consignment, "domestic_market") }
if r.error != () {
return map("ok", false, "reason", "duty not settled: {r.error}")
}
return map("ok", true, "state", "domestic_market")
}
on re_export(consignment: String) {
let r = try { transition(consignment, "re_exported") }
if r.error != () { return map("ok", false, "reason", "{r.error}") }
return map("ok", true, "state", "re_exported")
}
on bond_status(consignment: String) {
return map("consignment", consignment, "state", get_status(consignment),
"owed_cents", owed.get(consignment) ?? 0,
"paid_cents", paid.get(consignment) ?? 0)
}
}
cell test NoBondLeakage {
rules {
// 40 cases of whisky enter the bond owing 120,000 cents of duty
assert admit_goods("WX-40", 120000).ok == true
// THE DIVERSION: straight to the domestic market, duty unpaid.
// The edge does not exist.
assert release_domestic("WX-40").ok == false
assert_fails transition("WX-40", "domestic_market")
// partial payment does not open the gate
assert pay_duty("WX-40", 50000).settled == false
assert release_domestic("WX-40").ok == false
// full settlement does
assert pay_duty("WX-40", 70000).settled == true
assert release_domestic("WX-40").ok == true
assert bond_status("WX-40").state == "domestic_market"
// released goods cannot re-enter the bond or "re-export"
assert_fails transition("WX-40", "in_bond")
assert_fails transition("WX-40", "re_exported")
// re-export is legal duty-free — and terminal (the LCB fraud was
// "exported" goods reappearing; here they cannot re-enter)
assert admit_goods("WX-41", 99000).ok == true
assert re_export("WX-41").ok == true
assert_fails transition("WX-41", "in_bond")
assert_fails transition("WX-41", "duty_paid")
assert release_domestic("WX-41").ok == false
// ledgers refuse negative money
assert_fails owed.set("WX-41", -1)
assert_fails paid.set("WX-41", -1)
}
}What the toolchain says
$ soma check bonded_warehouse.cell
✓ All checks passed.$ soma test bonded_warehouse.cell
test NoBondLeakage ...
✓ assert admit_goods("WX-40", 120000).ok == true
✓ assert release_domestic("WX-40").ok == false
✓ assert_fails transition("WX-40", "domestic_market") — raised invalid transition: in_bond → domestic_market. Current state: 'in_bond'. Valid targets: [duty_paid, re_exported]
✓ assert pay_duty("WX-40", 50000).settled == false
✓ assert release_domestic("WX-40").ok == false
✓ assert pay_duty("WX-40", 70000).settled == true
✓ assert release_domestic("WX-40").ok == true
✓ assert bond_status("WX-40").state == "domestic_market"
✓ assert_fails transition("WX-40", "in_bond") — raised invalid transition: domestic_market → in_bond. Current state: 'domestic_market'. Valid targets: []
✓ assert_fails transition("WX-40", "re_exported") — raised invalid transition: domestic_market → re_exported. Current state: 'domestic_market'. Valid targets: []
✓ assert admit_goods("WX-41", 99000).ok == true
✓ assert re_export("WX-41").ok == true
✓ assert_fails transition("WX-41", "in_bond") — raised invalid transition: re_exported → in_bond. Current state: 're_exported'. Valid targets: []
✓ assert_fails transition("WX-41", "duty_paid") — raised invalid transition: re_exported → duty_paid. Current state: 're_exported'. Valid targets: []
✓ assert release_domestic("WX-41").ok == false
✓ assert_fails owed.set("WX-41", -1) — raised memory invariant violated on 'owed': owed >= 0 — rejected write of -1 (key "WX-41"); the slot is unchanged
✓ assert_fails paid.set("WX-41", -1) — raised memory invariant violated on 'paid': paid >= 0 — rejected write of -1 (key "WX-41"); the slot is unchanged
17 tests: 17 passed, 0 failed$ soma verify bonded_warehouse.cell
Verifying bonded_warehouse.cell...
State machine 'bond': 4 states, initial 'in_bond'
States: [domestic_market, duty_paid, in_bond, re_exported]
✓ 4 states, 3 transitions
✓ all states reachable from 'in_bond'
✓ terminal states: [re_exported, domestic_market]
✓ no deadlocks
✓ liveness: every state can eventually reach a terminal state
✓ think-isolated: CTL safety properties hold regardless of LLM output (3 handlers, 3 literal transitions, 0 dynamic)
✓ termination: all 5 handlers structurally terminate
✓ refinement: handler `pay_duty` ⟶ {duty_paid}
✓ refinement: handler `release_domestic` ⟶ {domestic_market}
✓ refinement: handler `re_export` ⟶ {re_exported}
· transition sources: `pay_duty`, `release_domestic`, `re_export` call transition(id, target) without declaring the source — the runtime refuses a move the graph forbids, but the proof does not see where the handler starts; `transition(id, from, to)` names the edge (checked by `soma check`, refused at run time from any other state)
BondedWarehouse/invariants:
✓ invariant owed >= 0 — writer 'admit_goods' proven by induction (writes duty_owed_cents)
✓ invariant paid >= 0 — writer 'admit_goods' proven (writes 0)
✓ invariant paid >= 0 — writer 'pay_duty' proven by induction (writes total)
13 passed, 0 warnings, 0 failures
Temporal properties for 'bond':
✓ deadlock_free — no deadlocks in any reachable state
Temporal: 1 passed, 0 failed
VERIFY OK