Skip to content

Conversation

@entuziaz
Copy link
Contributor

@entuziaz entuziaz commented Nov 13, 2025

Fixes #38. Prevents zero pricePerTiBPerEpoch in capacity and storage calculations.

  • Introduced assertPriceNonZero() in core/utils/validate-pricing.ts
  • Integrated into calculateActualCapacity() and calculateStorageFromUSDFC()
  • Updated tests to expect throws on zero pricing
  • Prevents Infinity / unsafe deposit calculations

Changes

  • Added core/utils/validate-pricing.ts with assertPriceNonZero()
  • Integrated guard into:
    • calculateActualCapacity()
    • calculateStorageFromUSDFC()
  • Updated unit tests to expect errors instead of silent 0-capacity returns.

Check this out @SgtPooki.

Copy link
Collaborator

@SgtPooki SgtPooki left a comment

Choose a reason for hiding this comment

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

Lgtm but needs a rebase?

… and storage calculations

- Introduced assertPriceNonZero() in core/utils/validate-pricing.ts
- Integrated into calculateActualCapacity() and calculateStorageFromUSDFC()
- Updated tests to expect throws on zero pricing
- Prevents Infinity / unsafe deposit calculations
@entuziaz entuziaz force-pushed the fix/validate-zero-pricing-guard branch from 375c8ce to 1aa4132 Compare November 13, 2025 15:55
@entuziaz
Copy link
Contributor Author

Lgtm but needs a rebase?

Aye aye, sir!
Done, @SgtPooki.

@SgtPooki SgtPooki requested a review from Copilot November 13, 2025 20:56
Copilot finished reviewing on behalf of SgtPooki November 13, 2025 20:58
Copy link
Contributor

Copilot AI left a comment

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 addresses issue #38 by adding input validation to prevent zero pricing values from causing division-by-zero errors or producing unsafe capacity calculations. The solution introduces a shared validation guard function that is integrated into capacity calculation functions.

Key changes:

  • Added assertPriceNonZero() validation utility that throws on zero or negative pricing
  • Replaced silent zero-price handling with explicit error throwing in calculateActualCapacity() and calculateStorageFromUSDFC()
  • Updated tests to verify error throwing behavior instead of expecting silent zero returns

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
src/core/utils/validate-pricing.ts New validation utility module with assertPriceNonZero() function
src/core/payments/index.ts Integrated validation guard into two capacity calculation functions, removing previous zero-price checks
src/test/unit/payments-setup.test.ts Added tests for validation function and updated existing tests to expect thrown errors

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@SgtPooki
Copy link
Collaborator

@entuziaz looks like you need to run npm run lint:fix on your code, see https://github.com/filecoin-project/filecoin-pin/actions/runs/19337489097/job/55344993018?pr=237

@entuziaz
Copy link
Contributor Author

@entuziaz looks like you need to run npm run lint:fix on your code, see https://github.com/filecoin-project/filecoin-pin/actions/runs/19337489097/job/55344993018?pr=237

Done, @SgtPooki

@BigLep BigLep added team/fs-wg FOC working group is a stakeholder for this work, and thus wants to track it on their project board. team/filecoin-pin "Filecoin Pin" project is a stakeholder for this work. labels Nov 15, 2025
@FilOzzy FilOzzy added this to FS Nov 15, 2025
@github-project-automation github-project-automation bot moved this to 📌 Triage in FS Nov 15, 2025
@BigLep BigLep requested a review from SgtPooki November 15, 2025 14:27
@BigLep BigLep moved this from 📌 Triage to 🔎 Awaiting review in FS Nov 15, 2025
@github-project-automation github-project-automation bot moved this from 🔎 Awaiting review to ✔️ Approved by reviewer in FS Nov 18, 2025
@SgtPooki SgtPooki merged commit 7e87f4c into filecoin-project:master Nov 18, 2025
8 checks passed
@github-project-automation github-project-automation bot moved this from ✔️ Approved by reviewer to 🎉 Done in FS Nov 18, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

team/filecoin-pin "Filecoin Pin" project is a stakeholder for this work. team/fs-wg FOC working group is a stakeholder for this work, and thus wants to track it on their project board.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug: calculateStorageFromUSDFC allows 0 pricePerTib

3 participants