CBOR: preservation-aware encode reuses stale chunk sizes, writing different content
Maintainer thường phản hồi trong vòng 1 ngày
Chưa có ai nhận issue này.
- #634 của @Kshot3000 — đã đóng, không merge
Đánh giá
- Độ khó
- 3/5
- Thời gian dự kiến
- 1-2 ngày
- Mức phù hợp với người mới
- 76/100
- Loại issue
- Lỗi
- Độ rõ ràng
- Đặc tả rõ ràng
- Mức độ hoạt động
- Sôi nổi
- Công nghệ
- typescript
Hướng nghiên cứu
Start in packages/evolution/src/CBOR.ts at the indefinite branches of encodeBytesSync and text-string encoding, then read .specs/cbor-encoding-preservation.md and the referenced Transaction.ts comment. Add regression coverage for changed byte and text values, including UTF-8 boundaries, while preserving byte-identical output for unchanged values. Done means each encoded value decodes to the value supplied and the tests fail on the current implementation but pass after the fix.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Summary
When a byte or text string was decoded as indefinite-length chunks, the captured format keeps the chunk sizes. If the value then changes and is encoded with that format, the encoder writes the old chunk sizes over the new value. The output is valid CBOR carrying different content, and no error is raised:
const { format } = CBOR.fromCBORHexWithFormat("5f4201024103ff") // h'010203' as chunks 2 + 1
CBOR.toCBORHexWithFormat(new Uint8Array([0xaa]), format)
// 5f42aa004100ff, decodes as h'aa0000' (zero padded)
CBOR.toCBORHexWithFormat(new Uint8Array([1, 2, 3, 4, 5]), format)
// 5f4201024103ff, decodes as h'010203' (tail dropped)
Text strings behave the same way: "x" under the format of "hij" decodes as "x\0\0", and a change can split a UTF-8 character, which gives undecodable output.
This breaks the preservation spec, .specs/cbor-encoding-preservation.md:
- L243: only a compatible format branch may be reused
- L244: preserved widths that no longer fit must fall back
Integer widths already follow L244 and strings do not. The comment at Transaction.ts L242 also says reconciliation "handles structural changes gracefully".
Affected
packages/evolution/src/CBOR.ts
encodeBytesSyncindefinite branch (L1156-1176): chunk lengths come fromstringEncoding.chunks, never from the value, and the zero-filled buffer is sized from them- text string indefinite branch (L1247-1265): same pattern
Reachable through CBOR.toCBORHexWithFormat and every *WithFormat encoder built on it, such as Transaction.toCBORHexWithFormat. The automatic cache path (toCBORHex after fromCBORHex, addVKeyWitnesses) does not change existing strings, so it does not reach this.
Fix
Reuse a captured chunk layout only when it still fits the value:
- bytes: the chunk sizes add up to the value's length
- text: the same, and every chunk ends on a UTF-8 character boundary
Otherwise fall back to the default encoding for that string, as integers already do. The definite branch keeps its header width, since encodeIntHeader already falls back when the length does not fit.
Regression test
- given: format captured from
5f4201024103ff - before fix: encoding h'aa' gives
5f42aa004100ff, and h'0102030405' gives5f4201024103ff - after fix: both decode back to the value that was encoded
- text:
"x","hijk"and"héllo"under the format of7f626869616affdecode back to themselves - control: an unchanged value under its own format stays byte-identical
Devnet, raw submission through Ogmios, using the documented edit flow:
- decode a transaction whose metadata is
{0: h'010203'}in chunks, withTransaction.fromCBORHexWithFormat - set the metadata to h'aa' and the body's auxiliary data hash to
AuxiliaryData.toHashof the new metadata - encode with
Transaction.toCBORHexWithFormatand the original format
The SDK writes the auxiliary data as a1005f42aa004100ff. The node rejects it with 3107, metadata hash mismatch: provided df360c50… (the SDK's hash of h'aa'), computed 9c397db0… (the hash of the bytes written, which hold h'aa0000'). The original transaction is accepted.
Must FAIL on main today and PASS after the fix.
Reference
Blocks the fix for #576 (Plutus data encodings), which will pass the captured format into the bounded bytes encoder.
- Ngôn ngữ chính
- TypeScript
- Star
- 22
- Fork
- 34
- Merge trung bình
- 16 giờ 53 phút
- Pull request đã merge (30 ngày)
- 10
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Không có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của IntersectMBO/evolution-sdk
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
IntersectMBO/evolution-sdk#696 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 79/100
IntersectMBO/evolution-sdk#694 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 84/100
IntersectMBO/evolution-sdk#559 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
enhancement
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
IntersectMBO/evolution-sdk#557 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
RewardAccount: validate header type bits and bech32 prefixCó thể làm lại được Pull request cho issue này đã bị đóng mà không được merge. Đang mởenhancement external-review
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 84/100
IntersectMBO/evolution-sdk#456 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của IntersectMBO/evolution-sdk
Issue tương tự
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
Maintainer thường phản hồi trong vòng 1 ngày
-
triage: failed
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
oxc-project/tsrs#1277 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
ardia-browser/ardia#6798 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
triage
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 83/100
novuhq/novu#13613 · 2 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
enhancement from-app needs-triage
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
nightly-labs/openbot#23943 ·
Maintainer thường phản hồi trong vòng 1 ngày