Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Confidential mint burn extension: Token program changes #7319

Merged
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
8fbb0fb
confidential mint-burn extension
abcalphabet Jun 19, 2024
de3d227
Merge branch 'master' into confidential_mint_burn_ext
abcalphabet Jul 1, 2024
32d528e
add ciphertext validity proof to confidential mint
abcalphabet Jul 1, 2024
3a9318d
simplify burn proofs
abcalphabet Jul 2, 2024
fee8acb
add confidential supply
abcalphabet Jul 5, 2024
5bbafec
remove debug statements
abcalphabet Jul 5, 2024
d6724a0
add tests for confidential mint-burn
abcalphabet Jul 5, 2024
0ec8537
Merge branch 'master' into confidential_mint_burn_ext
abcalphabet Jul 10, 2024
5939b72
fix clippy & serde tests
abcalphabet Jul 11, 2024
d4ad146
Merge branch 'master' into confidential_mint_burn_ext
abcalphabet Sep 4, 2024
8479bad
fix some tests
abcalphabet Sep 4, 2024
96d8f92
Merge branch 'master' into confidential_mint_burn_ext
abcalphabet Sep 4, 2024
0b20da3
clippy
abcalphabet Sep 4, 2024
48fcb02
Merge branch 'master' into confidential_mint_burn_ext
abcalphabet Sep 25, 2024
18aa58d
mint burn with new proof generation
abcalphabet Oct 1, 2024
59234ba
remove old mintburn proof generation
abcalphabet Oct 1, 2024
89c7cd2
cleanup
abcalphabet Oct 1, 2024
d46407c
remove cli / client changes and mint-burn tests
abcalphabet Oct 1, 2024
3944195
cleanup
abcalphabet Oct 1, 2024
e010003
more cleanup
abcalphabet Oct 1, 2024
42e0193
fix clippy; serde logic
abcalphabet Oct 2, 2024
e0aefa2
Update token/program-2022/src/extension/confidential_mint_burn/mod.rs
abcalphabet Oct 4, 2024
f795a3f
Update token/program-2022/src/extension/confidential_mint_burn/instru…
abcalphabet Oct 4, 2024
c2ec29a
review fixes
abcalphabet Oct 4, 2024
2a1316f
refactor proof location processing
abcalphabet Oct 4, 2024
3908688
comment
abcalphabet Oct 4, 2024
57684cf
cleanup
abcalphabet Oct 4, 2024
32e06db
fix target_os=solana ; test-sbf
abcalphabet Oct 5, 2024
4fea36d
review fixes
abcalphabet Oct 7, 2024
3a14e2e
fix fmt / serde
abcalphabet Oct 8, 2024
8ad746e
construct supply account info from ref to extension
abcalphabet Oct 8, 2024
df6cd8b
add conf mint/burn failure docs; remove todo
abcalphabet Oct 9, 2024
20c84b5
remove obsolete null check
abcalphabet Oct 9, 2024
bcc0812
Update token/program-2022/src/error.rs
abcalphabet Oct 24, 2024
1d2b804
Update token/program-2022/src/extension/confidential_mint_burn/instru…
abcalphabet Oct 24, 2024
534861e
Update token/program-2022/src/extension/confidential_mint_burn/accoun…
abcalphabet Oct 24, 2024
b01ac24
review fixes
abcalphabet Oct 24, 2024
f601fdd
Merge branch 'master' into confidential_mint_burn_ext_program
abcalphabet Oct 25, 2024
5256e9d
more fixes
abcalphabet Oct 28, 2024
3f3c66e
Merge branch 'master' into confidential_mint_burn_ext_program
abcalphabet Oct 28, 2024
fbff190
clippy; review fixes
abcalphabet Oct 29, 2024
d46193f
Merge branch 'master' into confidential_mint_burn_ext_program
abcalphabet Oct 30, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ use {
pubkey::Pubkey,
},
solana_zk_sdk::encryption::pod::{auth_encryption::PodAeCiphertext, elgamal::PodElGamalPubkey},
spl_pod::optional_keys::OptionalNonZeroPubkey,
};
#[cfg(not(target_os = "solana"))]
use {
Expand Down Expand Up @@ -187,9 +186,6 @@ pub enum ConfidentialMintBurnInstruction {
#[derive(Clone, Copy, Debug, PartialEq, Pod, Zeroable)]
#[repr(C)]
pub struct InitializeMintData {
/// Authority used to modify the `ConfidentialMintBurn` mint
/// configuration and mint new tokens
pub authority: OptionalNonZeroPubkey,
/// The ElGamal pubkey used to encrypt the confidential supply
#[cfg_attr(feature = "serde-traits", serde(with = "elgamalpubkey_fromstr"))]
pub supply_elgamal_pubkey: PodElGamalPubkey,
Expand Down Expand Up @@ -278,21 +274,18 @@ pub struct BurnInstructionData {
pub fn initialize_mint(
token_program_id: &Pubkey,
mint: &Pubkey,
authority: &Pubkey,
supply_elgamal_pubkey: PodElGamalPubkey,
decryptable_supply: PodAeCiphertext,
) -> Result<Instruction, ProgramError> {
check_program_account(token_program_id)?;
let accounts = vec![AccountMeta::new(*mint, false)];

let authority = Some(*authority);
Ok(encode_instruction(
token_program_id,
accounts,
TokenInstruction::ConfidentialMintBurnExtension,
ConfidentialMintBurnInstruction::InitializeMint,
&InitializeMintData {
authority: authority.try_into()?,
supply_elgamal_pubkey,
decryptable_supply,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ use {
auth_encryption::PodAeCiphertext,
elgamal::{PodElGamalCiphertext, PodElGamalPubkey},
},
spl_pod::optional_keys::OptionalNonZeroPubkey,
};

/// Maximum bit length of any mint or burn amount
Expand Down Expand Up @@ -33,9 +32,6 @@ pub mod account_info;
#[derive(Clone, Copy, Debug, Default, PartialEq, Pod, Zeroable)]
#[repr(C)]
pub struct ConfidentialMintBurn {
/// Authority to modify the `ConfidentialMintBurnMint` configuration and to
/// mint new confidential tokens
pub authority: OptionalNonZeroPubkey,
/// The confidential supply of the mint (encrypted by `encryption_pubkey`)
pub confidential_supply: PodElGamalCiphertext,
/// The decryptable confidential supply of the mint
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ use {
CiphertextCiphertextEqualityProofContext, CiphertextCiphertextEqualityProofData,
},
},
spl_pod::optional_keys::OptionalNonZeroPubkey,
spl_token_confidential_transfer_proof_extraction::instruction::verify_and_extract_context,
};

Expand All @@ -48,7 +49,6 @@ fn process_initialize_mint(accounts: &[AccountInfo], data: &InitializeMintData)
let mut mint = PodStateWithExtensionsMut::<PodMint>::unpack_uninitialized(mint_data)?;
let mint_burn_extension = mint.init_extension::<ConfidentialMintBurn>(true)?;

mint_burn_extension.authority = data.authority;
mint_burn_extension.supply_elgamal_pubkey = data.supply_elgamal_pubkey;
mint_burn_extension.decryptable_supply = data.decryptable_supply;

Expand All @@ -68,6 +68,7 @@ fn process_rotate_supply_elgamal_pubkey(
check_program_account(mint_info.owner)?;
let mint_data = &mut mint_info.data.borrow_mut();
let mut mint = PodStateWithExtensionsMut::<PodMint>::unpack(mint_data)?;
let mint_authority = mint.base.mint_authority;
let mint_burn_extension = mint.get_extension_mut::<ConfidentialMintBurn>()?;

let proof_context = verify_and_extract_context::<
Expand Down Expand Up @@ -95,8 +96,8 @@ fn process_rotate_supply_elgamal_pubkey(
let authority_info = next_account_info(account_info_iter)?;
let authority_info_data_len = authority_info.data_len();

let authority = Option::<Pubkey>::from(mint_burn_extension.authority)
.ok_or(TokenError::NoAuthorityExists)?;
let authority = OptionalNonZeroPubkey::try_from(mint_authority)?;
let authority = Option::<Pubkey>::from(authority).ok_or(TokenError::NoAuthorityExists)?;
abcalphabet marked this conversation as resolved.
Show resolved Hide resolved

Processor::validate_owner(
program_id,
Expand Down Expand Up @@ -126,10 +127,11 @@ fn process_update_decryptable_supply(
check_program_account(mint_info.owner)?;
let mint_data = &mut mint_info.data.borrow_mut();
let mut mint = PodStateWithExtensionsMut::<PodMint>::unpack(mint_data)?;
let mint_authority = mint.base.mint_authority;
let mint_burn_extension = mint.get_extension_mut::<ConfidentialMintBurn>()?;

let authority = Option::<Pubkey>::from(mint_burn_extension.authority)
.ok_or(TokenError::NoAuthorityExists)?;
let authority = OptionalNonZeroPubkey::try_from(mint_authority)?;
let authority = Option::<Pubkey>::from(authority).ok_or(TokenError::NoAuthorityExists)?;
abcalphabet marked this conversation as resolved.
Show resolved Hide resolved

Processor::validate_owner(
program_id,
Expand Down Expand Up @@ -158,6 +160,7 @@ fn process_confidential_mint(
check_program_account(mint_info.owner)?;
let mint_data = &mut mint_info.data.borrow_mut();
let mut mint = PodStateWithExtensionsMut::<PodMint>::unpack(mint_data)?;
let mint_authority = mint.base.mint_authority;

let auditor_elgamal_pubkey = mint
.get_extension::<ConfidentialTransferMint>()?
Expand All @@ -178,8 +181,8 @@ fn process_confidential_mint(
let authority_info = next_account_info(account_info_iter)?;
let authority_info_data_len = authority_info.data_len();

let authority = Option::<Pubkey>::from(mint_burn_extension.authority)
.ok_or(TokenError::NoAuthorityExists)?;
let authority = OptionalNonZeroPubkey::try_from(mint_authority)?;
let authority = Option::<Pubkey>::from(authority).ok_or(TokenError::NoAuthorityExists)?;
abcalphabet marked this conversation as resolved.
Show resolved Hide resolved

Processor::validate_owner(
program_id,
Expand Down Expand Up @@ -314,19 +317,19 @@ fn process_confidential_burn(
return Err(TokenError::ConfidentialTransferElGamalPubkeyMismatch.into());
}

let source_transfer_amount_lo = &proof_context
let burn_amount_lo = &proof_context
.burn_amount_ciphertext_lo
.try_extract_ciphertext(0)
.map_err(|_| ProgramError::InvalidAccountData)?;
let source_transfer_amount_hi = &proof_context
let burn_amount_hi = &proof_context
.burn_amount_ciphertext_hi
.try_extract_ciphertext(0)
.map_err(|_| ProgramError::InvalidAccountData)?;

let new_source_available_balance = ciphertext_arithmetic::subtract_with_lo_hi(
&confidential_transfer_account.available_balance,
source_transfer_amount_lo,
source_transfer_amount_hi,
burn_amount_lo,
burn_amount_hi,
)
.ok_or(TokenError::CiphertextArithmeticFailed)?;

Expand Down
14 changes: 0 additions & 14 deletions token/program-2022/src/processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -905,20 +905,6 @@ impl Processor {
)?;
extension.authority = new_authority.try_into()?;
}
AuthorityType::MintConfidentialTokens => {
abcalphabet marked this conversation as resolved.
Show resolved Hide resolved
let extension = mint.get_extension_mut::<ConfidentialMintBurn>()?;
let maybe_authority: Option<Pubkey> = extension.authority.into();
let authority = maybe_authority.ok_or(TokenError::AuthorityTypeNotSupported)?;

Self::validate_owner(
program_id,
&authority,
authority_info,
authority_info_data_len,
account_info_iter.as_slice(),
)?;
extension.authority = new_authority.try_into()?;
}
_ => {
return Err(TokenError::AuthorityTypeNotSupported.into());
}
Expand Down
Loading