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

adding inputs to constructor using evm run offline #30186

Closed
yohanelly95 opened this issue Jul 18, 2024 · 1 comment
Closed

adding inputs to constructor using evm run offline #30186

yohanelly95 opened this issue Jul 18, 2024 · 1 comment

Comments

@yohanelly95
Copy link

yohanelly95 commented Jul 18, 2024

I want deploy this contract via evm offline using bytecode and get the response:

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

contract BoolContract {
    constructor(bool _value) {
        assembly {
            let ptr := mload(0x40) // Load the current free memory pointer
            mstore(ptr, _value) // Store `true` (1) at the pointer
            mstore(0x40, add(ptr, 32)) // Update the free memory pointer
            return(ptr, 32) // Return the data
        }
    }
}

I get get the abi and byte code via

solc --bin contracts/BoolContract.sol  --abi contracts/BoolContract.sol -o output --evm-version london --overwrite 

and run

evm --code $(cat output/BoolContract.bin) run --input 0000000000000000000000000000000000000000000000000000000000000001 

but I always get the error that error:

execution reverted

how do I get the expected output which would be the same as the input?

@yohanelly95 yohanelly95 changed the title adding inputs to constructor using the evm run offline adding inputs to constructor using evm run offline Jul 18, 2024
@s1na
Copy link
Contributor

s1na commented Jul 22, 2024

I've been wondering about this since you opened the issue. And I have figured out the issue. Solidity expects constructor arguments to be appended to the code itself and not provided as calldata input. So what you need to do is:

❯ ./build/bin/evm run --code "6080604052348015600e575f80fd5b50604051609938038060998339818101604052810190602c91906072565b60405181815260208101604052602081f35b5f80fd5b5f8115159050919050565b6054816042565b8114605d575f80fd5b50565b5f81519050606c81604d565b92915050565b5f602082840312156084576083603e565b5b5f608f848285016060565b9150509291505056fe0000000000000000000000000000000000000000000000000000000000000001"
0x0000000000000000000000000000000000000000000000000000000000000001

Which as you can see does return the input value.

The reason is simple. In Ethereum, when you deploy a contract, the compile code will be set in the calldata of that transaction. Because the nodes have to learn about the code. And because there is only one calldata, Solidity decided for the approach of taking in arguments for constructor from the end of the code.

@s1na s1na closed this as completed Jul 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants