esaulpaugh / headlong

High-performance Contract ABI and RLP for Ethereum
Apache License 2.0
79 stars 20 forks source link

add flag for decoding byte arrays/strings assuming no trailing padding #59

Closed esaulpaugh closed 1 year ago

esaulpaugh commented 1 year ago

This is intended to assist with decoding legacy Solidity ABI encodings, specifically as in Solidity v0.4.X and earlier (i.e. before Solidity version 0.5).

Setting this new experimental flag (ABIType.FLAG_LEGACY_DECODE, value 1) during ABIType creation (e.g. when creating a Function or Event) enables an incompatible decoding mode which is local to the object created and the internally-created objects on which it depends (e.g. the object returned by Function#getInputs(). This mode assumes that all byte arrays (including strings) encountered will have no trailing padding bytes. Other behavior such as encoding is not affected. This means that any ABIType, Function, or Event which enables this flag cannot be used to decode specification-compliant encodings. This includes encodings made by these same objects, as their encoding output is still compliant.

If the legacy array flag is not set (for example if you specify ABIType.FLAGS_NONE, value 0) then the ABIType, Function, or Event should expect that all byte arrays have the appropriate padding according to the current ABI specification. In other words, if no flags are set then everything should behave exactly as before in all respects.

Testing and feedback are appreciated and will help ensure correctness and a timely release.

hawkaa commented 1 year ago

Hi @esaulpaugh ! I'm going to test this, but I can't promise to get to it this week. Thanks!