Skip to content
Access control Audit finding Intermediate

`Registry.sol` generate clone `Anchor.sol` never work. Profile owner cannot use their `Anchor` wallet

The Anchor contract's constructor sets the registry address to msg.sender, which during CREATE3 deployment is a proxy contract, not the actual Registry. As a result, the Anchor's execute function always reverts, and any funds sent to it are permanently stuck.

0xG0P1 Follow with 0xnirlin, Arz and 5 others

Originally disclosed on Sherlock

Source: https://github.com/sherlock-audit/2023-09-Gitcoin-judging/issues/380

Found by

0xG0P1, 0xnirlin, Arz, KingNFT, VAD37, niluk, pinalikefruit, zach030 User create new profile through Registry. Each profile have its own unique Anchor clone contract to handle transactions as a wallet. New clone Anchor.sol contract never work because registry address setup in Anchor constructor point to wrong address. This broke Anchor contract. Profile owner cannot use their wallet Anchor. All funds send to this Anchor contract will be lost forever.

Vulnerability Detail

Add this test to Registry.t.sol test file to reproduce the issue.

JavaScript
    function test_Audit_createProfile() public {
        // create profile
        bytes32 newProfileId = registry().createProfile(nonce, name, metadata, profile1_owner(), profile1_members());
        Registry.Profile memory profile = registry().getProfileById(newProfileId);
        Anchor _anchor = Anchor(payable(profile.anchor));

        console.log("registry address: %s", address(registry()));
        console.log("anchor address: %s", profile.anchor);
        console.log("anchor.registry: %s", address(_anchor.registry()));

        emit log_named_bytes32("profile.id", profile.id);
        emit log_named_bytes32("anchor.profile.id", _anchor.profileId());

        Anchor _anchor_proxy = Anchor(payable(address( _anchor.registry())));
        assertEq(address(registry()),address(_anchor.registry()) ,"wrong anchor registry");
    }

What happen with Anchor.sol is it expect msg.sender is Registry contract. But in reality msg.sender is a proxy contract generated by Solady during CREATE3 operation.

Solidity
    constructor(bytes32 _profileId) {
        registry = Registry(msg.sender);//@audit H Registry address here is not Registry. msg.sender is a proxy contract. Create3 deploy 2 contract. one is proxy. other is actual bytecode.
        profileId = _profileId;
    }

This can be seen with Solady comment for proxy contract. msg.sender above is middleman proxy contract. Not Registry contract. Solady generate 2 contract during CREATE3 operation. One is proxy contract. Second is actual bytecode.

Impact

Anchor.execute() function will not work because registry address point to empty proxy contract and not actual Registry so all call will revert.

Solidity
File: allo-v2\contracts\core\Anchor.sol
70:     function execute(address _target, uint256 _value, bytes memory _data) external returns (bytes memory) {
71:         // Check if the caller is the owner of the profile and revert if not
72:         if (!registry.isOwnerOfProfile(profileId, msg.sender)) revert UNAUTHORIZED();

Profile owner cannot use their wallet Anchor. All funds send to this Anchor contract will be lost forever.

Code Snippet

https://github.com/sherlock-audit/2023-09-Gitcoin/blob/main/allo-v2/contracts/core/Registry.sol#L350 https://github.com/sherlock-audit/2023-09-Gitcoin/blob/main/allo-v2/contracts/core/Anchor.sol#L55-L58

Tool used

Manual Review

Recommendation

Move msg.sender into constructor parameter

Solidity
File: allo-v2\contracts\core\Registry.sol
347:             bytes memory creationCode = abi.encodePacked(type(Anchor).creationCode, abi.encode(_profileId, address(this))); //@audit fix creation code
348: 
349:             // Use CREATE3 to deploy the anchor contract
350:             anchor = CREATE3.deploy(salt, creationCode, 0); 
File: allo-v2\contracts\core\Anchor.sol
55:     constructor(bytes32 _profileId, address _registry) {
56:         registry = Registry(_registry);
57:         profileId = _profileId;
58:     }

Discussion

jkoppel

Escalate.

This should be a medium because the error would be detected upon the first use of Anchor, with minimal funds lost. The owner would simply redeploy the Anchor and Registry contracts and call updateRegistry on Allo.

sherlock-admin2

Escalate.

This should be a medium because the error would be detected upon the first use of Anchor, with minimal funds lost. The owner would simply redeploy the Anchor and Registry contracts and call updateRegistry on Allo.

You've created a valid escalation!

To remove the escalation from consideration: Delete your comment.

You may delete or edit your escalation comment anytime before the 48-hour escalation window closes. After that, the escalation becomes final.

0xArz

@jkoppel This should be a high because execute is not payable and the users will have to send ether to the Anchor which will then get stuck and this doesnt have to be detected upon the first use, many users can create an Anchor and deposit ether and only later call execute. A normal user cant just detect this issue if the execute reverts, he might think that its an error on his side. We dont know how fast this will be fixed, how many users will deposit and how much but its def not minimal loss of funds here.

jkoppel

I didn't say no funds would get stuck. I just said that little would.

AhmadDecoded

Assumption that little funds will be completely arbitrary.

neeksec

Suggest to keep high.

Agree with @0xArz and @AhmadDecoded's comments. The lost amount is not foreseeable and could be high.

MLON33

https://github.com/allo-protocol/allo-v2/pull/348

Evert0x

Planning to reject escalation and keep issue state as is.

Evert0x

Result: High Has Duplicates

sherlock-admin2

Escalations have been resolved successfully!

Escalation status:

jack-the-pug

Fixed.

The original report as published on Sherlock, by 0xG0P1. Images and videos are our own copies; raw HTML is shown as text. View it on Sherlock.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

How it worked

Root cause

The Anchor constructor uses msg.sender to set the registry address, but during CREATE3 deployment msg.sender is a proxy contract, not the Registry.

Impact

The Anchor's execute function will always revert because the registry address points to an empty proxy, so the profile owner cannot use their wallet and any funds sent to it are lost forever.

What the attacker needed

None

The fix

The fix is to pass the Registry address as a constructor parameter instead of relying on msg.sender.

How it was found

  1. Create a new profile through the Registry contract.
  2. Retrieve the profile and its associated Anchor contract address.
  3. Check the registry address stored in the Anchor contract.
  4. Observe that it does not match the actual Registry address.

Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

When a new profile is created, a separate wallet contract (Anchor) is deployed for it. The Anchor contract tries to remember the main Registry contract's address by looking at who deployed it, but because of how the deployment tool works, it sees a temporary middleman instead. This means the wallet can never verify its owner and any money sent to it is lost.

What is Access control?

A user can do something their role should not allow: reach an admin function, act on a feature they have not paid for, or skip a permission check. IDOR is the special case where the object belongs to someone else.

More by 0xG0P1

View all

1 more disclosed report, best first.

More from Allo V2

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Broken access control

The lesson behind this report.

A user can do something their role should not allow: reach an admin function, act on a feature they have not paid for, or skip a permission check. IDOR is the special case where the object belongs to someone else.