vyperlang / vyper

Pythonic Smart Contract Language for the EVM
https://vyperlang.org
Other
4.84k stars 788 forks source link

Argument and Return Buffer Size Overestimated for External Calls #4103

Open ritzdorf opened 4 months ago

ritzdorf commented 4 months ago

Version Information

In external_call.py the function _pack_arguments computes the length of the buffer used to store both the arguments of the call and its returned value as:

if fn_type.return_type is not None:
    return_abi_t = calculate_type_for_external_return(fn_type.return_type).abi_type

    # we use the same buffer for args and returndata,
    # so allocate enough space here for the returndata too.
    buflen = max(args_abi_t.size_bound(), return_abi_t.size_bound())
else:
    buflen = args_abi_t.size_bound()

buflen += 32  # padding for the method id

In case the function returns a value and return_abi_t.size_bound() is greater than or equal to args_abi_t.size_bound() + 32, the last 32 bytes of the buffer are never used.