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.
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: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 withABIObjectFactory.createInputObject(...)and callscontractCodecJsonWrapper.decode(...)on the fullparamsInput(no 4-byte strip).Suggested fix
Make
decodeConstructorInputdecodeparamsInputdirectly without the 4-byte substring, mirroringdecodeConstructorInputToString(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.