2

I'm inspecting a contract on etherscan, at the following URL:

https://etherscan.io/address/0x5cb5f46a655c02889172323760d12d0e5d83cdaf#code

At the bottom of the web-page, I see two sections:

  1. Contract Creation Code
  2. Constructor Arguments (ABI-Encoded and is the last bytes of the Contract Creation Code above)

The contents of the 2nd section is most certainly not equal to the last bytes in the 1st section.

So what exactly does it mean "the last bytes of the Contract Creation Code above"?

My ultimate goal is in fact to obtain the constructor arguments of some other contract.

However, when I inspect this contract on etherscan, the 2nd section does not appear at all.

So I was hoping I could somehow extract it from the 1st section, but I cannot figure out the relation between them (if any).

The other contract can be inspected on etherscan at the following URL:

https://etherscan.io/address/0x5248e5fd5d3b43126e5352807f75d6a7d6d7eafb#code

Thank you!

1 Answer 1

3

The ABI standard defines how arguments are encoded and functions are accessed in function calls on smart contracts.

The ABI standard dictates that the the constructor arguments are put on the end of the contract creation code. If you look at the init field (etherscan calls it Input Data Field in the link below) of the contract creation transaction, you will see the data that etherscan has interpreted as the constructor arguments (it is the end of the Input Data Field):

000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000de0b6b3a764000000000000000000000000000000000000000000000000000000000000000000020000000000000000000000000e40ee0e6e309b9e68362b78c3801928b511a7e30000000000000000000000002bcc3e2c286780e8c63823a4bddd7f7e3dbd35dc

https://etherscan.io/tx/0x03ae45ef510d108fa553df60181e0f574f3936550dfcc2266efea60b1aeddfa5

So it seems that the field called "Contract Creation Code" on etherscan does not include the constructor arguments as the text would otherwise indicate.

Digging a little deeper into the contract creation code (the Input Data field from above) reveals that the constructor arguments begin at byte 6993 (0x1B51) of the init field. This value (1b51) also appears in the beginning of the input data field twice. I ran the binary code manually (the first 28 bytes of the init field) and found out that the bytes starting at 0x1b51 to the end of the init field are copied to memory (of the virtual machine). So the compiled code copies the constructor arguments from the init field to memory and accesses them from there in the further execution of the constructor.

You can also have a look at: How are the arguments of the constructor encoded in the contract creation transaction?

1
  • I compared between the contents of the 1st section and the input data of the contract-creation transaction, and it seems to be aligned with your answer (the two pieces of data are identical, with the exception of a suffix at the end of the latter). Thank you very much!!! Jan 7, 2019 at 17:12

Your Answer

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

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