Skip to content

chore: align contract error codes for amount/fee validation (400-404)#655

Open
69starman wants to merge 1 commit into
MentoNest:mainfrom
69starman:Starlinks
Open

chore: align contract error codes for amount/fee validation (400-404)#655
69starman wants to merge 1 commit into
MentoNest:mainfrom
69starman:Starlinks

Conversation

@69starman
Copy link
Copy Markdown
Contributor

Closes #559

  1. The Core Fix (Solidity Smart Contract)
    Add this comprehensive validation block to your financial or escrow contract. It uses custom errors for gas efficiency while fulfilling all acceptance criteria:

Solidity
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;

contract DripsFinancialValidator {
// Custom error definitions matching acceptance criteria codes
error InvalidAmount(); // 400
error InsufficientBalance(); // 401
error FeeTooHigh(); // 402
error InvalidSplit(); // 403
error OverflowDetected(); // 404

/// @notice Validates financial metrics for drips, splits, and fees
/// @param amount The transaction amount (signed to check for negative values)
/// @param balance The available buyer balance
/// @param fee The fee in basis points (bps)
/// @param disputeSplit The total sum of the split distribution
function validateTransaction(
    int256 amount, 
    uint256 balance, 
    uint256 fee, 
    uint256 disputeSplit
) external pure {
    // 400: Amount is zero or negative
    if (amount <= 0) revert InvalidAmount();
    
    uint256 unsignedAmount = uint256(amount);

    // 401: Buyer has insufficient funds
    if (balance < unsignedAmount) revert InsufficientBalance();

    // 402: Fee exceeds maximum (1000 bps = 10%)
    if (fee > 1000) revert FeeTooHigh();

    // 403: Dispute split does not sum to amount
    if (disputeSplit != unsignedAmount) revert InvalidSplit();

    // 404: Explicit arithmetic overflow check 
    // Note: Solidity 0.8+ reverts automatically, but this ensures explicit tracking
    unchecked {
        if (balance + unsignedAmount < balance) {
            revert OverflowDetected();
        }
    }
}

}

@drips-wave
Copy link
Copy Markdown

drips-wave Bot commented May 31, 2026

@69starman Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

@nafiuishaaq
Copy link
Copy Markdown
Contributor

Please resolve conflict @69starman

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.

Financial validation errors

2 participants