FISCO-BCOS / FISCO-BCOS/java-sdk
ContractCodec.decodeConstructorInput strips a non-existent 4-byte selector, corrupting constructor params
- Dominant language
- Java
- Stars
- 58
- Forks
- 62
- PR merge metrics
- No merged PRs in 30d
Description
### 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:
```java
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.
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.