Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remediation of Issues from Filecoin Solidity Audit by Zellic #66

Merged
merged 8 commits into from
Feb 7, 2025

Conversation

snissn
Copy link
Collaborator

@snissn snissn commented Jan 13, 2025

PR: Remediation of Issues from Filecoin Solidity Audit by Zellic

Overview

This PR implements fixes and improvements based on the security assessment conducted by Zellic for the Filecoin Solidity project. The audit identified seven issues, categorized as one medium, two low, and four informational. All findings have been remediated as detailed in the audit report.

Summary of Changes

The following changes were made to address the audit findings:

  1. Replaced assert with if checks + revert using custom errors

    • Eliminates Panic exceptions and ensures proper error messaging.
    • Introduces specific custom errors in Errors.sol:
      • InvalidArrayLength(uint256 expected, uint256 actual)
      • InvalidBooleanType()
      • ExpectedMajorByteString()
      • ExpectedNegativeBigNumTag()
      • ExpectedLowValue27()
    • Fixes Finding: Throwing Panic is not recommended
      Commit 72285939
  2. Standardized BigInt deserialization with deserializeBytesBigInt

    • Replaced inconsistent uses of deserializeBigInt with deserializeBytesBigInt across CBOR contracts.
    • Ensured uniform handling of optional BigInt values.
    • Fixes Finding: Discrepancy between BytesBigInt and BigInt is confusing
      Commit 09f2f205
      Commit ff0b3868
  3. Fixed buffer allocation type mismatch in serializeChangeWorkerAddressParams

    • Changed buffer size calculations from uint256 to uint64 to prevent truncation issues.
    • Fixes Finding: Buffer allocation type mismatch
      Commit acf7e81e
  4. Fixed capacity miscalculation in serializeExtendClaimTermsParams

    • Addressed incorrect CBOR buffer allocation to prevent unnecessary resizing and improve gas efficiency.
    • Fixes Finding: Incorrect CBOR buffer capacity
      Commit 14d60cec
  5. Enforced strict array length checks in deserialization

    • Updated deserializeGetDealDataCommitmentReturn to enforce expected array length instead of silently discarding extra entries.
    • Fixes Finding: Extra entries in DealDataCommitmentReturn are silently discarded
      Commit 1eabac47
  6. Added validation for BigInt sign byte in deserialization

    • Now rejects invalid sign bytes (only 0x00 or 0x01 allowed).
    • Fixes Finding: The BigInt sign serialization
      Commit 9bf88179
  7. Fixed type mismatch in universal receiver params struct

    • Ensured consistent deserialization and serialization of UniversalReceiverParams.type_ as uint32.
    • Fixes Finding: Type mismatch in the universal receiver params struct
      Commit d6bc37bc

Audit Summary

Impact

These changes improve the robustness and security of the Filecoin Solidity library by:

  • Enhancing error handling with custom error messages.
  • Ensuring correct buffer allocations to prevent potential memory issues.
  • Improving consistency in BigInt serialization and deserialization.
  • Eliminating silent failures in CBOR decoding.

….sol

Switched back to using deserializeBigInt for balance, locked, storage_price_per_epoch,
provider_collateral, and client_collateral fields to fix deserialization issues
and pass all tests.
- Replaced uint256 with uint64 for consistent buffer allocation in capacity calculation and initialization.
- Added safety check to prevent array length overflow beyond uint64 limits.
- Ensured proper serialization of new_control_addresses without potential truncation.

Addresses buffer allocation type mismatch warning.
- Replaced all `assert` statements with `if` checks followed by `revert` and custom errors from `Errors.sol`
- Implemented specific custom errors:
  - `InvalidArrayLength(uint256 expected, uint256 actual)`
  - `InvalidBooleanType()`
  - `ExpectedMajorByteString()`
  - `ExpectedNegativeBigNumTag()`
  - `ExpectedLowValue27()`
- Ensured proper import of `Errors.sol` across relevant CBOR modules
- Preserved original indentation and code formatting for readability
- Improves error handling consistency and prevents `Panic` exceptions

This change aligns with Solidity best practices by using custom errors for more efficient and descriptive error handling.
@snissn snissn changed the title Zellic remediation Remediation of Issues from Filecoin Solidity Audit by Zellic Feb 6, 2025
@snissn snissn marked this pull request as ready for review February 6, 2025 20:46
@snissn snissn requested a review from trruckerfling February 6, 2025 20:47
@snissn snissn self-assigned this Feb 6, 2025
@trruckerfling trruckerfling merged commit c72ec4b into master Feb 7, 2025
3 checks passed
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.

2 participants