< Back
#40 Bytecode One, Wrong Expected
AndreiToma

I can not understand why the expected return value for getBytecode() would ever be: ["0x0000000000000000000000000000000000000000000000000000000000000020"]. In the problem description it is stated that:

The contract should have a function called getBytecode that returns the bytecode of the contract.

My solution code for problem #40 is:

ragma solidity ^0.8.0;

contract BytecodeGetter {
    function getBytecode() public view returns (bytes memory) {
        bytes memory bytecode;
        assembly {
            let freeMemPtr := mload(0x40)
            mstore(bytecode, codesize())
            extcodecopy(address(), add(bytecode, 0x20), 0x00, codesize())
            mstore(0x40, add(bytecode, add(codesize(), 0x20)))
        }
        return bytecode;
    }
}

which returns the raw bytecode of the contract:

Output = ["0x608060405234801561001057600080fd5b506004361061002b5760003560e01c806352c7420d14610030575b600080fd5b61003861004e565b6040516100459190610101565b60405180910390f35b60608060405138825238600060208401303c602038018201604052508091505090565b600081519050919050565b600082825260208201905092915050565b60005b838110156100ab578082015181840152602081019050610090565b60008484015250505050565b6000601f19601f8301169050919050565b60006100d382610071565b6100dd818561007c565b93506100ed81856020860161008d565b6100f6816100b7565b840191505092915050565b6000602082019050818103600083015261011b81846100c8565b90509291505056fea2646970667358221220dd63d98480e491abfcf5fed8a6b1d6f9b451d4a88f7aeb043f05b4f53a367ecc64736f6c63430008130033"]

Can someone explain the actual expected result?

Comments: 0

Be the first to comment...