Skip to content

Commit 96a23e5

Browse files
committed
implement feedback
1 parent 8de313d commit 96a23e5

File tree

12 files changed

+151
-124
lines changed

12 files changed

+151
-124
lines changed

SECURITY_REVIEW_CPI_CONTEXT.md

Lines changed: 90 additions & 99 deletions
Large diffs are not rendered by default.

program-libs/compressed-account/src/instruction_data/zero_copy_set.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ impl ZInAccountMut<'_> {
5656
merkle_context: &<PackedMerkleContext as ZeroCopyAt>::ZeroCopyAt,
5757
root_index: U16,
5858
lamports: u64,
59-
address: Option<&[u8]>,
59+
address: Option<&[u8; 32]>,
6060
) -> Result<(), CompressedAccountError> {
6161
self.discriminator = discriminator;
6262
// Set merkle context fields manually due to mutability constraints
@@ -168,6 +168,9 @@ impl ZNewAddressParamsAssignedPackedMut<'_> {
168168
if let Some(assigned_account_index) = assigned_account_index {
169169
self.assigned_account_index = assigned_account_index;
170170
self.assigned_to_account = 1; // set to true
171+
} else {
172+
self.assigned_account_index = 0;
173+
self.assigned_to_account = 0; // set to false
171174
}
172175
// Note we can skip address derivation since we are assigning it to the account in index 0.
173176
self.address_merkle_tree_account_index = address_merkle_tree_account_index;

program-libs/compressed-account/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,9 +92,9 @@ impl From<CompressedAccountError> for u32 {
9292
CompressedAccountError::InstructionDataExpectedAddress => 12018,
9393
CompressedAccountError::CompressedAccountDataNotInitialized => 12019,
9494
CompressedAccountError::ExpectedDiscriminator => 12020,
95-
CompressedAccountError::ExpectedDataHash => 12020,
9695
CompressedAccountError::InstructionDataExpectedProof => 12021,
9796
CompressedAccountError::ZeroCopyExpectedProof => 12022,
97+
CompressedAccountError::ExpectedDataHash => 12023,
9898
CompressedAccountError::HasherError(e) => u32::from(e),
9999
}
100100
}

program-libs/ctoken-types/src/error.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,13 +78,13 @@ pub enum CTokenError {
7878
#[error("Instruction data expected mint authority")]
7979
InstructionDataExpectedMintAuthority,
8080

81-
#[error("Instruction data expected freeze authority")]
81+
#[error("Zero-copy expected mint authority")]
8282
ZeroCopyExpectedMintAuthority,
8383

8484
#[error("Instruction data expected freeze authority")]
8585
InstructionDataExpectedFreezeAuthority,
8686

87-
#[error("Instruction data expected freeze authority")]
87+
#[error("Zero-copy expected mint authority")]
8888
ZeroCopyExpectedFreezeAuthority,
8989

9090
#[error("Invalid authority type provided")]

program-libs/ctoken-types/src/instructions/create_compressed_mint.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,10 +126,18 @@ pub struct CpiContext {
126126

127127
impl CompressedCpiContextTrait for ZCpiContext<'_> {
128128
fn first_set_context(&self) -> u8 {
129-
self.first_set_context() as u8
129+
if self.first_set_context == 0 {
130+
0
131+
} else {
132+
1
133+
}
130134
}
131135

132136
fn set_context(&self) -> u8 {
133-
self.set_context() as u8
137+
if self.set_context == 0 {
138+
0
139+
} else {
140+
1
141+
}
134142
}
135143
}

program-libs/ctoken-types/src/instructions/extensions/mod.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,7 @@ impl ZExtensionInstructionData<'_> {
7272
"TokenMetadata hash version not supported {} (0 Poseidon, 1 Sha256 are supported).",
7373
token_metadata.version
7474
);
75-
unimplemented!(
76-
"TokenMetadata hash version not supported {}",
77-
token_metadata.version
78-
)
75+
Err(CTokenError::UnsupportedExtension)
7976
} // Version::Keccak256 => <Self as DataHasher>::hash::<Keccak>(self),
8077
// Version::Sha256Flat => self.sha_flat(),
8178
}

program-libs/ctoken-types/src/instructions/mint_actions.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,10 +123,18 @@ pub struct CpiContext {
123123
}
124124
impl CompressedCpiContextTrait for ZCpiContext<'_> {
125125
fn first_set_context(&self) -> u8 {
126-
self.first_set_context() as u8
126+
if self.first_set_context == 0 {
127+
0
128+
} else {
129+
1
130+
}
127131
}
128132

129133
fn set_context(&self) -> u8 {
130-
self.set_context() as u8
134+
if self.set_context == 0 {
135+
0
136+
} else {
137+
1
138+
}
131139
}
132140
}

program-libs/ctoken-types/src/instructions/mint_to_compressed.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,18 @@ pub struct CpiContext {
5959
}
6060
impl CompressedCpiContextTrait for ZCpiContext<'_> {
6161
fn first_set_context(&self) -> u8 {
62-
self.first_set_context() as u8
62+
if self.first_set_context == 0 {
63+
0
64+
} else {
65+
1
66+
}
6367
}
6468

6569
fn set_context(&self) -> u8 {
66-
self.set_context() as u8
70+
if self.set_context == 0 {
71+
0
72+
} else {
73+
1
74+
}
6775
}
6876
}

program-libs/ctoken-types/src/instructions/transfer2.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -283,13 +283,13 @@ impl ZCompression<'_> {
283283
// Compress: add to balance (tokens are being added to compressed pool)
284284
current_balance
285285
.checked_sub((*self.amount).into())
286-
.ok_or(CTokenError::ArithmeticOverflow)
286+
.ok_or(CTokenError::InsufficientSupply)
287287
}
288288
CompressionMode::Decompress => {
289289
// Decompress: subtract from balance (tokens are being removed from compressed pool)
290290
current_balance
291291
.checked_add((*self.amount).into())
292-
.ok_or(CTokenError::CompressInsufficientFunds)
292+
.ok_or(CTokenError::ArithmeticOverflow)
293293
} // CompressionMode::CompressFull => {
294294
// // CompressFull: subtract entire amount from solana account (amount will be set to actual balance in preprocessing)
295295
// current_balance

program-libs/ctoken-types/src/instructions/update_compressed_mint.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,18 @@ pub struct UpdateMintCpiContext {
6161

6262
impl CompressedCpiContextTrait for ZUpdateMintCpiContext<'_> {
6363
fn first_set_context(&self) -> u8 {
64-
self.first_set_context() as u8
64+
if self.first_set_context == 0 {
65+
0
66+
} else {
67+
1
68+
}
6569
}
6670

6771
fn set_context(&self) -> u8 {
68-
self.set_context() as u8
72+
if self.set_context == 0 {
73+
0
74+
} else {
75+
1
76+
}
6977
}
7078
}

0 commit comments

Comments
 (0)