-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathAtomicSwap.vg
More file actions
26 lines (21 loc) · 917 Bytes
/
AtomicSwap.vg
File metadata and controls
26 lines (21 loc) · 917 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
// Atomic Swap: (HTLC) Alice swaps a Secret for Bob's Payment.
// If Alice claims the Payment, the Secret is revealed (publicly).
// If Alice ghosts, Bob gets his money back.
// Distribution semantics: pot (20 wei) allocated based on swap outcome
game main() {
join Alice() $ 10 Bob() $ 10;
// Alice commits to the pre-image (the secret key)
commit Alice(secret: int) || { Bob -> 20 };
// Bob inspects the commitment (abstractly) and funds the contract
yield Bob(fund: bool) || { Alice -> 20 };
// Alice must reveal the secret to get the money
reveal Alice(secret: int) || { Bob -> 20 };
withdraw
// Case 1: Bob didn't fund -> Refund everyone
(!Bob.fund) ?
{ Alice -> 10; Bob -> 10 }
:
// Case 2: Bob funded, Alice revealed -> Swap happens
// Alice gets the payment (10), Bob effectively "gets" the secret (valued at 10)
{ Alice -> 10; Bob -> 10 }
}