Tadle

Tadle
DeFi
30,000 USDC
View results
Submission Details
Severity: low
Invalid

Inadequate Error Handling and State Update Order in DeliveryPlace Contract

Summary:

The DeliveryPlace contract suffers from potential vulnerabilities related to inadequate error handling and improper ordering of state updates and external calls. If an error occurs after some state changes but before the function completes, it could leave the contract in an inconsistent state. Additionally, if external calls are made before updating the contract's state, the contract might become vulnerable to unexpected failures or reentrancy attacks.


Vulnerability Details:

Title: Inadequate Error Handling and State Update Order

Severity: High

Description:
The DeliveryPlace contract contains functions that do not adequately handle errors and may update the contract state in an unsafe order. Specifically:

  • Error Handling: While the contract uses revert statements to handle errors, there is a risk that state changes occurring before the error are not reverted properly if the function encounters an error after partial state changes.

  • State Update Order: Functions like closeBidOffer and settleAskMaker make external calls before updating the contract state. If an external call fails or behaves unexpectedly, this could leave the contract in an inconsistent state, potentially leading to security vulnerabilities like reentrancy attacks.

Affected Code Snippets:

1. External Call Before State Update in closeBidOffer:

IPerMarkets perMarkets = tadleFactory.getPerMarkets();
perMarkets.updateOfferStatus(_offer, OfferStatus.Settled);
// State update occurs after external call
emit CloseBidOffer(
makerInfo.marketPlace,
offerInfo.maker,
_offer,
_msgSender()
);

2. External Call Before State Update in settleAskMaker:

IPerMarkets perMarkets = tadleFactory.getPerMarkets();
perMarkets.settledAskOffer(
_offer,
_settledPoints,
settledPointTokenAmount
);
// State update occurs after external call
emit SettleAskMaker(
makerInfo.marketPlace,
offerInfo.maker,
_offer,
_msgSender(),
_settledPoints,
settledPointTokenAmount,
makerRefundAmount
);

Vulnerability Summary:

  • Functions: closeBidOffer, settleAskMaker, settleAskTaker

  • Issue: State updates are performed after external calls, leading to potential inconsistencies if an error occurs during or after the external call.

  • Risk: Inconsistent contract state and vulnerability to reentrancy attacks.


Impact:

  • Inconsistent State: If an external call fails or behaves unexpectedly, the contract might be left in an inconsistent state, which could lead to further errors or vulnerabilities in subsequent operations.

  • Reentrancy Risk: Making external calls before updating the contract’s state increases the risk of reentrancy attacks, where an attacker could exploit the window of opportunity between the external call and the state update.

  • Security and Financial Loss: These vulnerabilities could be exploited to drain funds, manipulate offer statuses, or cause other unauthorized behaviors, leading to significant financial losses and undermining the security of the contract.


Recommendations:

  1. Reorder State Updates:

    • Ensure that all necessary state updates are performed before making any external calls. This reduces the risk of the contract being left in an inconsistent state if the external call fails.

  2. Use Checks-Effects-Interactions Pattern:

    • Follow the checks-effects-interactions pattern consistently in all functions. First, validate all conditions and update the contract’s state, then make external calls as the last step. This pattern minimizes the risk of reentrancy and other related issues.

  3. Implement Reentrancy Guards:

    • Use the nonReentrant modifier or other reentrancy guards to prevent reentrancy attacks, particularly in functions that make external calls.

  4. Comprehensive Testing:

    • Conduct extensive testing and auditing of the contract with a focus on edge cases, potential reentrancy scenarios, and state consistency, especially in the presence of external calls.

  5. Use Try/Catch for External Calls:

    • Consider using try/catch blocks for external calls to handle potential failures gracefully and ensure that the contract can respond appropriately without being left in an inconsistent state.


Conclusion:

The DeliveryPlace contract's current error handling and state update logic present significant risks related to inconsistent states and reentrancy attacks. By reordering state updates, following best practices like the checks-effects-interactions pattern, and implementing reentrancy guards, these vulnerabilities can be mitigated, ensuring the secure and reliable operation of the contract.

Updates

Lead Judging Commences

0xnevi Lead Judge 10 months ago
Submission Judgement Published
Invalidated
Reason: Lack of quality
Assigned finding tags:

[invalid] finding-PreMarkets-reentrancy

Invalid, all [vague generalities](https://docs.codehawks.com/hawks-auditors/how-to-determine-a-finding-validity#vague-generalities) talking about possible reentrancies 11and afaik, reentrancy is not possible and not proven.

Support

FAQs

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