String-ascii clarinet bug
Describe the bug
The bug consists of a failure when calling contract functions using the clarinet-sdk. When passing specific string-ascii values, the contract call fails specifying there are less arguments than provided, even the right number of arguments is provided.
Error encountered Got Contract call error: pox-4::get-signer-key-message-hash({ hashbytes: 0x, version: 0x00 }, u0, "r;NT="", u0, u10, u0) -> expecting 6 arguments, got 3.
To Reproduce Steps to reproduce the behavior:
- run this contract call from a well-formed clarinet-sdk environment (using the
r;NT="string-ascii)
simnet.callReadOnlyFn(
"pox-4",
"get-signer-key-message-hash",
[
Cl.tuple({
version: Cl.buffer(Uint8Array.from([0])),
hashbytes: Cl.buffer(Uint8Array.from([])),
}),
Cl.uint(0),
Cl.stringAscii('r;NT="'),
Cl.uint(0),
Cl.uint(10),
Cl.uint(0),
],
caller
);
Expected behavior Considering the fact that the function takes six parameters and all of them are provided, the expected behaviour would be that the contract call is executed successfully.
Details
@hugocaillard @moodmosaic
Without looking too deeply into this, it appears to be just an encoding issue. clarinet-sdk uses @stacks/transactions under the hood but I believe it pretty-prints the CVs and input them into the CVM as strings.
I noticed that there is a mistake in prettyPrint for string types, it should escape " but it doesn't:
https://github.com/hirosystems/stacks.js/blob/bb0b85d45db3daeed24f12324aa8cb87b03b74a5/packages/transactions/src/clarity/prettyPrint.ts#L84-L85
If clarinet-sdk uses prettyPrint or stringifies CVs itself in a similar way, then it explains the problem you are running into.
it was fixed in https://github.com/hirosystems/clarinet/pull/1380
Details:
-
The clarinet-sdk wasn't using stacks.js prettyPrint to send values to function call (it only uses it to print values) Instead it was using a similar approach in Rust (
clarity_values::uint8_to_string) but that was suffering the same issues -
With the rework in #1380, we use
Value::deserialize_readfrom the clarity VM 👍