Repository navigation
Conversation
…ient The data argument of write, initialize and set_data is a remainder option of bytes with no prefix, as the IDL, the JS client and the program define it. Write the raw bytes and read the rest of the input instead of using the Vec<u8> borsh encoding. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
RemainderOptionBytes(the hooked type behind thedataargument ofwrite,initializeandset_datain the Rust client) serializesSome(bytes)withVec::<u8>::serialize, which writes a 4-byte length prefix. The IDL types this argument as aremainderOptionTypeNodeofbytesTypeNode: the bytes are the rest of the instruction data, with no prefix. The JS client encodes it withgetOptionEncoder(getBytesEncoder(), { prefix: null }), and the program reads everything after the fixed fields as the data.So a Rust client that builds a
writewithdata: Some(vec![1, 2, 3]).into()andoffset: 7sends the args[7, 0, 0, 0, 3, 0, 0, 0, 1, 2, 3]instead of[7, 0, 0, 0, 1, 2, 3], and the program writes[3, 0, 0, 0, 1, 2, 3]into the buffer. The same happens forinitializeandset_data. Decoding has the opposite problem:deserialize_readerexpects a length prefix and maps any error toNone, so valid instruction data[1, 2, 3]decodes asNone.Fix
In
clients/rust/src/hooked/remainder_options.rs,RemainderOptionBytesnow writes the raw bytes forSome, and reads the rest of the input when deserializing: no bytes left isNone, otherwiseSome(bytes). This matches the JS option decoder withprefix: null.RemainderOptionSeedis unchanged, sinceSeedis a fixed[u8; 16]and has no prefix. The generated code is not touched.This is a different problem from the ones listed in #86.
Test
I added unit tests to the same file:
Some(vec![1, 2, 3])serializes to[1, 2, 3],Noneto[], remaining bytes decode toSomeand empty input toNone, values round-trip, andWriteInstructionArgs { offset: 7, data: Some([1, 2, 3]) }serializes to[7, 0, 0, 0, 1, 2, 3]. Three of these fail without the fix. With the fix,cargo testonclients/rustpasses, andcargo fmt --checkandcargo clippy --all-targets --all-features -- -D warnings(nightly-2026-01-22) are clean.This change was prepared with AI assistance (Claude) and reviewed by me before submitting.
🤖 Generated with Claude Code