Repository navigation
Commit 0f4793b
authored
perf(sapling-crypto)!: hold value commitments as bytes, not points (#638)
* perf(sapling-crypto)!: hold value commitments as bytes, not points
Parsing a Sapling bundle decompressed every spend's and output's cv into a
Jubjub point - a field square root each, plus a small-order check - and every
consumer short of proof and binding-signature verification then compressed it
straight back: the txid digest (cv().to_bytes() is the only field the digest
re-serialises from a parsed point), the outgoing cipher key (prf_ock), the
sighash, serialisation. Profiled on a wallet's memo backfill, that round trip
was 26% of all CPU.
ValueCommitment now keeps its 32 bytes. to_bytes() returns them; try_point()
decompresses and checks small order on demand, by value; derive() computes the
point once and stores its encoding; from_bytes_unvalidated() is the parser's
constructor and from_bytes_not_small_order() still validates eagerly for callers
that want that. The verifier calls try_point() and fails closed on an invalid
encoding, and CommitmentSum takes the point rather than the commitment, so the
callers that need arithmetic validate first. The consensus checks move from
parse time to verification time, where a node checks the description anyway.
Microbenchmark over 30,752 testnet transactions (110 MB; 3,339 Sapling spends,
11,462 outputs): Transaction::read 1.930 s to 0.993 s, 1.94x; 130 to 67 us per
Sapling description. The wallet crates read cv as bytes only (prf_ock,
serialisation), so they need no change; as_inner()'s only caller in this
repository is the verifier.
BREAKING CHANGE: ValueCommitment::as_inner() is removed (use try_point());
CommitmentSum's AddAssign/SubAssign take &jubjub::ExtendedPoint; a parsed cv is
no longer validated at parse time.
* docs(changelog): fragment for #2
* fix(sapling-crypto)!: sum value commitments fallibly with CommitmentSum::try_sum
The Add, Sub and Sum impls over ValueCommitment decoded each point with an
expect. Transaction::read now yields unvalidated commitments, so summing the
cvs of a parsed transaction could panic. Replace them with
CommitmentSum::try_sum, which returns None on an invalid commitment; the
builder expects on its own commitments and the PCZT IO finalizer returns
ValueCommitMismatch.
Correct the ValueCommitment doc on network data, and test that try_point
accepts exactly the encodings parsing used to accept.
* test(zcash_primitives): an invalid Sapling cv parses and fails verification
Corrupt a spend cv and an output cv of a valid testnet transaction, first
to the identity and then to bytes off the curve. The transaction still
reads and round-trips, and the batch validator, the single verifier and
CommitmentSum::try_sum all reject it.
* docs(changelog): fragment for #6381 parent cd74fe7 commit 0f4793b
11 files changed
Lines changed: 497 additions & 89 deletions
File tree
- crates
- sapling-crypto/src
- pczt
- value
- zcash_primitives
- src/transaction
- components
- tests
- docs/changelog/unreleased
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
835 | 835 | | |
836 | 836 | | |
837 | 837 | | |
838 | | - | |
839 | | - | |
840 | | - | |
841 | | - | |
842 | | - | |
843 | | - | |
844 | | - | |
845 | | - | |
| 838 | + | |
| 839 | + | |
| 840 | + | |
| 841 | + | |
| 842 | + | |
| 843 | + | |
846 | 844 | | |
847 | 845 | | |
848 | 846 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
45 | 45 | | |
46 | 46 | | |
47 | 47 | | |
48 | | - | |
49 | | - | |
50 | | - | |
51 | | - | |
52 | | - | |
53 | | - | |
54 | | - | |
55 | | - | |
56 | | - | |
57 | | - | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
58 | 52 | | |
59 | 53 | | |
60 | 54 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
130 | 130 | | |
131 | 131 | | |
132 | 132 | | |
133 | | - | |
134 | | - | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
135 | 146 | | |
136 | | - | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
137 | 150 | | |
138 | 151 | | |
139 | 152 | | |
| |||
145 | 158 | | |
146 | 159 | | |
147 | 160 | | |
148 | | - | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
149 | 164 | | |
150 | 165 | | |
151 | | - | |
| 166 | + | |
152 | 167 | | |
153 | | - | |
154 | | - | |
155 | | - | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
156 | 174 | | |
157 | 175 | | |
158 | | - | |
| 176 | + | |
159 | 177 | | |
160 | 178 | | |
161 | 179 | | |
| |||
167 | 185 | | |
168 | 186 | | |
169 | 187 | | |
170 | | - | |
171 | | - | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
172 | 203 | | |
173 | 204 | | |
174 | 205 | | |
175 | 206 | | |
176 | | - | |
| 207 | + | |
177 | 208 | | |
178 | 209 | | |
179 | 210 | | |
| |||
228 | 259 | | |
229 | 260 | | |
230 | 261 | | |
| 262 | + | |
| 263 | + | |
231 | 264 | | |
232 | 265 | | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
233 | 269 | | |
234 | | - | |
| 270 | + | |
| 271 | + | |
235 | 272 | | |
236 | 273 | | |
237 | 274 | | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
| 346 | + | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
| 359 | + | |
| 360 | + | |
| 361 | + | |
| 362 | + | |
| 363 | + | |
| 364 | + | |
| 365 | + | |
| 366 | + | |
| 367 | + | |
| 368 | + | |
| 369 | + | |
| 370 | + | |
| 371 | + | |
| 372 | + | |
| 373 | + | |
| 374 | + | |
| 375 | + | |
| 376 | + | |
| 377 | + | |
| 378 | + | |
| 379 | + | |
| 380 | + | |
| 381 | + | |
| 382 | + | |
| 383 | + | |
| 384 | + | |
| 385 | + | |
| 386 | + | |
| 387 | + | |
| 388 | + | |
| 389 | + | |
| 390 | + | |
| 391 | + | |
| 392 | + | |
| 393 | + | |
| 394 | + | |
| 395 | + | |
| 396 | + | |
| 397 | + | |
| 398 | + | |
| 399 | + | |
| 400 | + | |
| 401 | + | |
| 402 | + | |
238 | 403 | | |
239 | 404 | | |
240 | 405 | | |
| |||
257 | 422 | | |
258 | 423 | | |
259 | 424 | | |
260 | | - | |
| 425 | + | |
261 | 426 | | |
262 | 427 | | |
263 | | - | |
| 428 | + | |
| 429 | + | |
| 430 | + | |
264 | 431 | | |
265 | 432 | | |
266 | 433 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
183 | 183 | | |
184 | 184 | | |
185 | 185 | | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
186 | 198 | | |
187 | 199 | | |
188 | 200 | | |
| |||
210 | 222 | | |
211 | 223 | | |
212 | 224 | | |
213 | | - | |
214 | | - | |
215 | | - | |
216 | | - | |
217 | | - | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
218 | 230 | | |
219 | 231 | | |
220 | 232 | | |
221 | | - | |
222 | | - | |
223 | | - | |
224 | | - | |
225 | | - | |
226 | | - | |
227 | | - | |
228 | | - | |
229 | | - | |
230 | | - | |
231 | | - | |
232 | | - | |
233 | | - | |
234 | | - | |
235 | | - | |
236 | | - | |
237 | | - | |
238 | | - | |
239 | | - | |
240 | | - | |
241 | | - | |
242 | | - | |
243 | | - | |
244 | | - | |
245 | | - | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
246 | 237 | | |
247 | 238 | | |
248 | 239 | | |
| |||
253 | 244 | | |
254 | 245 | | |
255 | 246 | | |
256 | | - | |
257 | | - | |
258 | | - | |
259 | | - | |
260 | | - | |
261 | | - | |
262 | | - | |
263 | | - | |
264 | | - | |
265 | | - | |
266 | | - | |
267 | | - | |
0 commit comments