Given a data input: Count how many zeo bytes Count how many nonzero bytes Calldata gas = 16 nonzero_bytes + 4 zero+bytes Formula in DuneSQL format is here: 16 * ( bytearray_length(data) - (length(from_utf8(data)) - length(replace(from_utf8(data), chr(0), ''))) ) --nonzero bytes + 4 * ( (length(from_utf8(data)) - length(replace(from_utf8(data), chr(0), ''))) ) AS calldata_gas It could be formatted like get_calldata_gas(data)