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

🔒 H-01 - Ensure msg.value is Forwarded to Prevent Loss of User Funds #113

Merged
merged 7 commits into from
Aug 5, 2024

Conversation

Aboudjem
Copy link
Contributor

H-01. User may lose funds when creating Nexus account or executing user operations

Issue: Users may lose funds because msg.value is ignored during the creation of a Nexus account or execution of user ops. Any ETH sent with these txs could be lost if not properly handled.

Fix: Added handling for msg.value to ensure any ETH sent with the tx is forwarded appropriately.

Summary of Fixes:

  • Added handling for msg.value in the deployWithFactory, executeUserOp, and fallback functions to ensure ETH is properly forwarded.

Copy link

codecov bot commented Jul 29, 2024

Codecov Report

Attention: Patch coverage is 66.66667% with 1 line in your changes missing coverage. Please review.

Project coverage is 72.18%. Comparing base (2f9a401) to head (482e6cc).
Report is 1 commits behind head on dev.

Additional details and impacted files
@@             Coverage Diff             @@
##              dev     #113       +/-   ##
===========================================
- Coverage   87.29%   72.18%   -15.11%     
===========================================
  Files          13       13               
  Lines         559      676      +117     
  Branches      122      124        +2     
===========================================
  Hits          488      488               
- Misses         69      186      +117     
  Partials        2        2               
Files Coverage Δ
contracts/Nexus.sol 63.42% <100.00%> (-23.30%) ⬇️
contracts/factory/BiconomyMetaFactory.sol 93.33% <100.00%> (ø)
contracts/base/ModuleManager.sol 86.62% <0.00%> (-7.17%) ⬇️

... and 5 files with indirect coverage changes


Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update ad6af35...482e6cc. Read the comment docs.

@Aboudjem Aboudjem changed the title 🔒️ h01 fix by adding msg.value 🔒️ h01 - fix by adding msg.value Jul 29, 2024
@livingrockrises livingrockrises changed the base branch from dev to remediations/cyfrin July 29, 2024 15:42
@@ -166,7 +166,7 @@ contract Nexus is INexus, BaseAccount, ExecutionHelper, ModuleManager, UUPSUpgra
(address target, bytes memory data) = abi.decode(innerCall, (address, bytes));
bool success;
// Perform the call to the target contract with the decoded data.
(success, innerCallRet) = target.call(data);
(success, innerCallRet) = target.call{value: msg.value}(data);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this data is initialise data?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yep

@livingrockrises
Copy link
Contributor

this is same as
https://cantina.xyz/code/d1d4b139-9705-4367-9468-297b7078674e/findings/49
so to cantina auditers we will have to show them this.

please check above link also and make sure everything is covered. and ping the PR link in thread thre.

@Aboudjem Aboudjem changed the title 🔒️ h01 - fix by adding msg.value 🔒 H-01 - Ensure msg.value is Forwarded to Prevent Loss of User Funds Jul 31, 2024
@livingrockrises
Copy link
Contributor

We have a response from spearbit.

looks good to me but note that step 4) "Other factories don't forward it in INexus(account).initializeAccount(initData)" is still missing. A different bootstrap contract might want to use msg.value?

@Aboudjem
Copy link
Contributor Author

Aboudjem commented Aug 2, 2024

    function createAccount(
        address eoaOwner,
        uint256 index,
        address[] calldata attesters,
        uint8 threshold
    ) external payable returns (address payable) {
        // Compute the actual salt for deterministic deployment
        bytes32 actualSalt;
        assembly {
            let ptr := mload(0x40)
            let calldataLength := sub(calldatasize(), 0x04)
            mstore(0x40, add(ptr, calldataLength))
            calldatacopy(ptr, 0x04, calldataLength)
            actualSalt := keccak256(ptr, calldataLength)
        }

        // Deploy the Nexus contract using the computed salt
        (bool alreadyDeployed, address account) = LibClone.createDeterministicERC1967(msg.value, ACCOUNT_IMPLEMENTATION, actualSalt);

        // Create the validator configuration using the Bootstrap library
        BootstrapConfig memory validator = BootstrapLib.createSingleConfig(K1_VALIDATOR, abi.encodePacked(eoaOwner));
        bytes memory initData = BOOTSTRAPPER.getInitNexusWithSingleValidatorCalldata(validator, REGISTRY, attesters, threshold);

        // Initialize the account if it was not already deployed
        if (!alreadyDeployed) {
            INexus(account).initializeAccount{ value: msg.value }(initData);
            emit AccountCreated(account, eoaOwner, index);
        }
        return payable(account);
    }

The msg.value is already forwarded in the deployment step here, any suggestion?
(bool alreadyDeployed, address account) = LibClone.createDeterministicERC1967(msg.value, ACCOUNT_IMPLEMENTATION, actualSalt);

🔒 H-03 - Enforce Registry Calls Before Module Setup to Comply with EIP-7484
🔒 H-02 - Prevent Freezing of Funds in Factory Contracts
@livingrockrises
Copy link
Contributor

just make sure all factories forward it

@livingrockrises livingrockrises merged commit 323ab19 into remediations/cyfrin Aug 5, 2024
8 checks passed
@livingrockrises livingrockrises deleted the fix/security-h01 branch August 5, 2024 15:41
Copy link

github-actions bot commented Aug 5, 2024

🤖 Slither Analysis Report 🔎

Slither report

# Slither report

THIS CHECKLIST IS NOT COMPLETE. Use --show-ignored-findings to show all the results.
Summary

constable-states

Impact: Optimization
🔴 Confidence: High

base/RegistryAdapter.sol#L12

factory/RegistryFactory.sol#L39

_This comment was automatically generated by the GitHub Actions workflow._

Copy link

🔒 H-01 - Ensure msg.value is Forwarded to Prevent Loss of User Funds

Generated at commit: c3df11cedf5fdc80f31daeaebc825eae0b24d9f8

🚨 Report Summary

Severity Level Results
Contracts Critical
High
Medium
Low
Note
Total
0
1
0
6
24
31

For more details view the full report in OpenZeppelin Code Inspector

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.

None yet

3 participants