# Go-zenon and Bend 2: 22 laws

**URL:** https://forum.hypercore.one/t/go-zenon-and-bend-2-22-laws/957
**Category:** Development
**Created:** [November 19, 2026, 10:13am UTC](https://forum.hypercore.one/t/go-zenon-and-bend-2-22-laws/957 "2026-11-19T10:13:35Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![0x3639](https://forum.hypercore.one/user_avatar/forum.hypercore.one/0x3639/32/33_2.png) [@0x3639](https://forum.hypercore.one/u/0x3639)
#### Post date: [November 19, 2026, 10:13am UTC](https://forum.hypercore.one/t/go-zenon-and-bend-2-22-laws/957/1 "2026-11-19T10:13:35Z")

</div>

# Proving that go-zenon cannot double spend: 22 laws, checked by machine

I’m experimenting with a new kind of testing to the go-zenon `dev` branch. Instead of trying inputs and looking at the results, we wrote down the rules that must never be broken, proved them mathematically, and then checked that the real node follows them. This post explains the tool, the rules, and exactly what was and was not proved.

Short version: we found no way to spend value twice. The rules are proved for a model of the node, and the node agreed with that model on every one of roughly 32,000 sequences of transactions we ran, including every possible short sequence from a fixed list of steps.

## What is Bend

[Bend](https://github.com/bendlang/bend) is a programming language by Victor Taelin and the Higher Order Company. Version 2 came out in September 2026. Its special feature is that its compiler is also a proof checker.

In Bend you can write a **law** : a statement that must be true for every possible input. For example, “for every list of moves, the game is never won”. The compiler will not accept the program until someone supplies a proof of that law, and it checks the proof step by step. If one case could break the law, the proof is rejected.

That is different from testing. A test says “these inputs work”. A law says “all inputs work”, and a machine confirms it.

Bend is young, so we do not rely on its main checker alone. Every proof is checked a second time by a small kernel whose own correctness has been proved in Lean, a long-established proof assistant.

## How we used it

Bend proves things about Bend code, and go-zenon is written in Go. So the work has two halves.

1. **A model with laws.** We wrote the part of go-zenon that moves value again in Bend, as small as possible while keeping the node’s structure: balances, sends and receives, and the contracts that hold funds. The laws are proved about this model.
2. **A comparison with the node.** A test gives the same transactions to the model and to the real go-zenon chain, verifier and VM, and fails if they disagree on any step or on the final balances.

The first half is a proof. The second half is evidence. Both are described honestly below.

## The 22 laws

### Accounts and transfers

1. **No value is created.** Whatever sequence of sends, receives and momentums reaches the ledger, valid or not, the total of all balances plus value in transit stays the same.
2. **You cannot send more than you have.** A send above the sender’s balance is always refused.
3. **A send is received once.** After an account has received a send, the same receive is refused.
4. **Only the addressee can receive.** With this rule, a send that two accounts try to receive leaves the total unchanged.
5. **Rule 4 is necessary.** Without it, the model shows the total growing. The “already received” mark alone would not be enough.

### Contracts that hold value (HTLC, PTLC, stake, plasma fusion)

**Nothing is created or lost**

1. **The contract keeps its value.** Whatever sequence of creates, unlocks, reclaims, cancels and failed calls happens, balances plus what the contract holds stays the same.

**A payout uses up its entry**

1. **An HTLC unlock takes the entry with it.** When it pays, the contract holds exactly one entry fewer.
2. **A reclaim takes the entry with it.**
3. **A PTLC unlock takes the entry with it.**
4. **A stake cancel empties the entry.** After a cancel that pays, the entry holds nothing.

**You get exactly what your entry holds**

1. to 14. **An unlock, a PTLC unlock, a reclaim and a cancel each pay exactly what the entry holds.** Not more, not less, and nothing from anyone else’s entry.

**Who can take the funds, and when**

1. **Unlock and reclaim never overlap.** At no moment can an entry be both unlocked and reclaimed.
2. **The wrong preimage pays nothing.**
3. **Only the maker reclaims.** After expiry, another account asking for the entry gets nothing.

**Worked examples, followed to the end**

1. **An unlock pays once** , even when the entry is asked for again by unlock and by reclaim.
2. **A reclaim pays once.**
3. **A PTLC unlock pays once** , to the account named in the signature.
4. **A second cancel of a cancelled stake pays zero.**

**Failed calls**

1. **A call that fails changes nothing.** If a contract refuses a call that carried funds, every balance and every entry is exactly as before: the amount comes back whole, once.

## What we proved

**Proved, for every possible input:** all 22 laws hold for the model. Two independent checkers accept every proof, the second being the Lean-proved kernel.

**Checked that the laws are not empty.** A law can be proved and still say nothing if it is stated too weakly. So we broke the model on purpose in 21 ways, each one a way to double spend or to be paid without the right to, and required the proofs to fail. They failed every time. This step earned its place: our first set of contract laws missed two of these faults, and we added laws 16 and 17 because of it.

## What we checked on the real node

| Check | Result |
| --- | --- |
| Random sequences of transfers, on node and model | 306 sequences, 3,484 transactions, no disagreement |
| Random sequences on the HTLC, PTLC, stake and fusion contracts | 1,234 sequences, about 14,000 calls, no disagreement |
| Every possible sequence of up to 4 steps from a fixed list, for transfers, HTLC and PTLC | 30,864 sequences, no disagreement |
| Calls that a contract refuses after taking funds | 591 cases; the amount came back once each time |
| Two transactions competing for one position in an account’s chain | exactly one took effect, every time |
| A chain rollback | no value appeared or disappeared |

We also checked that this comparison would notice a real fault. We removed one safety check at a time from a copy of go-zenon’s Go code (the balance check, the “already received” check, the addressee check, the removal of a paid contract entry, the refund, and others) and ran the comparison again. All 11 broken versions were caught. None of these changes touched the real source; they exist only inside the test.

## What this does not show

We want to be exact about the limits.

- **It is not a proof about the Go code.** The laws are proved for the model. That the node behaves like the model is shown for the sequences we ran, which is strong evidence and not a proof.
- **Longer or different sequences.** The exhaustive check covers every sequence up to a fixed length from a fixed list of steps. A fault that needs more steps, or a step not on the list, would only be found by the random runs.
- **One node only.** The model does not describe two nodes that see different transactions. That is a consensus question and needs different tools.
- **Not covered yet:** rewards of any kind, the bridge, liquidity, accelerator, pillar and sentinel payouts, and some less common PTLC options.
- **Shortened lock times in the stake and fusion tests.** They show what a cancel does once the lock has run out, not that the lock lengths themselves are right.
- **Trust that remains.** The result depends on the Lean kernel being right, on Bend’s translation into that kernel, and on our reading of the node’s code when writing the model. The comparison guards the last of these, and it corrected our model once.

## Why we think this is worth doing

Unit tests and fuzzing can show that a bug exists. They cannot show that none does. For the one property that matters most in a ledger, that value cannot be spent twice, we now have the rules written in a form anyone can read, a machine-checked proof that the rules are sound, and a repeatable check that the node follows them. When the node’s code changes, the same check runs again in a few minutes.

Everything is scripted so that others can repeat it: one command builds the tools in a container, checks the proofs, breaks the model, runs the node comparison, breaks the node, and runs the exhaustive cases.

_Code and full results: [link to be added when the branch is published]._
