vyperlang / vyper

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

abi_encode fails based on slice with `constant` length #4131

Open ritzdorf opened 3 months ago

ritzdorf commented 3 months ago

Version Information

Issue description

When the _abi_encode function contains a slice call, which contains a length, that is a constant variable, then code generation fails. If the constant variable is replaced with the actual constant, compilation succeeds.

POC

# pragma version 0.4.0.rc3

A: constant(uint256) = 42

@external
def foo(b: Bytes[1024]):
    x: Bytes[1092] = _abi_encode(
            slice(b, 0, A),
            method_id=method_id("bar(bytes)"),
        )

fails to compile with:

vyper.exceptions.CodegenPanic: unhandled exception , parse_Call

  contract "examples/abi_encode.vy:7", function "foo", line 7:21 
       6 def foo(b: Bytes[1024]):
  ---> 7     x: Bytes[1092] = _abi_encode(
  ----------------------------^
       8             slice(b, 0, A),

Note that this code compiles successfully:

# pragma version 0.4.0.rc3

A: constant(uint256) = 42

@external
def foo(b: Bytes[1024]):
    x: Bytes[1092] = _abi_encode(
            slice(b, 0, 42),
            method_id=method_id("bar(bytes)"),
        )