From f178b3c0bc742db5cdb4c754efdbb9fb6d8eb324 Mon Sep 17 00:00:00 2001 From: Jarry Xiao <61092285+jarry-xiao@users.noreply.github.com> Date: Thu, 30 Jun 2022 10:24:04 -0400 Subject: [PATCH] Jxiao/fix log truncation (#121) * 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 --- contracts/tests/gummyroll-test.ts | 50 +++++++++++++++---------------- 1 file changed, 24 insertions(+), 26 deletions(-) diff --git a/contracts/tests/gummyroll-test.ts b/contracts/tests/gummyroll-test.ts index 86a71376d06..083ce1c1689 100644 --- a/contracts/tests/gummyroll-test.ts +++ b/contracts/tests/gummyroll-test.ts @@ -28,8 +28,11 @@ import { getMerkleRollAccountSize, createVerifyLeafIx, assertOnChainMerkleRollProperties, + createAllocTreeIx, } from "../sdk/gummyroll"; import { execute, logTx } from "./utils"; +import NodeWallet from "@project-serum/anchor/dist/cjs/nodewallet"; +import { CANDY_WRAPPER_PROGRAM_ID } from "../sdk/utils"; // @ts-ignore let Gummyroll; @@ -60,27 +63,20 @@ describe("gummyroll", () => { } const merkleRollKeypair = Keypair.generate(); - const requiredSpace = getMerkleRollAccountSize( - maxDepth, - maxSize, - canopyDepth - ); const leaves = Array(2 ** maxDepth).fill(Buffer.alloc(32)); for (let i = 0; i < numLeaves; i++) { leaves[i] = crypto.randomBytes(32); } const tree = buildTree(leaves); - const allocAccountIx = SystemProgram.createAccount({ - fromPubkey: payer.publicKey, - newAccountPubkey: merkleRollKeypair.publicKey, - lamports: - await Gummyroll.provider.connection.getMinimumBalanceForRentExemption( - requiredSpace - ), - space: requiredSpace, - programId: Gummyroll.programId, - }); + const allocAccountIx = await createAllocTreeIx( + Gummyroll.provider.connection, + maxSize, + maxDepth, + canopyDepth, + payer.publicKey, + merkleRollKeypair.publicKey, + ); let tx = new Transaction().add(allocAccountIx); if (numLeaves > 0) { @@ -108,6 +104,7 @@ describe("gummyroll", () => { merkleRoll: merkleRollKeypair.publicKey, authority: payer.publicKey, appendAuthority: payer.publicKey, + candyWrapper: CANDY_WRAPPER_PROGRAM_ID, }, signers: [payer], remainingAccounts: proof, @@ -121,6 +118,7 @@ describe("gummyroll", () => { merkleRoll: merkleRollKeypair.publicKey, authority: payer.publicKey, appendAuthority: payer.publicKey, + candyWrapper: CANDY_WRAPPER_PROGRAM_ID, }, signers: [payer], }) @@ -260,7 +258,7 @@ describe("gummyroll", () => { try { await execute(Gummyroll.provider, [verifyLeafIx], [payer]); assert(false, "Proof should have failed to verify"); - } catch {} + } catch { } // Replace instruction with same proof fails const replaceLeafIx = createReplaceIx( @@ -276,7 +274,7 @@ describe("gummyroll", () => { try { await execute(Gummyroll.provider, [replaceLeafIx], [payer]); assert(false, "Replace should have failed to verify"); - } catch {} + } catch { } const merkleRollAccount = await Gummyroll.provider.connection.getAccountInfo( merkleRollKeypair.publicKey @@ -308,7 +306,7 @@ describe("gummyroll", () => { }) ); assert( - replaceLeafIx.keys.length == 2 + MAX_DEPTH, + replaceLeafIx.keys.length == 3 + MAX_DEPTH, `Failed to create proof for ${MAX_DEPTH}` ); @@ -348,7 +346,7 @@ describe("gummyroll", () => { }) ); assert( - replaceLeafIx.keys.length == 2 + 1, + replaceLeafIx.keys.length == 3 + 1, "Failed to minimize proof to expected size of 1" ); await execute(Gummyroll.provider, [replaceLeafIx], [payer]); @@ -403,7 +401,7 @@ describe("gummyroll", () => { false, "Transaction should have failed, since `randomSigner` is not append authority" ); - } catch {} + } catch { } }); it("But authority can transfer appendAuthority", async () => { const transferAppendAuthorityIx = createTransferAuthorityIx( @@ -486,7 +484,7 @@ describe("gummyroll", () => { false, "Transaction should have failed since the append authority cannot act as the authority for replaces" ); - } catch {} + } catch { } }); }); describe("Examples transferring authority", () => { @@ -530,7 +528,7 @@ describe("gummyroll", () => { false, "Transaction should have failed since incorrect authority cannot execute replaces" ); - } catch {} + } catch { } }); it("Can transfer authority", async () => { const transferAppendAuthorityIx = createTransferAuthorityIx( @@ -587,7 +585,7 @@ describe("gummyroll", () => { false, "Transaction should have failed since incorrect authority cannot execute replaces" ); - } catch {} + } catch { } }); }); }); @@ -731,7 +729,7 @@ describe("gummyroll", () => { false, "Attacker was able to succesfully write fake existence of a leaf" ); - } catch (e) {} + } catch (e) { } const merkleRoll = decodeMerkleRoll( ( @@ -772,7 +770,7 @@ describe("gummyroll", () => { false, "Attacker was able to succesfully write fake existence of a leaf" ); - } catch (e) {} + } catch (e) { } const merkleRoll = decodeMerkleRoll( ( @@ -801,7 +799,7 @@ describe("gummyroll", () => { let leaves = []; let i = 0; - let stepSize = 8; + let stepSize = 4; while (i < 2 ** DEPTH) { let ixs = []; for (let j = 0; j < stepSize; ++j) {