Skip to content
This repository was archived by the owner on Mar 11, 2025. It is now read-only.

[spl-record] Remove borsh dependency from spl-record program #6054

Merged
merged 6 commits into from
Jan 4, 2024

Conversation

samkim-crypto
Copy link
Contributor

@samkim-crypto samkim-crypto commented Jan 3, 2024

Problem

Currently, the zero-knowledge proofs that are required for the token-2022 program barely fits in a single transaction. The spl-record program provides a convenient way to break up the proofs into byte chunks to be submitted on chain. However, the record program depends on borsh serialization, which creates issues when combined with the zk-token-proof program.

Summary of changes

Remove the borsh dependency from the record program and use bytemuck for the serialization of data.

@samkim-crypto samkim-crypto added the WIP Work in progress label Jan 3, 2024
@samkim-crypto samkim-crypto removed the WIP Work in progress label Jan 3, 2024
joncinque
joncinque previously approved these changes Jan 3, 2024
Copy link
Contributor

@joncinque joncinque left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Everything looks great! No show-stopping concerns, just some suggestions to make this better in subsequent work, if you'd like

Self::Write { offset, data } => {
buf.push(1);
buf.extend_from_slice(&offset.to_le_bytes());
buf.extend_from_slice(data);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since the bytes are just written directly, this doesn't adhere to the borsh encoding scheme, which prefaces a variable-length type with its size as a u32. I think it should be fine (and it gives us 4 extra bytes!), but it might confuse some people.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, good point. I added the vector length in the serialization.

Comment on lines +21 to +22
/// The length of the data contained in the account for testing.
const DATA_SIZE: usize = 8;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm realizing I didn't do this amazingly 😓 to give yourself more flexibility, it might be easier to remove the whole Data type and field, and just write arbitrary bytes into the provided account. But that can be done separately

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, I think I can probably do this in a follow-up PR.

};

/// Instructions supported by the program
#[derive(Clone, Debug, BorshSerialize, BorshDeserialize, PartialEq)]
#[derive(Clone, Debug, PartialEq)]
pub enum RecordInstruction {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can't comment further down, but you could avoid some copies by having the Write instruction and its creator take a byte slice. Doesn't need to be done here though

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, this is a good idea. Updated!

@mergify mergify bot dismissed joncinque’s stale review January 4, 2024 01:51

Pull request has been modified.

Copy link
Contributor

@joncinque joncinque left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great!

@samkim-crypto samkim-crypto merged commit f36c2fb into solana-labs:master Jan 4, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants