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

Inconsistent storage caused by function-type variable assignment #14982

Closed
Subway2023 opened this issue Apr 4, 2024 · 1 comment
Closed

Inconsistent storage caused by function-type variable assignment #14982

Subway2023 opened this issue Apr 4, 2024 · 1 comment
Labels

Comments

@Subway2023
Copy link

Description

The contract involves assigning a function-type variable, followed by compilation using four different types: 'origin', 'optimize', 'viaIr', and 'optimize-viaIr'. Upon executing the four sets of bytecode, inconsistencies in storage are observed.

Environment

  • Compiler version: 0.8.25
  • Target EVM version (as per compiler settings): No restrictions
  • Framework/IDE: Remix
  • EVM execution environment / backend / blockchain client: None
  • Operating system: None

Steps to Reproduce

contract C {
    function() internal returns (uint) a;
    function set() public returns (uint256 ret) {
        a = set;
        assembly{
            ret:=sload(0)
        }
    }
}

Four compilation modes

origin

optimize

1712215092147

viaIr

1712214651619
1712215343092

optimize-viaIr

1712215312782

Run in EVM and Get Output

origin

1712214999992

optimize

1712215172441

viaIr/optimize-viaIr

1712215032620

@mehtavishwa30
Copy link
Contributor

Hey @Subway2023! Thanks for raising the question.

The difference/"inconsistency" in the storage layout that you notice here is caused due to the fact that the IR-codegen represents internal function pointers differently from the old codegen. The old code generator uses code offsets or tags for values of internal function pointers. Whereas in the IR codegen, function pointers use internal IDs that are allocated in sequence.

For reference, you can check out the Solidity docs that describe this difference between the two codegens.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants