Skip to content

fix: validate deal data before publishing(GSI-737) - #2143

Open
snail8501 wants to merge 1 commit into
mainfrom
fix/validate-deal-data-before-publish
Open

snail8501 wants to merge 1 commit into
mainfrom
fix/validate-deal-data-before-publish

Conversation

@snail8501

Copy link
Copy Markdown
Contributor

Summary

A client could cause an honest provider's deal collateral to be burned by
submitting a CAR file that Boost accepts before publishing but rejects
afterwards.

Boost checked downloaded data with carv2.ReadVersion before publishing
(storagemarket/deal_commp.go), which reads only the 11-byte CARv2 pragma,
while addPiece uses the strict carv2.OpenReader, which also validates
the 40-byte CARv2 header. A file with a valid pragma and a zeroed header
passes CommP verification (the client can compute the matching PieceCID),
the deal is published and the provider collateral locked, and only then
does addPiece fail. That failure is classified as fatal, the inbound file
is deleted, and retry is refused. The published deal is never activated,
so SettleDealPayments at StartEpoch slashes 100% of the provider
collateral.

The same pre-publication gate also missed the size constraint enforced by
padreader.NewInflator: a file larger than PieceSize.Unpadded() passes
CommP verification (the padding branch is skipped) but fails fatally when
the piece is handed to the sealer.

Changes

  • Add validatePieceData, mirroring the constraints in openReader:
    non-empty file, size <= PieceSize.Unpadded(), strict carv2.OpenReader.
  • Run it in verifyCommP, so bad data is rejected before CommP is computed.
  • Run it again immediately before publishing, covering deals resumed at the
    Transferred checkpoint where verifyCommP is not re-run.
  • Retry classification: fatal for online deals, manual for offline deals
    (the provider can supply the correct file).

Compatibility

  • Valid CARv1 and CARv2 files are unaffected. carv2.OpenReader behaves the
    same as carv2.ReadVersion for CARv1 and additionally validates the CARv2
    header for CARv2.
  • Raw (non-CAR) files were already rejected by ReadVersion, so no support
    is lost.
  • The new check is a strict subset of the post-publication openReader
    check, so a file that could previously be sealed successfully cannot be
    rejected.
  • No client or protocol changes are required.
  • GenerateCommPLocally is untouched, so boostx commp behaviour is
    unchanged. DDO import paths are unaffected.

Testing

  • New TestValidatePieceData: valid CARv2, valid CARv1, oversized file,
    empty file, and a CARv2 with a valid pragma and a zeroed header (with an
    assertion that the old ReadVersion check accepts it).
  • Existing offline, online, resumption, and error-path tests pass:
    TestSimpleOfflineDealHappy, TestOfflineDealDataCleanup,
    TestSimpleDealHappy, TestDealCompletionOnProcessResumption,
    TestSingleDealResumptionDisconnect,
    TestDealFailuresHandlingNonRecoverableErrors, TestDealVerification,
    TestDealRestartAfterManualRecoverableErrors,
    TestOfflineDealRestartAfterManualRecoverableErrors.
  • go build ./storagemarket/..., go vet ./storagemarket/, gofmt clean.

Boost validated a downloaded CAR file with carv2.ReadVersion before
publishing a deal (which reads only the 11-byte CARv2 pragma) but with the
strict carv2.OpenReader in addPiece afterwards. A client could therefore
submit a file with a valid CARv2 pragma and an invalid (zeroed) 40-byte
header, pass CommP verification, and have the deal published with the
provider collateral locked. addPiece then failed fatally, Boost deleted
the inbound file and refused retry, leaving the deal published but never
activated; once SettleDealPayments was called at StartEpoch, the provider
collateral was slashed in full.

The pre-publication gate also did not check that the file fits in the
declared piece size, which is another post-publication fatal failure in
padreader.NewInflator: a file larger than PieceSize.Unpadded() passes
CommP verification (the padding branch is skipped) but fails when the
piece is handed to the sealer.

Add validatePieceData, which mirrors the constraints in openReader
(size > 0, size <= PieceSize.Unpadded(), strict carv2.OpenReader), and
run it in verifyCommP and again immediately before publishing. The extra
check before publishing also covers deals resumed at the Transferred
checkpoint, where verifyCommP is not re-run.

Online deals fail fatally; offline deals fail with a manual retry so the
provider can supply the correct file.
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