Skip to content

Commit

Permalink
fix: relax check for statically sized calldata (#3090)
Browse files Browse the repository at this point in the history
a37bbbc introduced per-method calldatasize checks. however, for the
case where calldata is statically sized (in the ABI sense), this check
is too strict, since users might want to append extra bytes to the
calldata and manipulate msg.data directly for some application-level
reasons.
  • Loading branch information
charles-cooper authored Sep 12, 2022
1 parent be2b7f4 commit 593c88f
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2473,13 +2473,12 @@ def foo(a: {typ}):
malformed = data[:-2]
assert_tx_failed(lambda: w3.eth.send_transaction({"to": c1.address, "data": malformed}))

# Static size exceeds by 1 byte
malformed = data + "ff"
assert_tx_failed(lambda: w3.eth.send_transaction({"to": c1.address, "data": malformed}))

# Static size is exact
w3.eth.send_transaction({"to": c1.address, "data": data})

# Static size exceeds by 1 byte, ok
w3.eth.send_transaction({"to": c1.address, "data": data + "ff"})


@pytest.mark.parametrize("typ,val", [("address", ([TEST_ADDR] * 3, "vyper"))])
def test_dynamic_calldata_clamp(w3, get_contract, assert_tx_failed, abi_encode, keccak, typ, val):
Expand Down
6 changes: 1 addition & 5 deletions vyper/codegen/function_definitions/external_function.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,7 @@ def handler_for(calldata_kwargs, default_kwargs):
# ensure calldata is at least of minimum length
args_abi_t = calldata_args_t.abi_type
calldata_min_size = args_abi_t.min_size() + 4
if args_abi_t.is_dynamic():
ret.append(["assert", ["ge", "calldatasize", calldata_min_size]])
else:
# stricter for static data
ret.append(["assert", ["eq", "calldatasize", calldata_min_size]])
ret.append(["assert", ["ge", "calldatasize", calldata_min_size]])

# TODO optimize make_setter by using
# TupleType(list(arg.typ for arg in calldata_kwargs + default_kwargs))
Expand Down

0 comments on commit 593c88f

Please sign in to comment.