Skip to content

Check node ID matching in addNodeObject - #620

Merged
vishalchangrani merged 2 commits into
masterfrom
bastian/port-add-node-object-nodeid-check
Nov 19, 2026
Merged

vishalchangrani merged 2 commits into
masterfrom
bastian/port-add-node-object-nodeid-check

Conversation

@turbolent

Copy link
Copy Markdown
Member

Validate in FlowStakingCollection.StakingCollection.addNodeObject that the nodeID of the provided MachineAccountInfo matches the ID of the node being added, so a node can no longer be associated with a machine account record that belongs to a different node.

This ports the fix already deployed via onflow/flow-core-contracts-internal#5 (authored by Leo Zhang). Apart from import addresses and whitespace, FlowStakingCollection.cdc on this branch is identical to the contract currently deployed on Mainnet and Testnet.

Changes

  • Assert info.nodeID == node.id in addNodeObject when a MachineAccountInfo is provided
  • Regenerate lib/go/contracts/internal/assets/assets.go
  • Add TestAddNodeObjectRejectsMismatchedMachineAccountInfo (verified to fail against the pre-fix contract) and TestAddNodeObjectAcceptsMatchingMachineAccountInfo (node transfer via transfer_node.cdc with a matching record still works)

Testing

  • go test ./... in lib/go/test and lib/go/contracts pass

Related: onflow/flow-core-contracts-internal#5

Validate that the nodeID of the MachineAccountInfo passed to
addNodeObject matches the ID of the node being added.

This ports the fix already deployed via
onflow/flow-core-contracts-internal#5.

@vishalchangrani vishalchangrani left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Review

Verdict: matches mainnet, small/surgical, well-tested.

What it changes

  • contracts/FlowStakingCollection.cdc — adds an 11-line guard inside addNodeObject asserting machineAccountInfo.nodeID == node.id.
  • lib/go/contracts/internal/assets/assets.go — regenerated blob (62.869kB → 63.54kB), consistent with the 11-line Cadence addition.
  • lib/go/test/flow_stakingcollection_security_test.go — new file, two tests:
    • TestAddNodeObjectRejectsMismatchedMachineAccountInfo — negative: account2's node + account1's MachineAccountInfo must be rejected.
    • TestAddNodeObjectAcceptsMatchingMachineAccountInfo — positive: uses transfer_node.cdc, confirms the receiver can withdraw from the machine account after transfer.

Does the branch match mainnet?

Yes. I fetched the live mainnet contract at 0x8d0e87b65159ae63 (per flow.json) via the access-node REST API and diffed it against this PR's head (beba069c):

  • Mainnet already contains the exact assert(info.nodeID == id, …) block with an identical error message — the internal hotfix (onflow/flow-core-contracts-internal#5) is already live on Mainnet.
  • After stripping (a) imports — the PR uses import \"FungibleToken\" resolved via flow.json aliases, Mainnet has concrete from 0x… addresses — and (b) trailing whitespace, the files are identical except for one trailing blank line at EOF on Mainnet. No semantic drift.

So the public repo was lagging Mainnet; this PR closes that gap. The PR body's claim ("apart from import addresses and whitespace, identical to Mainnet and Testnet") is accurate.

Nits (non-blocking)

  • assets.go is auto-generated; size delta matches, so make generate was run correctly.
  • The negative test uses shouldFail=true, which only checks that the tx errored — not that it errored for this reason. Tightening it to assert the error message contains \"does not match the node's ID\" would make the test future-proof against unrelated regressions that also happen to fail the tx. Not a blocker since this is the only assert added in addNodeObject.

@vishalchangrani
vishalchangrani merged commit 0b11036 into master Nov 19, 2026
2 checks passed
@vishalchangrani
vishalchangrani deleted the bastian/port-add-node-object-nodeid-check branch November 19, 2026 21:47
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.

3 participants