Skip to content

vm.signAndAttachDelegation and vm.attachDelegate result in the incorrect code attached for 7702 delegations #9817

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

Closed
2 tasks
nathanglb opened this issue Feb 3, 2025 · 3 comments
Labels
T-bug Type: bug T-needs-triage Type: this issue needs to be labelled

Comments

@nathanglb
Copy link

Component

Forge

Have you ensured that all of these are up to date?

  • Foundry
  • Foundryup

What version of Foundry are you on?

forge 0.3.0 (5a8bd89 2024-12-20T08:45:53.204298000Z)

What version of Foundryup are you on?

foundryup: 0.3.1

What command(s) is the bug in?

No response

Operating System

None

Describe the bug

When using vm.signAndAttachDelegation or vm.attachDelegation in foundry tests, querying the bytecode of the account that had the delegation attached returns the full bytecode of the delegated contract. This does not match EIP-7702 spec.

The code of the account that has the delegation should be 0xef0100 || <delegate_address> according to spec, and the code length should always be 23 for accounts that have delegates attached.

I used the SimpleDelegateContract example from the foundry docs:

pragma solidity 0.8.24;

contract SimpleDelegateContract {
    event Executed(address indexed to, uint256 value, bytes data);

    struct Call {
        bytes data;
        address to;
        uint256 value;
    }

    function execute(Call[] memory calls) external payable {
        for (uint256 i = 0; i < calls.length; i++) {
            Call memory call = calls[i];
            (bool success, bytes memory result) = call.to.call{value: call.value}(call.data);
            require(success, string(result));
            emit Executed(call.to, call.value, call.data);
        }
    }

    receive() external payable {}
}

After attaching this as the delegate, the account.code query returned:

0x608060405260043610610020575f3560e01c8063a6d0ad611461002b575f80fd5b3661002757005b5f80fd5b61003e61003936600461025a565b610040565b005b5f5b8151811015610189575f82828151811061005e5761005e6103d0565b602002602001015190505f80826020015173ffffffffffffffffffffffffffffffffffffffff168360400151845f015160405161009b919061041f565b5f6040518083038185875af1925050503d805f81146100d5576040519150601f19603f3d011682016040523d82523d5f602084013e6100da565b606091505b5091509150818190610122576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016101199190610483565b60405180910390fd5b50826020015173ffffffffffffffffffffffffffffffffffffffff167fcaf938de11c367272220bfd1d2baa99ca46665e7bc4d85f00adb51b90fe1fa9f8460400151855f015160405161017692919061049c565b60405180910390a2505050600101610042565b5050565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52604160045260245ffd5b6040516060810167ffffffffffffffff811182821017156101dd576101dd61018d565b60405290565b604051601f82017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe016810167ffffffffffffffff8111828210171561022a5761022a61018d565b604052919050565b803573ffffffffffffffffffffffffffffffffffffffff81168114610255575f80fd5b919050565b5f602080838503121561026b575f80fd5b823567ffffffffffffffff80821115610282575f80fd5b818501915085601f830112610295575f80fd5b8135818111156102a7576102a761018d565b8060051b6102b68582016101e3565b91825283810185019185810190898411156102cf575f80fd5b86860192505b838310156103c3578235858111156102eb575f80fd5b86017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe06060828d038201121561031f575f80fd5b6103276101ba565b8983013588811115610337575f80fd5b8301603f81018e13610347575f80fd5b8a81013560408a82111561035d5761035d61018d565b61036d8d86601f850116016101e3565b94508185528f81838501011115610382575f80fd5b818184018e8701375f8d838701015284845261039f818701610232565b848e01526060959095013594830194909452508452505091860191908601906102d5565b9998505050505050505050565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52603260045260245ffd5b5f5b838110156104175781810151838201526020016103ff565b50505f910152565b5f82516104308184602087016103fd565b9190910192915050565b5f81518084526104518160208601602086016103fd565b601f017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0169290920160200192915050565b602081525f610495602083018461043a565b9392505050565b828152604060208201525f6104b4604083018461043a565b94935050505056
@nathanglb nathanglb added T-bug Type: bug T-needs-triage Type: this issue needs to be labelled labels Feb 3, 2025
@github-project-automation github-project-automation bot moved this to Todo in Foundry Feb 3, 2025
@grandizzy
Copy link
Collaborator

@nathanglb this is similar with #9751 and fixed in nightly / v1.0 rc build, please retest (foundryup -i rc or foundryup -i nightly).
Please reopen if still an issue, thank you!

@github-project-automation github-project-automation bot moved this from Todo to Done in Foundry Feb 3, 2025
@nathanglb
Copy link
Author

That appears to have solved it, thank you. Do you know when this is slated to make it to a stable release?

@grandizzy
Copy link
Collaborator

yep, planned for next week

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
T-bug Type: bug T-needs-triage Type: this issue needs to be labelled
Projects
Status: Done
Development

No branches or pull requests

2 participants