Skip to content

Commit 5f31725

Browse files
minor fixes (#40)
* check mint proof account size when created * touch program file * only iterate through conditions once; add vec length to anchor constant * patch bump program version
1 parent 19e104c commit 5f31725

File tree

7 files changed

+39
-26
lines changed

7 files changed

+39
-26
lines changed

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

clients/js/test/_common.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ import {
2929
} from '../src/index.js';
3030

3131
export const MAX_PROOF_LENGTH = 28;
32-
32+
export const MINT_PROOF_V2_SIZE = 945;
3333
export const CURRENT_WHITELIST_VERSION = 1;
3434
export const SLOT_DELAY = 100;
3535

clients/js/test/mintProof.test.ts

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
import {
2+
ANCHOR_ERROR__ACCOUNT_DISCRIMINATOR_MISMATCH,
3+
ANCHOR_ERROR__ACCOUNT_NOT_INITIALIZED,
4+
} from '@coral-xyz/anchor-errors';
15
import {
26
SOLANA_ERROR__JSON_RPC__INVALID_PARAMS,
37
appendTransactionMessageInstruction,
@@ -30,19 +34,17 @@ import {
3034
} from '../src';
3135
import {
3236
MAX_PROOF_LENGTH,
37+
MINT_PROOF_V2_SIZE,
3338
SLOT_DELAY,
3439
TRANSACTION_FEE,
3540
createMintProofThrows,
3641
createWhitelist,
3742
expectCustomError,
43+
getAccountDataLength,
3844
updateWhitelist,
3945
upsertMintProof,
4046
} from './_common';
4147
import { generateTreeOfSize } from './_merkle';
42-
import {
43-
ANCHOR_ERROR__ACCOUNT_DISCRIMINATOR_MISMATCH,
44-
ANCHOR_ERROR__ACCOUNT_NOT_INITIALIZED,
45-
} from '@coral-xyz/anchor-errors';
4648

4749
test('it can create and update mint proof v2', async (t) => {
4850
const client = createDefaultSolanaClient();
@@ -95,6 +97,12 @@ test('it can create and update mint proof v2', async (t) => {
9597
},
9698
}));
9799

100+
const mintProofV2AccountLength = await getAccountDataLength(
101+
client,
102+
mintProof
103+
);
104+
t.assert(mintProofV2AccountLength === MINT_PROOF_V2_SIZE);
105+
98106
// Mint a second NFT
99107
const { mint: mint2 } = await createDefaultNft({
100108
client,

program/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "whitelist-program"
3-
version = "0.2.1"
3+
version = "0.2.2"
44
edition = "2021"
55
readme = "./README.md"
66
license-file = "../LICENSE"

program/idl.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"version": "0.2.1",
2+
"version": "0.2.2",
33
"name": "whitelist_program",
44
"constants": [
55
{
@@ -33,7 +33,7 @@
3333
"type": {
3434
"defined": "usize"
3535
},
36-
"value": "8 + 1 + 1 + 32 + 1 + 32 + 32 + 32"
36+
"value": "8 + 1 + 1 + 32 + 1 + 32 + 32 + 32 + 4"
3737
},
3838
{
3939
"name": "WHITELIST_V2_CONDITIONS_LENGTH",

program/src/state/whitelist.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -160,13 +160,13 @@ impl Whitelist {
160160
collection: Option<Collection>,
161161
creators: Option<Vec<Creator>>,
162162
) -> Result<()> {
163-
//Priority 1: Merkle proof (because we manually control this = highest priority)
163+
// Priority 1: Merkle proof (because we manually control this = highest priority)
164164
if self.root_hash != ZERO_ARRAY {
165165
// TODO: currently unsupported for tcomp
166166
throw_err!(ErrorCode::FailedMerkleProofVerification);
167167
}
168168

169-
//Priority 2: VOC
169+
// Priority 2: VOC
170170
if self.voc.is_some() {
171171
match collection {
172172
Some(collection) => {
@@ -187,7 +187,7 @@ impl Whitelist {
187187
return Ok(());
188188
}
189189

190-
//Priority 3: FVC
190+
// Priority 3: FVC
191191
if self.fvc.is_some() {
192192
match creators {
193193
Some(creators) => {

program/src/state/whitelist_v2.rs

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ pub const WHITELIST_V2_BASE_SIZE: usize =
1818
+ 32 // update_authority
1919
+ 32 // namespace
2020
+ 32 // freeze_authority
21+
+ 4 // conditions vector length bytes
2122
;
2223

2324
/// Maximum number of conditions allowed in a whitelist.
@@ -92,24 +93,28 @@ impl WhitelistV2 {
9293
throw_err!(ErrorCode::TooManyConditions);
9394
}
9495

95-
// Only one merkle proof per whitelist allowed.
96-
let merkle_proofs = conditions
97-
.iter()
98-
.filter(|c| c.mode == Mode::MerkleTree)
99-
.count();
96+
// Track the first merkle proof index and count them in one pass
97+
let mut merkle_proof_count = 0;
98+
let mut first_merkle_index = None;
10099

101-
if merkle_proofs > 1 {
100+
for (i, condition) in conditions.iter().enumerate() {
101+
if condition.mode == Mode::MerkleTree {
102+
merkle_proof_count += 1;
103+
if first_merkle_index.is_none() {
104+
first_merkle_index = Some(i);
105+
}
106+
}
107+
}
108+
109+
if merkle_proof_count > 1 {
102110
throw_err!(ErrorCode::TooManyMerkleProofs);
103111
}
104112

105-
// Ensure the merkle proof is the first item in the vector, if it exists.
106-
if let Some(index) = conditions
107-
.iter()
108-
.enumerate()
109-
.find(|(_, c)| c.mode == Mode::MerkleTree)
110-
.map(|(index, _)| index)
111-
{
112-
conditions.rotate_left(index);
113+
// Rotate if we found a merkle proof that wasn't first
114+
if let Some(index) = first_merkle_index {
115+
if index > 0 {
116+
conditions.rotate_left(index);
117+
}
113118
}
114119

115120
Ok(())

0 commit comments

Comments
 (0)