Project

One World
NFTDeFi
15,000 USDC
View results
Submission Details
Severity: high
Invalid

Critical Exploit by Combining Hash Collisions and Event-Based Reentrancy Vulnerabilities

Summary

The combination of two vulnerabilities—hash collisions caused by the use of abi.encodePacked() with user-controlled data, and event-based reentrancy attacks—allows for a severe exploit. This exploit enables an attacker to generate hash collisions to bypass security checks while using reentrancy to recursively call certain functions and manipulate the contract’s state to their advantage. Specifically, the attacker can craft byte sequences to impersonate authorized users or perform restricted actions and, by reentering vulnerable functions, modify the contract’s state in a way that disrupts its integrity and functionality.

Vulnerability Details

  1. Hash Collisions: In the current code, the use of abi.encodePacked() allows attackers to craft byte arrays that result in hash collisions, enabling them to impersonate other users or bypass security checks.

  2. Event-Based Reentrancy: Several functions within the codebase, such as joinDAO() and upgradeTier(), involve external calls followed by state changes and event emissions, leaving them vulnerable to reentrancy attacks. By reentering these functions, an attacker can repeatedly exploit the logic and manipulate contract data in an unintended manner.

This combined exploit is possible because an attacker can bypass initial checks through hash collision manipulation and then use reentrancy to recursively call functions and modify sensitive data, all while avoiding event emissions that could have detected the malicious actions.

Link to the Affected Code

  1. abi.encodePacked(functionSignature, userAddress) in NativeMetaTransaction.sol

    • https://github.com/Cyfrin/2024-11-one-world/blob/1e872c7ab393c380010a507398d4b4caca1ae32b/contracts/meta-transaction/NativeMetaTransaction.sol#L63

  2. function joinDAO(address daoMembershipAddress, uint256 tierIndex) external

    • https://github.com/Cyfrin/2024-11-one-world/blob/1e872c7ab393c380010a507398d4b4caca1ae32b/contracts/dao/MembershipFactory.sol#L140-L150)

Impact

This combined exploit enables an attacker to bypass specific security checks and execute recursive calls that manipulate contract state to their advantage. By exploiting hash collisions alongside event-based reentrancy, an attacker could gain unauthorized access, modify core contract parameters, or even drain contract funds. This attack chain can be used to bypass access control mechanisms, perform unauthorized upgrades, or repeatedly trigger malicious behavior within critical contract functions.

The likelihood of this combined vulnerability being exploited is significant due to the user-controlled data input in the abi.encodePacked() function and the lack of reentrancy protection in sensitive functions. Since the contract handles various external calls and checks based on encoded data, this increases the probability of a successful attack if an attacker is able to deploy a malicious contract and interact with these functions.

This exploit could allow an attacker to gain unauthorized control over the DAO’s membership or perform restricted operations, undermining the contract’s intended functionality. By bypassing security checks via hash collisions, the attacker can impersonate another user or spoof required signatures. Combined with reentrancy, they can recursively call functions like joinDAO or upgradeTier, manipulating state variables before the original function execution completes. This could lead to scenarios where multiple invalid state changes occur, such as unauthorized tier upgrades, repeated fund transfers, or draining contract balances.

Attack Scenario

  1. Unauthorized Memberships and Tier Upgrades: The attacker could bypass membership requirements or upgrade restrictions to gain control of higher-tier membership benefits.

  2. Repeated Transfers or Drains: By repeatedly calling functions that perform transfers, the attacker could siphon funds from the contract or users.

  3. Compromised DAO Governance: Unauthorized DAO membership or tier upgrades could enable the attacker to skew governance votes or other privileges tied to membership status.

Proof of Concept

The proof of concept would involve two steps:

  1. Bypass Checks with Hash Collision: Craft specific inputs that result in the same hash output to bypass access controls or signature checks within the abi.encodePacked() logic.

  2. Reentrancy to Modify State: After bypassing access control, the attacker could recursively call joinDAO or upgradeTier, updating tier levels or repeatedly invoking membership functions to perform unauthorized actions.

// Pseudo-Attack Outline:
contract MaliciousContract {
address public targetContract;
uint256 public tierIndex;
constructor(address _target, uint256 _tier) {
targetContract = _target;
tierIndex = _tier;
}
function exploit() public {
// Bypass checks with crafted input
bytes memory craftedData = abi.encodePacked("targetFunction", address(this));
// Call vulnerable function with crafted data
(bool success,) = targetContract.call(craftedData);
if(success) {
// Reenter to modify state
while(success) {
success = targetContract.call(craftedData);
}
}
}
}

In this example, the attacker uses crafted input to bypass checks and recursively calls a vulnerable function to manipulate membership tiers or siphon funds.

Tools Used

Manual Review

Recommendations

  1. Use abi.encode() Instead of abi.encodePacked(): This adds length markers and prevents potential hash collisions, securing access checks based on hashed data.

  2. Implement Reentrancy Guards: Add the nonReentrant modifier (from OpenZeppelin’s ReentrancyGuard) to all functions that involve state changes and external calls, preventing recursive attacks.

  3. Use Checks-Effects-Interactions Pattern: Move all state changes to occur before external calls to avoid inconsistencies during function execution.

  4. Emit Events Before External Calls: Emit key events before making external calls to avoid missing event records in the event of reentrant attacks.

By implementing these recommendations, the contract will be safeguarded against both hash collision and reentrancy-based exploits, ensuring the integrity of critical operations and preventing unauthorized access to restricted functions.

Updates

Lead Judging Commences

0xbrivan2 Lead Judge 10 months ago
Submission Judgement Published
Invalidated
Reason: Incorrect statement

Support

FAQs

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