Skip to content

Commit

Permalink
Jxiao/fix log truncation (solana-labs#121)
Browse files Browse the repository at this point in the history
* Initial implementation of log truncation fix

* Add new files

* refactor bubblegum pda

* amend me

* update basic ts sdk

* better bgum convenience

* addProof modifies instructions to add proof fluently

* better bg init

* fix rebase issues

* fix sugar shack tests

* use convenience initializer

* revert maxSeq change, update smokeTest

Co-authored-by: Noah Gundotra <noahgundotra@noahs-mbp.mynetworksettings.com>
  • Loading branch information
jarry-xiao and Noah Gundotra authored Jun 30, 2022
1 parent 32e4f89 commit 62a540b
Show file tree
Hide file tree
Showing 52 changed files with 880 additions and 1,230 deletions.
4 changes: 4 additions & 0 deletions contracts/Anchor.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ program = "../deps/solana-program-library/target/deploy/spl_token.so"
address = "metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s"
program = "../deps/metaplex-program-library/token-metadata/target/deploy/mpl_token_metadata.so"

[[test.genesis]]
address = "WRAPYChf58WFCnyjXKJHtrPgzKXgHp6MD9aVDqJBbGh"
program = "./target/deploy/candy_wrapper.so"

[registry]
url = "https://anchor.projectserum.com"

Expand Down
17 changes: 8 additions & 9 deletions contracts/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions contracts/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
[workspace]
members = [
"programs/gummyroll",
"programs/gummyroll_crud",
"programs/bubblegum",
"programs/gumball-machine",
"programs/sugar-shack"
"programs/sugar-shack",
"programs/candy-wrapper"
]
28 changes: 25 additions & 3 deletions contracts/programs/bubblegum/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,12 @@ use {
NewNFTEvent,
NFTDecompressionEvent,
},
gummyroll::{program::Gummyroll, Node},
gummyroll::{
program::Gummyroll,
Node,
state::CandyWrapper,
utils::wrap_event,
},
crate::error::BubblegumError,
crate::utils::{append_leaf,
replace_leaf,
Expand Down Expand Up @@ -54,6 +59,7 @@ pub struct CreateTree<'info> {
#[account(mut)]
pub payer: Signer<'info>,
pub tree_creator: Signer<'info>,
pub candy_wrapper: Program<'info, CandyWrapper>,
pub system_program: Program<'info, System>,
pub gummyroll_program: Program<'info, Gummyroll>,
#[account(zero)]
Expand All @@ -72,6 +78,7 @@ pub struct MintV1<'info> {
/// CHECK: This account is neither written to nor read from.
#[account(mut)]
pub authority: Account<'info, Nonce>,
pub candy_wrapper: Program<'info, CandyWrapper>,
pub gummyroll_program: Program<'info, Gummyroll>,
/// CHECK: This account is neither written to nor read from.
pub owner: AccountInfo<'info>,
Expand All @@ -90,6 +97,7 @@ pub struct Burn<'info> {
)]
/// CHECK: This account is neither written to nor read from.
pub authority: Account<'info, Nonce>,
pub candy_wrapper: Program<'info, CandyWrapper>,
pub gummyroll_program: Program<'info, Gummyroll>,
/// CHECK: This account is checked in the instruction
pub owner: UncheckedAccount<'info>,
Expand All @@ -114,6 +122,7 @@ pub struct Transfer<'info> {
pub delegate: UncheckedAccount<'info>,
/// CHECK: This account is neither written to nor read from.
pub new_owner: UncheckedAccount<'info>,
pub candy_wrapper: Program<'info, CandyWrapper>,
pub gummyroll_program: Program<'info, Gummyroll>,
#[account(mut)]
/// CHECK: This account is modified in the downstream program
Expand All @@ -133,6 +142,7 @@ pub struct Delegate<'info> {
pub previous_delegate: UncheckedAccount<'info>,
/// CHECK: This account is neither written to nor read from.
pub new_delegate: UncheckedAccount<'info>,
pub candy_wrapper: Program<'info, CandyWrapper>,
pub gummyroll_program: Program<'info, Gummyroll>,
#[account(mut)]
/// CHECK: This account is modified in the downstream program
Expand All @@ -154,6 +164,7 @@ pub struct Redeem<'info> {
)]
/// CHECK: This account is neither written to nor read from.
pub authority: Account<'info, Nonce>,
pub candy_wrapper: Program<'info, CandyWrapper>,
pub gummyroll_program: Program<'info, Gummyroll>,
#[account(mut)]
pub owner: Signer<'info>,
Expand Down Expand Up @@ -185,6 +196,7 @@ pub struct CancelRedeem<'info> {
)]
/// CHECK: This account is neither written to nor read from.
pub authority: Account<'info, Nonce>,
pub candy_wrapper: Program<'info, CandyWrapper>,
pub gummyroll_program: Program<'info, Gummyroll>,
#[account(mut)]
/// CHECK: unsafe
Expand Down Expand Up @@ -286,6 +298,7 @@ pub struct Compress<'info> {
pub token_metadata_program: UncheckedAccount<'info>,
/// CHECK:
pub token_program: UncheckedAccount<'info>,
pub candy_wrapper: Program<'info, CandyWrapper>,
pub gummyroll_program: Program<'info, Gummyroll>,
}

Expand Down Expand Up @@ -343,6 +356,7 @@ pub mod bubblegum {
authority: ctx.accounts.authority.to_account_info(),
append_authority: ctx.accounts.tree_creator.to_account_info(),
merkle_roll: merkle_slab,
candy_wrapper: ctx.accounts.candy_wrapper.to_account_info(),
},
authority_pda_signer,
);
Expand Down Expand Up @@ -380,11 +394,13 @@ pub mod bubblegum {
data_hash.to_bytes(),
creator_hash.to_bytes(),
);
emit!(NewNFTEvent {
let new_nft = NewNFTEvent {
version: Version::V1,
metadata: message,
nonce: nonce.count
});
};
emit!(new_nft);
wrap_event(new_nft.try_to_vec()?, &ctx.accounts.candy_wrapper)?;
emit!(leaf.to_event());
nonce.count = nonce.count.saturating_add(1);
append_leaf(
Expand All @@ -394,6 +410,7 @@ pub mod bubblegum {
&ctx.accounts.authority.to_account_info(),
&ctx.accounts.mint_authority.to_account_info(),
&ctx.accounts.merkle_slab.to_account_info(),
&ctx.accounts.candy_wrapper.to_account_info(),
leaf.to_node(),
)
}
Expand Down Expand Up @@ -438,6 +455,7 @@ pub mod bubblegum {
&ctx.accounts.gummyroll_program.to_account_info(),
&ctx.accounts.authority.to_account_info(),
&ctx.accounts.merkle_slab.to_account_info(),
&ctx.accounts.candy_wrapper.to_account_info(),
ctx.remaining_accounts,
root,
previous_leaf.to_node(),
Expand Down Expand Up @@ -476,6 +494,7 @@ pub mod bubblegum {
&ctx.accounts.gummyroll_program.to_account_info(),
&ctx.accounts.authority.to_account_info(),
&ctx.accounts.merkle_slab.to_account_info(),
&ctx.accounts.candy_wrapper.to_account_info(),
ctx.remaining_accounts,
root,
previous_leaf.to_node(),
Expand Down Expand Up @@ -513,6 +532,7 @@ pub mod bubblegum {
&ctx.accounts.gummyroll_program.to_account_info(),
&ctx.accounts.authority.to_account_info(),
&ctx.accounts.merkle_slab.to_account_info(),
&ctx.accounts.candy_wrapper.to_account_info(),
ctx.remaining_accounts,
root,
previous_leaf.to_node(),
Expand Down Expand Up @@ -543,6 +563,7 @@ pub mod bubblegum {
&ctx.accounts.gummyroll_program.to_account_info(),
&ctx.accounts.authority.to_account_info(),
&ctx.accounts.merkle_slab.to_account_info(),
&ctx.accounts.candy_wrapper.to_account_info(),
ctx.remaining_accounts,
root,
previous_leaf.to_node(),
Expand Down Expand Up @@ -576,6 +597,7 @@ pub mod bubblegum {
&ctx.accounts.gummyroll_program.to_account_info(),
&ctx.accounts.authority.to_account_info(),
&ctx.accounts.merkle_slab.to_account_info(),
&ctx.accounts.candy_wrapper.to_account_info(),
ctx.remaining_accounts,
root,
[0; 32],
Expand Down
4 changes: 4 additions & 0 deletions contracts/programs/bubblegum/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ pub fn replace_leaf<'info>(
gummyroll_program: &AccountInfo<'info>,
authority: &AccountInfo<'info>,
merkle_roll: &AccountInfo<'info>,
candy_wrapper: &AccountInfo<'info>,
remaining_accounts: &[AccountInfo<'info>],
root_node: Node,
previous_leaf: Node,
Expand All @@ -28,6 +29,7 @@ pub fn replace_leaf<'info>(
gummyroll::cpi::accounts::Modify {
authority: authority.clone(),
merkle_roll: merkle_roll.clone(),
candy_wrapper: candy_wrapper.clone(),
},
authority_pda_signer,
)
Expand All @@ -42,6 +44,7 @@ pub fn append_leaf<'info>(
authority: &AccountInfo<'info>,
append_authority: &AccountInfo<'info>,
merkle_roll: &AccountInfo<'info>,
candy_wrapper: &AccountInfo<'info>,
leaf_node: Node,
) -> Result<()> {
let seeds = &[seed.as_ref(), &[bump]];
Expand All @@ -52,6 +55,7 @@ pub fn append_leaf<'info>(
authority: authority.clone(),
append_authority: append_authority.clone(),
merkle_roll: merkle_roll.clone(),
candy_wrapper: candy_wrapper.clone(),
},
authority_pda_signer,
);
Expand Down
20 changes: 20 additions & 0 deletions contracts/programs/candy-wrapper/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
[package]
name = "candy-wrapper"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[lib]
crate-type = ["cdylib", "lib"]
name = "candy_wrapper"

[features]
no-entrypoint = []
no-idl = []
no-log-ix-name = []
cpi = ["no-entrypoint"]
default = []


[dependencies]
solana-program = "1.10.1"
25 changes: 25 additions & 0 deletions contracts/programs/candy-wrapper/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
use solana_program::{
account_info::AccountInfo, declare_id, entrypoint, entrypoint::ProgramResult,
instruction::Instruction, pubkey::Pubkey,
};

declare_id!("WRAPYChf58WFCnyjXKJHtrPgzKXgHp6MD9aVDqJBbGh");

#[cfg(not(feature = "no-entrypoint"))]
entrypoint!(wrap);

fn wrap(
_program_id: &Pubkey,
_accounts: &[AccountInfo],
_instruction_data: &[u8],
) -> ProgramResult {
Ok(())
}

pub fn wrap_instruction(data: Vec<u8>) -> Instruction {
Instruction {
program_id: crate::id(),
accounts: vec![],
data,
}
}
12 changes: 11 additions & 1 deletion contracts/programs/gumball-machine/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ use bubblegum::program::Bubblegum;

use bubblegum::state::metaplex_adapter::MetadataArgs;
use bytemuck::cast_slice_mut;
use gummyroll::program::Gummyroll;
use gummyroll::{
program::Gummyroll, state::CandyWrapper,
};
use spl_token::native_mint;
pub mod state;
pub mod utils;
Expand All @@ -37,6 +39,7 @@ pub struct InitGumballMachine<'info> {
/// CHECK: Tree authority to the merkle slab, PDA owned by BubbleGum
#[account(mut)]
bubblegum_authority: AccountInfo<'info>,
candy_wrapper: Program<'info, CandyWrapper>,
gummyroll: Program<'info, Gummyroll>,
/// CHECK: Empty merkle slab
#[account(zero)]
Expand Down Expand Up @@ -91,6 +94,7 @@ pub struct DispenseSol<'info> {
/// This key must sign for all write operations to the NFT Metadata stored in the Merkle slab
#[account(mut)]
bubblegum_authority: AccountInfo<'info>,
candy_wrapper: Program<'info, CandyWrapper>,
gummyroll: Program<'info, Gummyroll>,
/// CHECK: Validation occurs in Gummyroll
#[account(mut)]
Expand Down Expand Up @@ -129,6 +133,7 @@ pub struct DispenseToken<'info> {
/// This key must sign for all write operations to the NFT Metadata stored in the Merkle slab
#[account(mut)]
bubblegum_authority: AccountInfo<'info>,
candy_wrapper: Program<'info, CandyWrapper>,
gummyroll: Program<'info, Gummyroll>,
/// CHECK: Validation occurs in Gummyroll
#[account(mut)]
Expand Down Expand Up @@ -228,6 +233,7 @@ fn find_and_mint_compressed_nft<'info>(
gummyroll: &Program<'info, Gummyroll>,
merkle_slab: &AccountInfo<'info>,
bubblegum: &Program<'info, Bubblegum>,
candy_wrapper_program: &Program<'info, CandyWrapper>,
num_items: u64,
) -> Result<GumballMachineHeader> {
// Prevent atomic transaction exploit attacks
Expand Down Expand Up @@ -272,6 +278,7 @@ fn find_and_mint_compressed_nft<'info>(
bubblegum::cpi::accounts::MintV1 {
mint_authority: willy_wonka.to_account_info(),
authority: bubblegum_authority.to_account_info(),
candy_wrapper: candy_wrapper_program.to_account_info(),
gummyroll_program: gummyroll.to_account_info(),
owner: payer.to_account_info(),
delegate: payer.to_account_info(),
Expand Down Expand Up @@ -360,6 +367,7 @@ pub mod gumball_machine {
bubblegum::cpi::accounts::CreateTree {
tree_creator: ctx.accounts.willy_wonka.to_account_info(),
authority: ctx.accounts.bubblegum_authority.to_account_info(),
candy_wrapper: ctx.accounts.candy_wrapper.to_account_info(),
gummyroll_program: ctx.accounts.gummyroll.to_account_info(),
merkle_slab: ctx.accounts.merkle_slab.to_account_info(),
payer: ctx.accounts.creator.to_account_info(),
Expand Down Expand Up @@ -515,6 +523,7 @@ pub mod gumball_machine {
&ctx.accounts.gummyroll,
&ctx.accounts.merkle_slab,
&ctx.accounts.bubblegum,
&ctx.accounts.candy_wrapper,
num_items,
)?;

Expand Down Expand Up @@ -557,6 +566,7 @@ pub mod gumball_machine {
&ctx.accounts.gummyroll,
&ctx.accounts.merkle_slab,
&ctx.accounts.bubblegum,
&ctx.accounts.candy_wrapper,
num_items,
)?;

Expand Down
1 change: 1 addition & 0 deletions contracts/programs/gummyroll/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ default = []
anchor-lang = { path="../../../deps/anchor/lang" }
bytemuck = "1.8.0"
concurrent-merkle-tree = { path="../../../lib/concurrent-merkle-tree", features = [ "sol-log" ]}
candy-wrapper = { path="../candy-wrapper", features = [ "no-entrypoint" ]}

[profile.release]
overflow-checks = true
Loading

0 comments on commit 62a540b

Please sign in to comment.