0
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.13;

contract testABI {
    function getEncodePacked(string calldata _func,bytes calldata _data) public pure     returns(bytes memory) {
        return abi.encodePacked(bytes4(keccak256(bytes(_func))), _data);
    }

    function getEncodeWithSignature(string calldata _func,bytes calldata _data) public pure returns(bytes memory) {
        return abi.encodeWithSignature(_func, _data);
    }
}

enter image description here

I'm working on abi.encodePacked and abi.encodeWithSignature.

I want to know what "0000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000000000" means after the result of abi.encodeWithSignature.

1 Answer 1

1

That's just the offset of the start of the data and the count of elements in the bytes dynamic 'array' and it's values (which in this case is zero).

Take a look at the docs: https://docs.soliditylang.org/en/v0.8.16/abi-spec.html#use-of-dynamic-types

The 2 is the start offset of the data. 1 is the elements in the bytes array (the only value that is has is an empty byte which is 0x00).

And after 1 we found the value, which is 00, but there many zeros in there, because all those values are padded with zeros to 32 bytes.

For an inmput like this baz(uint32,bool),0x05:

It would result in:

0xcdcd77c0000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000010500000000000000000000000000000000000000000000000000000000000000

For baz(uint32,bool),0x0503:

It would be (notice that now there's no 1, but 2 because I sent 2 params. The dynamic data offset is still the same:

0xcdcd77c0000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000020503000000000000000000000000000000000000000000000000000000000000

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.