metaplex-foundation/metaplex-program-library

[Bug]: mpl-bubblegum/createVerifyCreatorInstruction: Error using concurrent merkle tree: Invalid root recomputed from proof

brennoflavio opened this issue · 4 comments

Which package is this bug report for?

token-metadata

Which Type of Package is this bug report for?

JS SDK

Issue description

When verifying the creator for a compressed NFT using the instruction generated by createVerifyCreatorInstruction, we'll get the error described bellow.

To reproduce it:

  • Mint a compressed NFT with a creator unverified
  • Generate the instruction (snippet bellow)
  • When signing and sending the transaction, you'll get the log output bellow

I tested the following scenarios:

  • Using the same metadata that was used when creating NFT and the data hash retrieved on chain
    Result: The following error
    'Program BGUMAp9Gq7iTEuizy4pqaxsTyUCBK68MDfK752saRPUY invoke [1]',
    'Program log: Instruction: VerifyCreator',
    'Program log: AnchorError occurred. Error Code: DataHashMismatch. Error Number: 6010. Error Message: User-provided metadata must result in same user-provided data hash.',
    'Program BGUMAp9Gq7iTEuizy4pqaxsTyUCBK68MDfK752saRPUY consumed 15263 of 200000 compute units',
    'Program BGUMAp9Gq7iTEuizy4pqaxsTyUCBK68MDfK752saRPUY failed: custom program error: 0x177a'
  • Using the same metadata that was used when creating NFT and the data hash computed using the function computeDataHash
    Result: The following error
    'Program log: Error using concurrent merkle tree: Invalid root recomputed from proof',
    'Program log: AnchorError thrown in programs/account-compression/src/lib.rs:273. Error Code: ConcurrentMerkleTreeError. Error Number: 6001. Error Message: Concurrent merkle tree error.',

I also tested variations like setting the creator as verified inside metadata JSON, sendind / not sending anchorRemainingAccounts, but those does not seem to affect this result.

Here is a code snipped on how I'm generating the instructions for the following NFT: AieFedBw3mqmEuAL3VHwE3c5JhurtfabREFTkzzSdGku

const hardcodedMetadata = {
    name: "My first Mint API NFT",
    symbol: "",
    uri: "https://nftstorage.link/ipfs/Qmc3GJVdk6sTEyqB8t9HkqXiPcwrJoeWNnKJqNzrVTK4ER",
    sellerFeeBasisPoints: 0,
    tokenStandard: 0,
    tokenProgramVersion: 0,
    primarySaleHappened: false,
    isMutable: true,
    creators: [
        {
            address: new PublicKey("A8ZykbnhDXjQoNJbtZLrydUVKbrm1UigdwWGiiPciZVY"),
            share: 100,
            verified: false,
        },
    ],
    editionNonce: null,
    uses: null,
    collection: {
        verified: false,
        key: new PublicKey("F5U2ht8qiPKwam3zB5tNxs3eCmyRxHvkZYsNkWq9QKVH"),
    },
};

const hardcodedDataHash = Array.from(computeDataHash(hardcodedMetadata));

[...]

const treeAuthority = treeAccount.getAuthority();
const canopyDepth = treeAccount.getCanopyDepth();

const proof: AccountMeta[] = assetProof.proof
    .slice(0, assetProof.proof.length - (!!canopyDepth ? canopyDepth : 0))
    .map((node: PublicKey) => ({
        pubkey: node,
        isSigner: false,
        isWritable: false,
    }));

const verifyCreatorInstruction = createVerifyCreatorInstruction(
    {
        treeAuthority,
        leafOwner: new PublicKey(asset.ownership.owner),
        leafDelegate: new PublicKey(asset.ownership.delegate),
        merkleTree,
        payer,
        creator: creatorAddress,
        logWrapper: SPL_NOOP_PROGRAM_ID,
        compressionProgram: SPL_ACCOUNT_COMPRESSION_PROGRAM_ID,
        anchorRemainingAccounts: proof,
    },
    {
        root,
        dataHash: hardcodedDataHash,
        creatorHash,
        nonce,
        index,
        message: hardcodedMetadata,
    }
);

Relevant log output

