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

ABICoderv1 and AST import cause storage difference due to function-type variable assignment #15410

Open
Subway2023 opened this issue Sep 6, 2024 · 0 comments
Labels

Comments

@Subway2023
Copy link

Description

14986 indicates that when --metadata-hash none is added, the generated bytecode should not change. However, function-type variable assignment will cause storage changes.

Environment

  • Compiler version: 0.8.27
  • Target EVM version (as per compiler settings): None
  • Framework/IDE (e.g. Truffle or Remix): None
  • EVM execution environment / backend / blockchain client: None
  • Operating system: Linux

Steps to Reproduce

contract C {
    function() internal returns (uint) a;

    function g() public returns (uint256) {
        return 2;
    }

    function set() public returns (bytes4) {
        a=g;
    }
}

Get bin

Import from ast

solc C.sol --combined-json ast >> C.json
solc  --bin --import-ast C.json --metadata-hash none

6080604052348015600e575f5ffd5b50610d5b8061001c5f395ff3fe608060405234801561000f575f5ffd5b506004361061007b575f3560e01c8063bd14598f11610059578063bd14598f14610101578063c0f8940c1461010b578063ce8b02671461012b578063d2b0bf7c146101475761007b565b8063189da0691461007f5780633da0ac79146100b15780639ffc991d146100cf575b5f5ffd5b61009960048036038101906100949190610726565b610165565b6040516100a8939291906107a8565b60405180910390f35b6100b96101c3565b6040516100c691906107f7565b60405180910390f35b6100e960048036038101906100e4919061086a565b610330565b6040516100f8939291906107a8565b60405180910390f35b610109610380565b005b61011361042b565b604051610122939291906107a8565b60405180910390f35b610145600480360381019061014091906108e9565b6104e4565b005b61014f610663565b60405161015c91906109a9565b60405180910390f35b5f8181548110610173575f80fd5b905f5260205f2090600202015f91509050805f015f9054906101000a900463ffffffff1690805f0160049054906101000a90046fffffffffffffffffffffffffffffffff16908060010154905083565b5f5f60015f3373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020015f2090505f5f5f60028054610214906109f6565b80601f0160208091040260200160405190810160405280929190818152602001828054610240906109f6565b801561028b5780601f106102625761010080835404028352916020019161028b565b820191905f5260205f20905b81548152906001019060200180831161026e57829003601f168201915b50505050508060200190518101906102a39190610a62565b9250925092508263ffffffff16845f015f9054906101000a900463ffffffff1663ffffffff161480156103185750816fffffffffffffffffffffffffffffffff16845f0160049054906101000a90046fffffffffffffffffffffffffffffffff166fffffffffffffffffffffffffffffffff16145b80156103275750808460010154145b94505050505090565b6001602052805f5260405f205f91509050805f015f9054906101000a900463ffffffff1690805f0160049054906101000a90046fffffffffffffffffffffffffffffffff16908060010154905083565b5f60015f3373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020015f209050805f015f9054906101000a900463ffffffff16815f0160049054906101000a90046fffffffffffffffffffffffffffffffff16826001015460405160200161040a939291906107a8565b604051602081830303815290604052600290816104279190610c7f565b5050565b5f5f5f5f5f5f6002805461043e906109f6565b80601f016020809104026020016040519081016040528092919081815260200182805461046a906109f6565b80156104b55780601f1061048c576101008083540402835291602001916104b5565b820191905f5260205f20905b81548152906001019060200180831161049857829003601f168201915b50505050508060200190518101906104cd9190610a62565b925092509250828282955095509550505050909192565b5f60405180606001604052808563ffffffff168152602001846fffffffffffffffffffffffffffffffff1681526020018381525090505f81908060018154018082558091505060019003905f5260205f2090600202015f909190919091505f820151815f015f6101000a81548163ffffffff021916908363ffffffff1602179055506020820151815f0160046101000a8154816fffffffffffffffffffffffffffffffff02191690836fffffffffffffffffffffffffffffffff1602179055506040820151816001015550508060015f3373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020015f205f820151815f015f6101000a81548163ffffffff021916908363ffffffff1602179055506020820151815f0160046101000a8154816fffffffffffffffffffffffffffffffff02191690836fffffffffffffffffffffffffffffffff1602179055506040820151816001015590505050505050565b60028054610670906109f6565b80601f016020809104026020016040519081016040528092919081815260200182805461069c906109f6565b80156106e75780601f106106be576101008083540402835291602001916106e7565b820191905f5260205f20905b8154815290600101906020018083116106ca57829003601f168201915b505050505081565b5f5ffd5b5f819050919050565b610705816106f3565b811461070f575f5ffd5b50565b5f81359050610720816106fc565b92915050565b5f6020828403121561073b5761073a6106ef565b5b5f61074884828501610712565b91505092915050565b5f63ffffffff82169050919050565b61076981610751565b82525050565b5f6fffffffffffffffffffffffffffffffff82169050919050565b6107938161076f565b82525050565b6107a2816106f3565b82525050565b5f6060820190506107bb5f830186610760565b6107c8602083018561078a565b6107d56040830184610799565b949350505050565b5f8115159050919050565b6107f1816107dd565b82525050565b5f60208201905061080a5f8301846107e8565b92915050565b5f73ffffffffffffffffffffffffffffffffffffffff82169050919050565b5f61083982610810565b9050919050565b6108498161082f565b8114610853575f5ffd5b50565b5f8135905061086481610840565b92915050565b5f6020828403121561087f5761087e6106ef565b5b5f61088c84828501610856565b91505092915050565b61089e81610751565b81146108a8575f5ffd5b50565b5f813590506108b981610895565b92915050565b6108c88161076f565b81146108d2575f5ffd5b50565b5f813590506108e3816108bf565b92915050565b5f5f5f60608486031215610900576108ff6106ef565b5b5f61090d868287016108ab565b935050602061091e868287016108d5565b925050604061092f86828701610712565b9150509250925092565b5f81519050919050565b5f82825260208201905092915050565b8281835e5f83830152505050565b5f601f19601f8301169050919050565b5f61097b82610939565b6109858185610943565b9350610995818560208601610953565b61099e81610961565b840191505092915050565b5f6020820190508181035f8301526109c18184610971565b905092915050565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52602260045260245ffd5b5f6002820490506001821680610a0d57607f821691505b602082108103610a2057610a1f6109c9565b5b50919050565b5f81519050610a3481610895565b92915050565b5f81519050610a48816108bf565b92915050565b5f81519050610a5c816106fc565b92915050565b5f5f5f60608486031215610a7957610a786106ef565b5b5f610a8686828701610a26565b9350506020610a9786828701610a3a565b9250506040610aa886828701610a4e565b9150509250925092565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52604160045260245ffd5b5f819050815f5260205f209050919050565b5f6020601f8301049050919050565b5f82821b905092915050565b5f60088302610b3b7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff82610b00565b610b458683610b00565b95508019841693508086168417925050509392505050565b5f819050919050565b5f610b80610b7b610b76846106f3565b610b5d565b6106f3565b9050919050565b5f819050919050565b610b9983610b66565b610bad610ba582610b87565b848454610b0c565b825550505050565b5f5f905090565b610bc4610bb5565b610bcf818484610b90565b505050565b5b81811015610bf257610be75f82610bbc565b600181019050610bd5565b5050565b601f821115610c3757610c0881610adf565b610c1184610af1565b81016020851015610c20578190505b610c34610c2c85610af1565b830182610bd4565b50505b505050565b5f82821c905092915050565b5f610c575f1984600802610c3c565b1980831691505092915050565b5f610c6f8383610c48565b9150826002028217905092915050565b610c8882610939565b67ffffffffffffffff811115610ca157610ca0610ab2565b5b610cab82546109f6565b610cb6828285610bf6565b5f60209050601f831160018114610ce7575f8415610cd5578287015190505b610cdf8582610c64565b865550610d46565b601f198416610cf586610adf565b5f5b82811015610d1c57848901518255600182019150602085019450602081019050610cf7565b86831015610d395784890151610d35601f891682610c48565b8355505b6001600288020188555050505b50505050505056fea164736f6c634300081b000a

With abicoder v1

add pragma abicoder v1; in program

solc --bin C.sol
6080604052348015600e575f5ffd5b50610be68061001c5f395ff3fe608060405234801561000f575f5ffd5b506004361061007b575f3560e01c8063bd14598f11610059578063bd14598f14610183578063c0f8940c1461018d578063ce8b0267146101d1578063d2b0bf7c1461022a5761007b565b8063189da0691461007f5780633da0ac79146100e65780639ffc991d14610106575b5f5ffd5b6100aa60048036036020811015610094575f5ffd5b81019080803590602001909291905050506102ac565b604051808463ffffffff168152602001836fffffffffffffffffffffffffffffffff168152602001828152602001935050505060405180910390f35b6100ee61030a565b60405180821515815260200191505060405180910390f35b6101476004803603602081101561011b575f5ffd5b81019080803573ffffffffffffffffffffffffffffffffffffffff16906020019092919050505061049c565b604051808463ffffffff168152602001836fffffffffffffffffffffffffffffffff168152602001828152602001935050505060405180910390f35b61018b6104ec565b005b6101956105bb565b604051808463ffffffff168152602001836fffffffffffffffffffffffffffffffff168152602001828152602001935050505060405180910390f35b610228600480360360608110156101e6575f5ffd5b81019080803563ffffffff16906020019092919080356fffffffffffffffffffffffffffffffff16906020019092919080359060200190929190505050610699565b005b610232610818565b604051808060200182810382528381815181526020019150805190602001908083835f5b83811015610271578082015181840152602081019050610256565b50505050905090810190601f16801561029e5780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b5f81815481106102ba575f80fd5b905f5260205f2090600202015f91509050805f015f9054906101000a900463ffffffff1690805f0160049054906101000a90046fffffffffffffffffffffffffffffffff16908060010154905083565b5f5f60015f3373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020015f2090505f5f5f6002805461035b906108d1565b80601f0160208091040260200160405190810160405280929190818152602001828054610387906108d1565b80156103d25780601f106103a9576101008083540402835291602001916103d2565b820191905f5260205f20905b8154815290600101906020018083116103b557829003601f168201915b505050505080602001905160608110156103ea575f5ffd5b810190808051906020019092919080519060200190929190805190602001909291905050509250925092508263ffffffff16845f015f9054906101000a900463ffffffff1663ffffffff161480156104845750816fffffffffffffffffffffffffffffffff16845f0160049054906101000a90046fffffffffffffffffffffffffffffffff166fffffffffffffffffffffffffffffffff16145b80156104935750808460010154145b94505050505090565b6001602052805f5260405f205f91509050805f015f9054906101000a900463ffffffff1690805f0160049054906101000a90046fffffffffffffffffffffffffffffffff16908060010154905083565b5f60015f3373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020015f209050805f015f9054906101000a900463ffffffff16815f0160049054906101000a90046fffffffffffffffffffffffffffffffff168260010154604051602001808463ffffffff168152602001836fffffffffffffffffffffffffffffffff1681526020018281526020019350505050604051602081830303815290604052600290816105b79190610ae1565b5050565b5f5f5f5f5f5f600280546105ce906108d1565b80601f01602080910402602001604051908101604052809291908181526020018280546105fa906108d1565b80156106455780601f1061061c57610100808354040283529160200191610645565b820191905f5260205f20905b81548152906001019060200180831161062857829003601f168201915b5050505050806020019051606081101561065d575f5ffd5b81019080805190602001909291908051906020019092919080519060200190929190505050925092509250828282955095509550505050909192565b5f60405180606001604052808563ffffffff168152602001846fffffffffffffffffffffffffffffffff1681526020018381525090505f81908060018154018082558091505060019003905f5260205f2090600202015f909190919091505f820151815f015f6101000a81548163ffffffff021916908363ffffffff1602179055506020820151815f0160046101000a8154816fffffffffffffffffffffffffffffffff02191690836fffffffffffffffffffffffffffffffff1602179055506040820151816001015550508060015f3373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020015f205f820151815f015f6101000a81548163ffffffff021916908363ffffffff1602179055506020820151815f0160046101000a8154816fffffffffffffffffffffffffffffffff02191690836fffffffffffffffffffffffffffffffff1602179055506040820151816001015590505050505050565b60028054610825906108d1565b80601f0160208091040260200160405190810160405280929190818152602001828054610851906108d1565b801561089c5780601f106108735761010080835404028352916020019161089c565b820191905f5260205f20905b81548152906001019060200180831161087f57829003601f168201915b505050505081565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52602260045260245ffd5b5f60028204905060018216806108e857607f821691505b6020821081036108fb576108fa6108a4565b5b50919050565b5f81519050919050565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52604160045260245ffd5b5f819050815f5260205f209050919050565b5f6020601f8301049050919050565b5f82821b905092915050565b5f600883026109947fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff82610959565b61099e8683610959565b95508019841693508086168417925050509392505050565b5f819050919050565b5f819050919050565b5f6109e26109dd6109d8846109b6565b6109bf565b6109b6565b9050919050565b5f819050919050565b6109fb836109c8565b610a0f610a07826109e9565b848454610965565b825550505050565b5f5f905090565b610a26610a17565b610a318184846109f2565b505050565b5b81811015610a5457610a495f82610a1e565b600181019050610a37565b5050565b601f821115610a9957610a6a81610938565b610a738461094a565b81016020851015610a82578190505b610a96610a8e8561094a565b830182610a36565b50505b505050565b5f82821c905092915050565b5f610ab95f1984600802610a9e565b1980831691505092915050565b5f610ad18383610aaa565b9150826002028217905092915050565b610aea82610901565b67ffffffffffffffff811115610b0357610b0261090b565b5b610b0d82546108d1565b610b18828285610a58565b5f60209050601f831160018114610b49575f8415610b37578287015190505b610b418582610ac6565b865550610ba8565b601f198416610b5786610938565b5f5b82811015610b7e57848901518255600182019150602085019450602081019050610b59565b86831015610b9b5784890151610b97601f891682610aaa565b8355505b6001600288020188555050505b50505050505056fea2646970667358221220ac450a9b35b803e5311a20923f31dbc00418bb2113689ee678b2fe8cd9c3f19164736f6c634300081b0033

Origin

solc --bin C.sol
6080604052348015600e575f5ffd5b506101638061001c5f395ff3fe608060405234801561000f575f5ffd5b5060043610610034575f3560e01c8063b8e010de14610038578063e2179b8e14610056575b5f5ffd5b610040610074565b60405161004d91906100e3565b60405180910390f35b61005e6100a1565b60405161006b9190610114565b60405180910390f35b5f6100a15f5f6101000a81548167ffffffffffffffff021916908367ffffffffffffffff16021790555090565b5f6002905090565b5f7fffffffff0000000000000000000000000000000000000000000000000000000082169050919050565b6100dd816100a9565b82525050565b5f6020820190506100f65f8301846100d4565b92915050565b5f819050919050565b61010e816100fc565b82525050565b5f6020820190506101275f830184610105565b9291505056fea26469706673582212209a196401a77f4de8dcbe2ede5701eb5207d55c659505aa045911717b00ee25d564736f6c634300081b0033

Run in EVM

Import from ast

contractName,funcName,storage
C,set,{'0': '161'}

With abicoder v1

contractName,funcName,storage
C,set,{'0': '183'}

Origin

contractName,funcName,storage
C,set,{'0': '104'}
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

1 participant