Skip to content

fix: reject undefined DealDataRoot in deal proposals (GSI-743) - #2142

Open
snail8501 wants to merge 1 commit into
mainfrom
fix/undefined-deal-data-root
Open

snail8501 wants to merge 1 commit into
mainfrom
fix/undefined-deal-data-root

Conversation

@snail8501

Copy link
Copy Markdown
Contributor

Summary

A deal client could omit the DealDataRoot key from the DealParams CBOR map. The field is outside the signed ClientDealProposal.Proposal and CBOR decoding tolerates its absence, so the proposal passed validation and was written to the deals DB. The DB layer serialized cid.Undef as the string "b", which cannot be parsed back, and a single such row makes every subsequent Provider.Start() fail in ListActive / ListCompleted — i.e. one accepted deal permanently prevents boostd from starting until the row is removed manually.

Root cause

  • DealParams.UnmarshalCBOR zero-initializes the struct and only assigns keys that are present (generated code).
  • validateDealProposal guarded proposal.PieceCID.Defined() but had no equivalent check for DealDataRoot.
  • CidFieldDef.Marshall only checked for a nil pointer and otherwise called String(); cid.Undef.String() is "b", and cid.Parse("b") returns cid too short.

Because DealDataRoot is unused by the transfer / commP / publish path, the bad value is not noticed until the row is read back.

Changes

  • storagemarket/deal_acceptance.go: reject an undefined DealDataRoot before signature verification, mirroring the existing PieceCID check. This is the single acceptance path for libp2p deals (v1.2.0 and v1.2.1), offline deal proposals, contract-monitor deals and BoostDummyDeal.
  • db/fielddef/fielddef.go: CidFieldDef / CidPtrFieldDef now return an error instead of marshalling an undefined CID. A value that cannot be read back is never written.

Tests

  • TestDealVerification/"deal data root undefined" — proposal is rejected with deal data root undefined.
  • TestDealsDBRejectsUndefinedCID — inserting a deal with cid.Undef fails with cannot marshal undefined cid and leaves the table untouched.
go test ./db/... -count=1
go test ./storagemarket/ -count=1 -v -timeout 900s

Compatibility

  • No wire, schema or migration change. DealDataRoot has existed since the first boost commit and is required by protocol 1.2.0; a zero-valued CID cannot even be marshalled, so omission is the only way to produce Undef.
  • BoostDummyDeal (local admin API) now rejects hand-built params without a root.
  • Existing rows with DealDataRoot = 'b' are not repaired automatically — see below.

Upgrade note for affected nodes

A boostd that already has a poisoned row still fails to start after upgrading. Stop it and remove the row:

SELECT ID, CreatedAt, Checkpoint, ChainDealID FROM Deals WHERE DealDataRoot='b';
DELETE FROM Deals WHERE DealDataRoot='b';

If the row had already reached Published or later, the deal exists on chain; verify ChainDealID before deleting, since removing the row also removes boost's local tracking of it.

DealDataRoot is part of the unsigned DealParams, so it is not covered by
the client signature, and CBOR decoding leaves it at cid.Undef when the
key is omitted. validateDealProposal only checked PieceCID, so such a
proposal was accepted and persisted: CidFieldDef serialized cid.Undef as
the one-character string "b", which cid.Parse rejects, so every
subsequent Provider.Start() failed in ListActive/ListCompleted until the
row was deleted by hand.

- validateDealProposal: reject an undefined DealDataRoot next to the
  existing PieceCID guard, before signature verification.
- fielddef: make CidFieldDef and CidPtrFieldDef refuse to marshal an
  undefined CID, so a value that cannot be read back is never written.

Tests cover the acceptance rejection and the DB insert failure.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

1 participant