You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: bip-0442.md
+59-32Lines changed: 59 additions & 32 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -33,7 +33,7 @@ Stack operation:
33
33
- Pop `x2` and `x1` from the stack.
34
34
- Push `pc` onto the stack.
35
35
36
-
[^1]: The number of SHA256 blocks is minimized in typical use cases. The tag can be pre-computed as a SHA256 mid-state, requiring only 2 hash cycles for two 32-byte items, or 1 for two smaller items.
36
+
[^1]: The number of SHA256 blocks is minimized in typical use cases. The tag can be precomputed as a SHA256 mid-state, requiring only two hash cycles for two 32-byte items, or one for two smaller items.
37
37
38
38
## Motivation
39
39
@@ -49,65 +49,91 @@ Combined with `OP_CHECKSIGFROMSTACK`, signing commitments to multiple items enab
49
49
50
50
`OP_PAIRCOMMIT` can commit to a vector of stack elements securely and efficiently.
Lightning Symmetry contracts require data availability for contested closes. By forcing parties to include settlement transaction hashes in the witness, later updates can reconstruct scripts using only the latest state.
66
+
Lightning Symmetry contracts require data availability for contested closes. [^3]By forcing parties to include settlement transaction hashes in the witness, later updates can reconstruct scripts using only the latest state.
62
67
[^3]: The required data is a full CTV hash of the settlement transaction when there are open HTLCs, or merely the difference in balance between the channel partners in other cases. Whether the latter optimization would be used is an implementation detail not further discussed here.
63
68
64
-
Example channel script (pseudo-code):
65
-
66
-
```text
67
-
# S = 500000000
68
-
# internal key = [BIP-327] aggregate key of channel participants
These constructions ensure both parties sign the same pair hash, requiring inclusion of both update and settlement hashes in the witness.
109
+
These constructions ensure both parties sign the same pair hash, requiring inclusion of both update and settlement hashes in the witness. [^4][^5]
110
+
111
+
[^4]: `state-n-hash` commits to a specific `nLockTime` value for the transaction through `OP_CHECKTEMPLATEVERIFY`; `OP_CHECKLOCKTIMEVERIFY` ensures that the state progression can only go forward (the transaction needs to have greater `nLockTime` value than the intermediate state
112
+
[^5]: `OP_0NOTEQUAL` can be omitted (any non-zero value left on the stack would be accepted by the script interpreter).
87
113
88
114
### In MATT
89
115
90
-
The Merklize All The Things ([MATT]) framework uses `OP_CAT` to combine items for commitments. `OP_PAIRCOMMIT` provides a more ergonomic and secure alternative[^4].
116
+
The Merklize All The Things ([MATT]) framework uses `OP_CAT` to combine items for commitments. `OP_PAIRCOMMIT` provides a more ergonomic and secure alternative[^6].
91
117
92
-
[^4]: Naive use of `OP_CAT` is vulnerable to byte shifting attacks. E.g. `0x0102 || 0x03` equals `0x01 || 0x0203`. Mitigation requires length checking or hashing.
118
+
[^6]: Naive use of `OP_CAT` is vulnerable to byte shifting attacks. E.g. `0x0102 || 0x03` equals `0x01 || 0x0203`. Mitigation requires length checking or hashing.
93
119
94
120
## Alternative approaches
95
121
96
122
Alternative approaches considered and rejected:
97
123
98
-
-`OP_CAT`[^4][^7]
99
-
- SHA256 streaming opcodes[^7]
124
+
-`OP_CAT`[^6][^9]
125
+
- SHA256 streaming opcodes[^9]
100
126
- Merkle operation opcodes
101
127
- 'Kitty' CAT: `OP_CAT` with size limits
102
-
-`OP_CHECKTEMPLATEVERIFY` committing to the taproot annex[^5]
128
+
-`OP_CHECKTEMPLATEVERIFY` committing to the taproot annex[^7]
103
129
-`OP_CHECKSIGFROMSTACK` on n elements
104
130
-`OP_VECTORCOMMIT`: generalized for n > 2 elements
105
131
- ReKey/Laddering[^2]
106
-
-`OP_RETURN`[^6]
132
+
-`OP_RETURN`[^8]
107
133
108
-
[^5]: Committing to the taproot annex allows one additional item, but it is not accessible to script.
109
-
[^6]: `OP_RETURN` can commit to additional data, but is costly and not accessible to script.
110
-
[^7]: `OP_PAIRCOMMIT` enables useful scripts without the risks of `OP_CAT` (see [CAT-tricks-I], [CAT-tricks-II]).
134
+
[^7]: Committing to the taproot annex allows one additional item, but it is not accessible to script.
135
+
[^8]: `OP_RETURN` can commit to additional data, but is costly and not accessible to script.
136
+
[^9]: `OP_PAIRCOMMIT` enables useful scripts without the risks of `OP_CAT` (see [CAT-tricks-I], [CAT-tricks-II]).
111
137
112
138
## Reference Implementation
113
139
@@ -189,6 +215,7 @@ This document is licensed under the 3-clause BSD license.
0 commit comments