Repository navigation
feat(https_outcalls): only accept canonically encoded canister HTTP payloads - #11751
Merged
Merged
Conversation
Contributor
There was a problem hiding this comment.
Copilot review overview
🟢 Approval recommended
The validation is narrowly scoped, dependency metadata is consistent, and canonical and malformed encodings are adequately tested.
Review effort: Balanced
Findings: None
What changed in this PR
Ensures canister HTTP consensus payloads use the exact canonical Prost encoding required for stable block hashes.
Changes:
- Re-encodes decoded messages to detect non-canonical payload bytes.
- Applies canonical decoding during payload validation.
- Adds unit/integration coverage and Prost dependencies.
| File | Description |
|---|---|
rs/https_outcalls/consensus/src/payload_builder/parse.rs |
Implements canonical decoding and tests. |
rs/https_outcalls/consensus/src/payload_builder.rs |
Enforces canonical encoding during validation. |
rs/https_outcalls/consensus/src/payload_builder/tests.rs |
Tests end-to-end rejection. |
rs/https_outcalls/consensus/Cargo.toml |
Adds Prost dependency. |
rs/https_outcalls/consensus/BUILD.bazel |
Adds matching Bazel dependency. |
Cargo.lock |
Records the dependency update. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
eichhorl
commented
Oct 5, 2026
|
✅ No security or compliance issues detected. Reviewed everything up to 4728c2c. Security Overview
Detected Code Changes
|
eichhorl
added a commit
that referenced
this pull request
Oct 5, 2026
A receiver puts a stripped payload back together by encoding what it decodes, which reproduces the bytes that the block hash covers only if they are prost's own encoding of the payload's messages. Stripping a payload that prost decodes but would encode differently, e.g. one with an unknown field, would hand every peer a block that it has to reject. #11751 makes payload validation reject such payloads, so every block that an honest node strips is canonically encoded; the docs now state that stripping relies on this. The threshold applies to exactly the quantity that a response's metadata reports as its `content_size`: a reject's code counts one byte, as in `CanisterHttpReject::count_bytes`, rather than four. Declaring a stripped response costs 36 bytes, not 34, and the feature flag's doc names the threshold. The benchmark case of 500 one-byte responses measured a block with nothing worth stripping; it now uses the smallest response that is stripped. Every case asserts that the block declares as many responses as it has worth stripping, and that assembling it succeeds. New tests cover the identical responses of a flexible outcall, which are declared and fetched once, rejects on either side of the threshold, and the content size the threshold applies to. The canister HTTP round trips through the assembler compare the whole block, and the size test checks the exact cost of each declaration. The payload fixture with one of every kind of message moved to the test utilities, so that these tests share it. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
pierugo-dfinity
approved these changes
Oct 5, 2026
github-merge-queue
Bot
removed this pull request from the merge queue due to failed status checks
Oct 5, 2026
github-merge-queue
Bot
removed this pull request from the merge queue due to failed status checks
Oct 5, 2026
AleDema
pushed a commit
to AleDema/ic
that referenced
this pull request
Oct 18, 2026
…y#11719) **This is the PR that turns hashes in blocks on for canister HTTP responses.** A block proposal now goes out without the contents of the responses it delivers, naming them by the content hash it already carries alongside each of them. Receivers have been able to serve (dfinity#11717) and reassemble (dfinity#11718) those contents since the previous two PRs, so this is where the bandwidth saving starts. An outcall response can be up to 2 MB and the block used to carry it to every peer, on top of the copy the replicas already gossip to each other. A payload with nothing to strip is left untouched byte for byte, so a block without an outcall response never pays for being re-encoded. Declaring a stripped content costs 36 bytes in the stripped proposal, its 32-byte hash plus framing, and only contents of at least 64 bytes are stripped, each of which saves at least 70 bytes for every slot it is taken out of. So **stripping a response never makes the proposal that goes out bigger** than the stripped proposal that every data block already goes out as. Break-even is at about 30 bytes of content, and the threshold deliberately stays close to it: the declared hash and the content it replaces both go to every peer, so the comparison is the same whatever the subnet size, and with up to 500 responses per block each byte of slack is multiplied by five hundred — at a 1 KiB threshold a block could have carried half a megabyte of unstripped content to every peer. It also keeps the replica's own terse rejects in the block, which save little or nothing when stripped. A response is stripped whatever kind of outcall it answers, because in each case the replicas that signed for it are already holding its content — see the module docs of `canister_http.rs`. The assembler benchmark gains the canister HTTP dimension, parameterized by the number of signatures a response carries, since that is what dominates the cost of stripping and reassembling. At the 500-response cap with a 40-node quorum, stripping a block costs **5.4 ms** and reassembling one **9.8 ms**. That case uses 1 KiB responses and the 10-byte node ids of the test utilities; with real, 29-byte node ids, 500 responses with 27 signatures each only fit into the 2 MiB payload limit with bodies of about 800 bytes, but the signatures that dominate the cost stay the same. > Earlier revisions of this description quoted 3.4 ms and 6.4 ms for those cases. Two > benchmark cases exceeded `MAX_CANISTER_HTTP_PAYLOAD_SIZE`, and `iterator_to_bytes` > silently drops what does not fit, so they measured roughly 300 responses under a label > claiming 500. The cases are now sized to fit and `fake_canister_http_payload` panics > rather than let that happen again. ### Worth a reviewer's attention For a fully replicated outcall, a node whose own adapter has not produced the response yet when the block arrives used to get the bytes in the block and now does a round trip for them. It is bounded — at least `n - f` peers hold the content, and it is no worse on bandwidth — but it is a new dependency of block assembly on a peer fetch in the common outcall mode, not just the non-replicated one. A receiver puts the payload back together by encoding what it decodes, which only reproduces the bytes the block hash covers because payload validation accepts nothing but canonically encoded canister HTTP payloads (dfinity#11751). ### Stack 1. dfinity#11716 — protobuf definitions (merged) 2. dfinity#11717 — serve canister HTTP responses out of a block (merged) 3. dfinity#11718 — reassemble blocks whose canister HTTP responses were stripped (merged) 4. **this PR — strip canister HTTP responses from block proposals** 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Co-authored-by: Claude Opus 5 (1M context) <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This makes canonical encoding a validity rule of the canister HTTP payload:
validate_payloadnow rejects a payload unless it is byte for byte what prost encodes its messages to.Why
The block hash covers the raw bytes of the canister HTTP payload. This becomes a problem once nodes re-encode payloads they did not build. The upcoming hashes-in-blocks for canister HTTP responses does exactly that: a relay strips the response contents from a block, and the receiver puts them back and re-encodes. With a non-canonical payload, every honest relay would hand out a copy that no peer can validate.
How
parse::canonical_bytes_to_payloaddecodes the payload one length-delimited message at a time, re-encodes each message into a reused buffer and compares it with the bytes it was decoded from.validate_payloaduses it after the size check and before any state lookup or signature verification. Batch delivery (into_messages) keeps the lenientbytes_to_payload, since it only ever sees validated payloads.Cost
Testing
🤖 Generated with Claude Code