AggregateErrorChild(index 3) SendTransactionError: failed to send transaction: Transaction simulation failed: Error processing Instruction 0: custom program error: 0x1771
    at SolanaConnectionAdapter.sendEncodedTransaction (/home/brenno/github/crossbit-main/node_modules/@solana/web3.js/lib/index.cjs.js:9754:13)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at async SolanaConnectionAdapter.sendRawTransaction (/home/brenno/github/crossbit-main/node_modules/@solana/web3.js/lib/index.cjs.js:9711:20)
    at async eval (webpack-internal:///(api)/./services/solana/MultiRpcSolanaConnectionAdapter.ts:31:24)
    at async Promise.any (index 3)
    at async MultiRpcSolanaConnectionAdapter.sendRawTransaction (webpack-internal:///(api)/./services/solana/MultiRpcSolanaConnectionAdapter.ts:66:41)
    at async Function.sendAndConfirmRawTransaction (webpack-internal:///(api)/./services/solana/SolanaAdapter.ts:530:22)
    at async Function.sendSignedTransaction (webpack-internal:///(api)/./services/solana/SolanaAdapter.ts:605:18)
    at async processInstructions (webpack-internal:///(api)/./pages/api/actions/mintAPI/update/verifyCreator.ts:115:29)
    at async eval (webpack-internal:///(api)/./pages/api/actions/mintAPI/update/verifyCreator.ts:49:89)
    at async Promise.all (index 0)
    at async eval (webpack-internal:///(api)/./pages/api/actions/mintAPI/update/verifyCreator.ts:49:5)
    at async eval (webpack-internal:///(api)/./utils/api/apiHandler.ts:255:9)
    at async handle (webpack-internal:///(api)/./utils/api/handlers/apiHandler.ts:31:40)
    at async eval (webpack-internal:///(api)/./utils/api/handlers/apiHandler.ts:48:9) {
  logs: [
    'Program BGUMAp9Gq7iTEuizy4pqaxsTyUCBK68MDfK752saRPUY invoke [1]',
    'Program log: Instruction: VerifyCreator',
    'Program noopb9bkMVfRPU8AsbpTUg8AQkHtKwMYZiFUjNRtMmV invoke [2]',
    'Program noopb9bkMVfRPU8AsbpTUg8AQkHtKwMYZiFUjNRtMmV consumed 97 of 182163 compute units',
    'Program noopb9bkMVfRPU8AsbpTUg8AQkHtKwMYZiFUjNRtMmV success',
    'Program cmtDvXumGCrqC1Age74AVPhSRVXJMd8PJS91L8KbNCK invoke [2]',
    'Program log: Instruction: ReplaceLeaf',
    'Program log: Attempting to fill in proof',
    'Program consumption: 155755 units remaining',
    'Program log: Active Index: 33',
    'Program log: Rightmost Index: 97',
    'Program log: Buffer Size: 64',
    'Program log: Leaf Index: 0',
    'Program log: Fast-forwarding proof, starting index 33',
    'Program consumption: 152818 units remaining',
    'Program consumption: 152714 units remaining',
    'Program log: Error using concurrent merkle tree: Invalid root recomputed from proof',
    'Program log: AnchorError thrown in programs/account-compression/src/lib.rs:273. Error Code: ConcurrentMerkleTreeError. Error Number: 6001. Error Message: Concurrent merkle tree error.',
    'Program cmtDvXumGCrqC1Age74AVPhSRVXJMd8PJS91L8KbNCK consumed 28849 of 175371 compute units',
    'Program cmtDvXumGCrqC1Age74AVPhSRVXJMd8PJS91L8KbNCK failed: custom program error: 0x1771',
    'Program BGUMAp9Gq7iTEuizy4pqaxsTyUCBK68MDfK752saRPUY consumed 53478 of 200000 compute units',
    'Program BGUMAp9Gq7iTEuizy4pqaxsTyUCBK68MDfK752saRPUY failed: custom program error: 0x1771'
  ]
}

Priority this issue should have

Medium (should be fixed soon)

Taking a look at this

Hey, @danenbm, you don't need to. There was an issue with the metadata object (need to ser the collection as verified) and the nonce calculation was wrong aswell (it should be the same as the index). Those changes made this snippet work.

I'll close the issue!

Hey, @danenbm, you don't need to. There was an issue with the metadata object (need to ser the collection as verified) and the nonce calculation was wrong aswell (it should be the same as the index). Those changes made this snippet work.

I'll close the issue!

Ok great thank you for the update!!!