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

dcou: BorrowedAccount::set_data() #32424

Merged
merged 2 commits into from
Jul 13, 2023

Conversation

ryoqun
Copy link
Contributor

@ryoqun ryoqun commented Jul 8, 2023

(this is the first use of the shiny dev-context-only-utils, introduced at #32169.)

Problem

BorrowedAccount::set_data() (which is demoted to test-only use at #28053) is still called in production code in zk-token-proof program.

Summary of Changes

cfg-guard ::set_data() under dev-context-only-utils for compile-time safety against these kinds of misuse in foreseeable future.

Also, switch to use alternate fn for the call-site in the zk-token-proof program.

@ryoqun ryoqun force-pushed the dcou-borrowed-account-set-data branch from befc183 to 2b1bf2a Compare July 8, 2023 14:26
Comment on lines -889 to -890
///
/// Currently only used by tests and the program-test crate.
Copy link
Contributor Author

@ryoqun ryoqun Jul 8, 2023

Choose a reason for hiding this comment

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

no need for these kinds of hopeful comments anymore. :)

@codecov
Copy link

codecov bot commented Jul 8, 2023

Codecov Report

Merging #32424 (2b1bf2a) into master (70f8ced) will decrease coverage by 0.1%.
The diff coverage is 0.0%.

@@            Coverage Diff            @@
##           master   #32424     +/-   ##
=========================================
- Coverage    82.1%    82.1%   -0.1%     
=========================================
  Files         778      778             
  Lines      210107   210106      -1     
=========================================
- Hits       172596   172580     -16     
- Misses      37511    37526     +15     

Copy link
Contributor

@samkim-crypto samkim-crypto left a comment

Choose a reason for hiding this comment

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

This is great. Thank you for fixing this!

@@ -64,7 +64,7 @@ where
return Err(InstructionError::InvalidAccountData);
}

proof_context_account.set_data(context_state_data)?;
proof_context_account.set_data_from_slice(&context_state_data)?;
Copy link
Contributor

Choose a reason for hiding this comment

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

given

impl<T: Pod> ProofContextState<T> {
    pub fn encode(
        context_state_authority: &Pubkey,
        proof_type: ProofType,
        proof_context: &T,
    ) -> Vec<u8> {
        let mut buf = Vec::with_capacity(size_of::<Self>());
        buf.extend_from_slice(context_state_authority.as_ref());
        buf.push(ToPrimitive::to_u8(&proof_type).unwrap());
        buf.extend_from_slice(bytes_of(proof_context));
        buf
    }

Shoudn't we make encode write directly into the account, skipping the temporary vec + another memcpy?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

heh, i wasn't bothered enough to erase the newly extra memcpy. ;) sounds nice suggestion. @samkim-crypto could you address this after this pr is merged? or, should i do that in this pr? (if could, i want to offload to you.. thanks in advance!)

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh yes, sorry I missed this. Yes, I can definitely address this on a follow-up!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh yes, sorry I missed this. Yes, I can definitely address this on a follow-up!

thanks very much! I just merged this.

@ryoqun
Copy link
Contributor Author

ryoqun commented Jul 13, 2023

btw, i also wondering this pr (sans dcou stuff) should be back ported to v1.16. (i guess these codes falls under some code path which is planned to activated for v1.16 release line?) I'm just guessing from rather active bp activities related to confidential tokens.

@samkim-crypto
Copy link
Contributor

Oh right, this addresses the proof program, so I think it should technically be backported.

@ryoqun ryoqun merged commit d80745c into solana-labs:master Jul 13, 2023
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.

3 participants