Liquid Staking

Stakelink
DeFiHardhatOracle
50,000 USDC
View results
Submission Details
Severity: high
Invalid

scripts/prod/1.0.0-metis-staking/4-add-stMETIS-rewards-pool.ts

Here’s an assessment of potential vulnerabilities and risks in the code you provided, focusing on Web3 security practices and contract interaction issues:


Potential Vulnerabilities & Risks

  1. Hardcoded Multisig Address

    • Risk: The address '0xB351EC0FEaF4B99FdFD36b484d9EC90D0422493D' is hardcoded, which may make the code inflexible and prone to misconfiguration or accidental misuse in other environments.

    • Mitigation: Consider fetching this address from a configuration file or environment variables.

  2. Lack of Input Validation on Transaction Data

    • Risk: The populateTransaction function can potentially return undefined or invalid transaction data, resulting in an empty data field (''). If this field is used incorrectly, it could trigger unexpected behaviors in the smart contract or lead to failed transactions.

    • Mitigation: Add a proper check for the populated transaction data to ensure it is valid before proceeding.

    const populatedTransaction = await sdlPool.addToken.populateTransaction(
    stakingPool.target,
    stMetisSDLRewardsPool.target
    );
    if (!populatedTransaction?.data) {
    throw new Error('Failed to generate transaction data.');
    }
  3. Blind Trust in External API Responses

    • Risk: You are using Safe’s API (SafeApiKit) to propose transactions, and the transaction data is submitted without verifying the response integrity. If the API is compromised, it could introduce malicious transactions or fake signatures.

    • Mitigation: Consider adding a response verification layer to validate the integrity of any transaction data returned.

  4. Signer Management and Security

    • Risk: The code assumes that accounts[0] is the intended signer without verifying that it is correctly configured or authorized. This could lead to misuse of a sensitive account or incorrect transaction signing.

    • Mitigation: Add checks to verify that accounts[0] is properly authorized to sign for the multisig wallet.

    if (!accounts[0]) {
    throw new Error('Signer account is not available or configured.');
    }
  5. Handling Chain ID as a BigInt

    • Risk: Using 1n (BigInt) as the chain ID may cause compatibility issues if the SDK or tools expect it as a number type (e.g., 1). This could result in runtime errors.

    • Mitigation: Verify that the SDK functions are fully compatible with BigInt inputs or convert it to the expected type.

  6. Transaction Value Hardcoded to '0'

    • Risk: Although the transaction value is explicitly set to '0', an oversight could occur if the smart contract or function later requires non-zero amounts. This may lead to silent transaction failures.

    • Mitigation: Confirm that '0' is valid for all potential contract executions, or parameterize the value.

  7. Missing Error Handling for API Calls

    • Risk: The await calls to Safe’s SDK (e.g., createTransaction, getTransactionHash, proposeTransaction) are not wrapped in try-catch blocks. If an API request fails, it could leave the process in an unknown state.

    • Mitigation: Add error handling around external API calls.

    try {
    const safeTransaction = await safeSdk.createTransaction({ transactions });
    const safeTxHash = await safeSdk.getTransactionHash(safeTransaction);
    const senderSignature = await safeSdk.signHash(safeTxHash);
    await safeApiKit.proposeTransaction({
    safeAddress: multisigAddress,
    safeTransactionData: safeTransaction.data,
    safeTxHash,
    senderAddress: accounts[0],
    senderSignature: senderSignature.data,
    });
    } catch (error) {
    console.error('Error creating or proposing the transaction:', error);
    throw error;
    }
  8. Race Condition Risk in Multisig Transactions

    • Risk: If multiple transactions are proposed simultaneously (from different sources), you could encounter race conditions where a later proposal invalidates an earlier one.

    • Mitigation: Use nonce management in the multisig to avoid these issues, ensuring that your transaction is always valid upon execution.


Additional Suggestions

  • Logging and Monitoring:
    Add more granular logging (e.g., for transaction hashes, safe address, signatures) to improve observability during failures or debugging.

  • Ensure Network Consistency:
    Verify that hre.network.provider is correctly configured to match the target environment (e.g., Ethereum mainnet).


This version of the code ensures proper error handling, input validation, and improved security around signer management.

Updates

Lead Judging Commences

inallhonesty Lead Judge about 1 year ago
Submission Judgement Published
Invalidated
Reason: Lack of quality

Support

FAQs

Can't find an answer? Chat with us on Discord, Twitter or Linkedin.