0

I have two questions regarding the ABI.

1. When does it happen?

A digital signature is made by creating a transaction data structure, RLP-encoded serializing the data, hashing it through keccak-256, and signing it with ECDSA using a private key. At which point does ABI-encoding happen?

2. What does it encode?

Does ABI-encoding only happen for the contract method invoking data or also for things like the value, nonce, etc? If latter, does that mean the transaction parameters get RLP-encoded AND ABI-encoded?

1 Answer 1

0

The ABI or the Application Binary Interface is the standard to interact with the contracts. EVM uses the ABI encoded data to understand which part of the bytecode to execute.

When does it happen? A contract interaction is just another transaction on ethereum. The payload/what-to-do is in the data field of the transaction. ABI encoding encodes the user's parameters and function signature. Then you put this in the data field of the transaction. And then you sign the transaction as proof of ownership. Then the whole transaction data is RLP encoded.

What does it encode? ABI encoding is used only in contract interactions. It is used to compute the keccak256 hash of the target function selector and then the arguments you want to supply. The process returns raw bytes which are then put into the data field of the transaction.

The whole flow :

Sender :

  • Decide which function to execute at a contract address
  • ABI encode function selector and arguments
  • Put the ABI encoder's output raw bytes in the data field of transaction
  • Put all the other values, to, value and nonce
  • RLP encode these fields
  • Sign the transaction
  • Again RLP encode it and send

After travelling through some wires...

Receiver/Node :

  • RLP decode the received transaction
  • Verify if valid by checking the signature
  • RLP decode
  • Execute! (EVM internally handles the ABI decode and execution)

RLP encoding is the protocol used to communicate over channels i.e your mobile's data or Ethernet or etc.., it is the low level method used to convert data before sending through transmission. Aside from Ethereum, you can also use RLP encoding for something like Mobile communication. It's just another protocol.

6
  • Thank you for the detailed response. You mentioned Then the whole transaction data is RLP encoded after being signed, but, if my understanding is correct, doesn't the transaction data get RLP-encoded serialized first, put through keccak256, then the hash of that gets signed with ECDSA and a private key?
    – Kevvv
    Jan 26, 2022 at 17:13
  • Nope. Check this article for more details. RLP encoding is the way data is sent to a destination, doesn't have anything to do with transaction details/signs.
    – Pranay
    Jan 26, 2022 at 17:53
  • interesting. I'm confused. Does that mean this equation S i g = F sig ( F keccak256 ( m ) , k ) from this book is inaccurate?
    – Kevvv
    Jan 26, 2022 at 18:02
  • Ah, I'm sorry that I missed it. I made changes.
    – Pranay
    Jan 26, 2022 at 18:55
  • no worries. so just to be clear, ABI is initially a conversion of a smart contract into a human readable JSON format first then a conversion into the raw byte code right? I'm confused about different formats of ABI's.
    – Kevvv
    Jan 26, 2022 at 19:25

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.