Skip to content

ContractCodec.decodeConstructorInput strips a non-existent 4-byte selector, corrupting constructor params #949

Description

@kyonRay

Description

org.fisco.bcos.sdk.v3.codec.ContractCodec.decodeConstructorInput(abi, bin, input) returns corrupted constructor parameters.

Cause

It delegates to decodeMethodAndGetInputObject(...)decodeMethodAndGetInputObjectByABIDefinition(...), which strips the first 4 bytes assuming a function selector:

return ContractCodecTools.decode(
        inputObject, Hex.decode(input.substring(startWithHexPrefix ? 10 : 8)), isWasm);

But constructor parameter data (the bytes after the contract bytecode) has no 4-byte function selector, so the first 4 bytes of the first parameter are discarded → wrong decode.

By contrast, decodeConstructorInputToString(...) decodes correctly — it builds the input object with ABIObjectFactory.createInputObject(...) and calls contractCodecJsonWrapper.decode(...) on the full paramsInput (no 4-byte strip).

Suggested fix

Make decodeConstructorInput decode paramsInput directly without the 4-byte substring, mirroring decodeConstructorInputToString (e.g. ContractCodecTools.decode(ABIObjectFactory.createInputObject(ctorDef), Hex.decode(paramsInput), isWasm)).

Found via

A constructor encode→decode round-trip test whose object-path result did not match the (correct) string-path result, during #947.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

bugSomething isn't working

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions