Commit ae4984e
authored
Backport of #6820.
## Motivation
The web wallet decompresses bytecodes with `ruzstd`, whose
`StreamingDecoder` decodes a single
zstd frame and then keeps returning `Ok(0)`. Our `wasm32` code did not
account for that, as
noted in #2710:
* `decompress` looped `while !decoder.get_ref().is_empty()`, so a
bytecode made of more than one
frame made it **loop forever**, freezing the tab, instead of merely
decoding the first frame.
* `decompressed_size_at_most` measured the first frame only, so it
underestimated the size of a
multi-frame bytecode.
Validators use the `zstd` crate, which accepts several concatenated
frames, both for the size
check in `linera-execution/src/policy.rs` and for decompression in
`linera-storage/src/lib.rs`.
Nothing that we compress produces multiple frames, but nothing rejects
them either: a module
published as two frames is valid to a validator and hangs every web
client that loads it.
## Proposal
Decode frame by frame on `wasm32`, creating a `StreamingDecoder` per
frame and stepping over
skippable frames using the length in their header, which is what `zstd`
does. The two targets
now accept the same bytecodes, so this is not a change in validation.
The frame loop is shared by `decompress` and
`decompressed_size_at_most`, and replaces the
`TODO(#2710)` comments in both.
Also drops the two `#[cfg(with_metrics)]` blocks from the `wasm32` impl:
`with_metrics` is
defined as `all(not(target_arch = "wasm32"), feature = "metrics")`, so
they were dead code, and
the one in `decompress` referred to an unqualified
`BYTECODE_DECOMPRESSION_LATENCY` that would
not have compiled had it ever been enabled.
## Test Plan
Cherry-picked from #6820 with no conflicts, then rechecked against this
branch's Rust 1.86
toolchain: `cargo test -p linera-base`, `cargo clippy -p linera-base
--all-targets
--all-features -- -D warnings`, `cargo clippy -p linera-base --target
wasm32-unknown-unknown
-- -D warnings`, and `cargo fmt --check` on `nightly-2025-04-03`.
The three unit tests that come with the fix cover a bytecode of two
frames followed by a
skippable frame: all frames are decompressed, all frames count towards
the size limit, and
trailing garbage is an error rather than a hang.
## Release Plan
- These changes should be backported to the latest `testnet` branch,
then
- be released in a new SDK.
## Links
- #6820
- #2710
- [reviewer
checklist](https://github.com/linera-io/linera-protocol/blob/main/CONTRIBUTING.md#reviewer-checklist)
🤖 Generated with [Claude Code](https://claude.com/claude-code)
1 parent c0db6d1 commit ae4984e
2 files changed
Lines changed: 132 additions & 24 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
114 | 114 | | |
115 | 115 | | |
116 | 116 | | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
117 | 122 | | |
118 | 123 | | |
119 | 124 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1542 | 1542 | | |
1543 | 1543 | | |
1544 | 1544 | | |
| 1545 | + | |
| 1546 | + | |
| 1547 | + | |
| 1548 | + | |
| 1549 | + | |
| 1550 | + | |
| 1551 | + | |
| 1552 | + | |
| 1553 | + | |
| 1554 | + | |
| 1555 | + | |
| 1556 | + | |
| 1557 | + | |
| 1558 | + | |
| 1559 | + | |
| 1560 | + | |
| 1561 | + | |
| 1562 | + | |
| 1563 | + | |
| 1564 | + | |
| 1565 | + | |
| 1566 | + | |
| 1567 | + | |
| 1568 | + | |
| 1569 | + | |
| 1570 | + | |
| 1571 | + | |
| 1572 | + | |
| 1573 | + | |
| 1574 | + | |
| 1575 | + | |
| 1576 | + | |
| 1577 | + | |
| 1578 | + | |
1545 | 1579 | | |
1546 | 1580 | | |
1547 | 1581 | | |
1548 | 1582 | | |
1549 | 1583 | | |
1550 | 1584 | | |
1551 | 1585 | | |
1552 | | - | |
1553 | 1586 | | |
1554 | 1587 | | |
1555 | | - | |
1556 | 1588 | | |
1557 | | - | |
1558 | | - | |
1559 | | - | |
| 1589 | + | |
| 1590 | + | |
1560 | 1591 | | |
1561 | 1592 | | |
1562 | 1593 | | |
| |||
1566 | 1597 | | |
1567 | 1598 | | |
1568 | 1599 | | |
1569 | | - | |
1570 | | - | |
1571 | | - | |
1572 | | - | |
1573 | | - | |
1574 | | - | |
1575 | 1600 | | |
1576 | | - | |
1577 | | - | |
1578 | | - | |
1579 | | - | |
1580 | | - | |
1581 | | - | |
1582 | | - | |
1583 | | - | |
1584 | | - | |
1585 | | - | |
1586 | | - | |
1587 | | - | |
1588 | | - | |
| 1601 | + | |
1589 | 1602 | | |
1590 | 1603 | | |
1591 | 1604 | | |
| |||
2220 | 2233 | | |
2221 | 2234 | | |
2222 | 2235 | | |
| 2236 | + | |
| 2237 | + | |
| 2238 | + | |
| 2239 | + | |
| 2240 | + | |
| 2241 | + | |
| 2242 | + | |
| 2243 | + | |
| 2244 | + | |
| 2245 | + | |
| 2246 | + | |
| 2247 | + | |
| 2248 | + | |
| 2249 | + | |
| 2250 | + | |
| 2251 | + | |
| 2252 | + | |
| 2253 | + | |
| 2254 | + | |
| 2255 | + | |
| 2256 | + | |
| 2257 | + | |
| 2258 | + | |
| 2259 | + | |
| 2260 | + | |
| 2261 | + | |
| 2262 | + | |
| 2263 | + | |
| 2264 | + | |
| 2265 | + | |
| 2266 | + | |
| 2267 | + | |
| 2268 | + | |
| 2269 | + | |
| 2270 | + | |
| 2271 | + | |
| 2272 | + | |
| 2273 | + | |
| 2274 | + | |
| 2275 | + | |
| 2276 | + | |
| 2277 | + | |
| 2278 | + | |
| 2279 | + | |
| 2280 | + | |
| 2281 | + | |
| 2282 | + | |
| 2283 | + | |
| 2284 | + | |
| 2285 | + | |
| 2286 | + | |
| 2287 | + | |
| 2288 | + | |
| 2289 | + | |
| 2290 | + | |
| 2291 | + | |
| 2292 | + | |
| 2293 | + | |
| 2294 | + | |
| 2295 | + | |
| 2296 | + | |
| 2297 | + | |
| 2298 | + | |
| 2299 | + | |
| 2300 | + | |
| 2301 | + | |
| 2302 | + | |
| 2303 | + | |
| 2304 | + | |
| 2305 | + | |
| 2306 | + | |
| 2307 | + | |
| 2308 | + | |
| 2309 | + | |
| 2310 | + | |
| 2311 | + | |
| 2312 | + | |
| 2313 | + | |
| 2314 | + | |
| 2315 | + | |
| 2316 | + | |
| 2317 | + | |
| 2318 | + | |
| 2319 | + | |
| 2320 | + | |
| 2321 | + | |
| 2322 | + | |
| 2323 | + | |
| 2324 | + | |
| 2325 | + | |
2223 | 2326 | | |
0 commit comments