Skip to content

Add nil-element validation to flow data models - #8668

Open
zhangchiqing wants to merge 3 commits into
leo/fix-new-payload-nil-element-validationfrom
leo/fix-nil-element-validation
Open

Add nil-element validation to flow data models#8668
zhangchiqing wants to merge 3 commits into
leo/fix-new-payload-nil-element-validationfrom
leo/fix-nil-element-validation

Conversation

@zhangchiqing

@zhangchiqing zhangchiqing commented Aug 26, 2026

Copy link
Copy Markdown
Member

Add nil-element validation to more flow models: Hotstuff timeout, execution result, chunk data pack, block header, etc.


View with [code]smith Autofix with [code]smith
Need help on this PR? Tag @codesmith-bot with what you need. Autofix is disabled.

@coderabbitai

coderabbitai Bot commented Aug 26, 2026

Copy link
Copy Markdown
Contributor

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: a780ebb4-bbfb-4590-a7bc-81aa47d6bc5a

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@zhangchiqing
zhangchiqing marked this pull request as ready for review August 26, 2026 19:18
@zhangchiqing
zhangchiqing requested a review from a team as a code owner August 26, 2026 19:18
@zhangchiqing
zhangchiqing requested review from AlexHentschel and janezpodhostnik and a lite review from Copilot August 26, 2026 19:18

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR hardens Flow’s core data model constructors against malformed/untrusted inputs by adding validation that rejects nil elements (and nil nested pointers) inside otherwise non-nil container types. This reduces the risk of panics or inconsistent IDs when decoding network-provided payloads (e.g., CBOR null → Go nil).

Changes:

  • Add nil-element checks for nested lists (e.g., ExecutionResult.Chunks) during payload/result construction.
  • Validate nested pointer fields by reconstructing through constructors (e.g., HeaderBody.LastViewTC, HotStuff TimeoutObject.LastViewTC, ChunkDataPack.Collection).
  • Extend unit tests to cover the new rejection paths.

Reviewed changes

Copilot reviewed 11 out of 11 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
model/flow/payload.go Rejects nil chunk entries within non-nil execution results in payloads.
model/flow/payload_test.go Adds coverage for rejecting a payload containing a result with a nil chunk element.
model/flow/header.go Validates LastViewTC via NewTimeoutCertificate instead of accepting nested nil pointers.
model/flow/header_test.go Adds coverage for rejecting a header body with LastViewTC.NewestQC == nil.
model/flow/execution_result.go Rejects nil chunk elements in ExecutionResult.Chunks.
model/flow/execution_result_test.go Adds coverage for rejecting an execution result containing a nil chunk element.
model/flow/chunk.go Validates optional Collection via NewCollection to reject nil transaction elements.
model/flow/chunk_test.go Adds coverage for rejecting a chunk data pack whose collection contains a nil transaction.
model/flow/block_test.go Updates block malleability test to account for stricter header-body validation.
consensus/hotstuff/model/timeout.go Validates LastViewTC via flow.NewTimeoutCertificate and uses the validated TC for comparisons/return value.
consensus/hotstuff/model/timeout_test.go Adjusts/extends tests to align with stricter TC validity requirements and new nil-nested-pointer rejection.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread model/flow/block_test.go
Comment thread model/flow/block_test.go
Comment on lines 139 to 143
unittest.RequireEntityNonMalleable(
t,
unittest.FullBlockFixture(),
blockWithLastViewTC(),
unittest.WithFieldGenerator("HeaderBody.ParentView", func() uint64 {
return block.View - 1 // ParentView must stay below View, so set it to View-1

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated in commit 0f35865765: TestBlockMalleability now passes the same block instance into RequireEntityNonMalleable, so the ParentView generator is consistent with the entity under test.

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
@github-actions

Copy link
Copy Markdown
Contributor

Dependency Review

✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.

Scanned Files

None

@codecov-commenter

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

Co-authored-by: zhangchiqing <811374+zhangchiqing@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants