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

Unexpected behavior with eth_call's state override #22709

Closed
kclowes opened this issue Apr 20, 2021 · 2 comments
Closed

Unexpected behavior with eth_call's state override #22709

kclowes opened this issue Apr 20, 2021 · 2 comments
Labels

Comments

@kclowes
Copy link

kclowes commented Apr 20, 2021

👋 Hi Geth team! The web3py team is looking to support the state override parameter in eth_call and we're running into some unexpected behavior. It looks like @rjl493456442 implemented this in #19917. Please see details below!

System information

Geth version: v1.10.1
OS & Version: OSX

Expected behaviour

When using the state override argument for eth_call, I expect that a change to the Solidity code will return the expected result. See steps to reproduce below.

Actual behaviour

It looks like some bytecode is returned instead of the expected int, but haven't been able to figure out what the bytecode represents.

Steps to reproduce the behaviour

Following the example in the docs here leads to the expected behavior. I'm using curl with Rinkeby on Infura.

Working as expected:

pragma solidity ^0.5.10;

contract CheckpointOracle {
    mapping(address => bool) admins;
    address[] adminList;
    uint64 sectionIndex;
    uint height;
    bytes32 hash;
    uint sectionSize;
    uint processConfirms;
    uint threshold;

    function VotingThreshold() public view returns (uint) {
        return threshold;
    }
}

bytecode (from Remix): 6080604052348015600f57600080fd5b5060888061001e6000396000f3fe6080604052348015600f57600080fd5b506004361060285760003560e01c80630be5b6ba14602d575b600080fd5b60336049565b6040518082815260200191505060405180910390f35b600060075490509056fea265627a7a72315820c20a98eb83e0fa5a4f0c05d6f392484e4d8009ccacdedd0c6884c53210f8ab5f64736f6c63430005110032

function hash (from Remix): 0be5b6ba

> curl --data '{"method":"eth_call","params":[{"to":"0xebe8efa441b9302a0d7eaecc277c09d20d684540","data":"0x0be5b6ba"}, "latest", {"0xebe8efa441b9302a0d7eaecc277c09d20d684540": {"code":"0x6080604052348015600f57600080fd5b5060888061001e6000396000f3fe6080604052348015600f57600080fd5b506004361060285760003560e01c80630be5b6ba14602d575b600080fd5b60336049565b6040518082815260200191505060405180910390f35b600060075490509056fea265627a7a72315820c20a98eb83e0fa5a4f0c05d6f392484e4d8009ccacdedd0c6884c53210f8ab5f64736f6c63430005110032"}}],"id":1,"jsonrpc":"2.0"}' -H "Content-Type: application/json" -X POST https://rinkeby.infura.io/v3/$INFURA_API_KEY

{"jsonrpc":"2.0","id":1,"result":"0x0000000000000000000000000000000000000000000000000000000000000002"}

which is correct.

However, changing the Solidity code to:

pragma solidity ^0.5.10;

contract CheckpointOracle {
    mapping(address => bool) admins;
    address[] adminList;
    uint64 sectionIndex;
    uint height;
    bytes32 hash;
    uint sectionSize;
    uint processConfirms;
    uint threshold;

    function VotingThreshold() public pure returns (uint) {
        return 42;
    }
}

bytecode (from Remix): 6080604052348015600f57600080fd5b5060878061001e6000396000f3fe6080604052348015600f57600080fd5b506004361060285760003560e01c80630be5b6ba14602d575b600080fd5b60336049565b6040518082815260200191505060405180910390f35b6000602a90509056fea265627a7a723158209dca50efe62375ee4d60d5d21ee28edd70e2afa4558b9f8560778158274c9eed64736f6c63430005110032

function hash (from Remix): 0be5b6ba

Then:

> curl --data '{"method":"eth_call","params":[{"to":"0xebe8efa441b9302a0d7eaecc277c09d20d684540","data":"0x0be5b6ba"}, "latest", {"0xebe8efa441b9302a0d7eaecc277c09d20d684540": {"code":"6080604052348015600f57600080fd5b5060878061001e6000396000f3fe6080604052348015600f57600080fd5b506004361060285760003560e01c80630be5b6ba14602d575b600080fd5b60336049565b6040518082815260200191505060405180910390f35b6000602a90509056fea265627a7a723158209dca50efe62375ee4d60d5d21ee28edd70e2afa4558b9f8560778158274c9eed64736f6c63430005110032"}}],"id":1,"jsonrpc":"2.0"}' -H "Content-Type: application/json" -X POST https://rinkeby.infura.io/v3/$INFURA_API_KEY

{"jsonrpc":"2.0","id":1,"result":"0x6080604052348015600f57600080fd5b506004361060285760003560e01c80630be5b6ba14602d575b600080fd5b60336049565b6040518082815260200191505060405180910390f35b6000602a90509056fea265627a7a723158209dca50efe62375ee4d60d5d21ee28edd70e2afa4558b9f8560778158274c9eed64736f6c63430005110032"}

I expect result to return 42 after decoding.

It's also worth noting that neither Remix nor py-solc-x generates the same bytecode from the Solidity contract source shown in the docs.

I'm not sure if this is a bug or a documentation issue or a decoding issue on our end.

Thanks!

@rjl493456442
Copy link
Member

@kclowes You have to attach the runtime bytecode in order to override the contract code. In your case the bytecode is for deployment.

Can you please try the 6080604052348015600f57600080fd5b506004361060285760003560e01c80630be5b6ba14602d575b600080fd5b60336049565b6040518082815260200191505060405180910390f35b6000602a90509056fea265627a7a72315820cf283c7cc96ce94c0a7d6f99cb6e0c6ae854d84d7ca945bb68e9923ff7383ed264736f6c63430005110032 instead? Or you can copy the runtime bytecode from the remix output.

@kclowes
Copy link
Author

kclowes commented Apr 21, 2021

Ah shoot. That works! Thank you!

@kclowes kclowes closed this as completed Apr 21, 2021
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