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

deth_ctf - Incorrect address computation #38

Open
Maroutis opened this issue Aug 12, 2024 · 1 comment
Open

deth_ctf - Incorrect address computation #38

Maroutis opened this issue Aug 12, 2024 · 1 comment
Labels
bug Something isn't working duplicate This issue or pull request already exists

Comments

@Maroutis
Copy link

Summary

The computeAddress function does not compute the correct address for the would be deployed Vault.

Details

When a contract has constructor parameters, the Create2 opcode needs to account for the parameters that are to be concatenated with the contract's bytecode. In case of the Vault contract the owner parameter is missing and the initCode is incomplete :

    function computeAddress() public view returns (address) {
        bytes32 salt = bytes32(uint256(uint160(msg.sender)));
        return address(uint160(uint256(keccak256(abi.encodePacked(
            bytes1(0xff),
            address(this),
            salt,
 @>           keccak256(type(Vault).creationCode)
        )))));

Impact

Users will call the incorrect address where the call would ultimately fail or worse call a malicious contract where their funds could be at risk. In any case a non dev user will find himself stuck as he cannot use the computed address.

Solution

Implement the following changes :

    function computeAddress() public view returns (address) {
        bytes32 salt = bytes32(uint256(uint160(msg.sender)));
        return address(uint160(uint256(keccak256(abi.encodePacked(
            bytes1(0xff),
            address(this),
            salt,
            keccak256(abi.encodePacked(type(Vault).creationCode, abi.encode(msg.sender))
        ))))));
@0xdeth 0xdeth added bug Something isn't working duplicate This issue or pull request already exists labels Aug 17, 2024
@0xdeth
Copy link
Contributor

0xdeth commented Aug 17, 2024

Duplicate of #6.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working duplicate This issue or pull request already exists
Projects
None yet
Development

No branches or pull requests

2 participants