What actually happens under the hood when calldata hits the EVM (Execution Flow Breakdown)
0
0
There’s a lot of focus lately on calldata in the context of rollups and EIP-2028 gas economics (16 vs 4 gas per byte). While data availability is important, I often see the actual low-level execution mechanics get glossed over.
I wrote a deep dive on EVM internals covering this exact topic. If you've ever wondered what happens at the opcode level the millisecond your transaction payload hits a smart contract, here is the actual lifecycle of calldata:
The Raw Byte Handoff & The 4-Byte Check
When a transaction is sent, the EVM doesn't understand "functions" or "parameters", it just sees a raw hex-encoded blob in a read-only area called calldata. Before anything else, the EVM checks the length of this data:
The Function Dispatcher (The EVM's Switchboard)
If there is data, the EVM runs the dispatcher essentially a giant, compiler-generated switch/case statement:
- If it finds a match, it uses JUMPI to move the Program Counter to that specific block of code.
ABI Decoding & Stack Loading
Once the EVM jumps to the right function, it has to "unpack" the arguments:
- Dynamic Types (string, bytes[]): The calldata contains an offset (a pointer). The EVM reads this offset, jumps to that position in the calldata, reads the length prefix, and then processes the actual data.
The payable Word
Before executing any actual business logic, the EVM checks the callvalue (msg.value). If the target function is not explicitly marked as payable, but the transaction includes ETH, the EVM triggers a REVERT right here. This prevents trapped funds and happens before your code even starts running.
memory vs. calldata Execution
This is where the famous gas savings come in during execution:
- If a function parameter is declared as memory, the EVM is forced to use CALLDATACOPY to move the read-only bytes into mutable memory. This triggers memory expansion gas costs.
- If declared as calldata, the EVM skips the copy process entirely. It just uses CALLDATALOAD to read directly from the original transaction payload, saving you the memory expansion overhead.
source/deep dive overview: https://andreyobruchkov1996.substack.com/p/what-actually-happens-when-calldata
[link] [comments]
0
0
Securely connect the portfolio you’re using to start.







