Assertions

Assert Merkle Tree Account

AssertAccountDelta Instruction

The AssertMerkleTreeAccount instruction is a wrapper for the verify_leaf instruction for the spl-account-compression program. The one advantage it has over the verify leaf instruction is that you can pass in a dummy account in as the root instead of needing to pass a [u8; 32] as the instruction root argument if you had called verify_leaf instruction directly.

Using this over verify_leaf instruction saves 31 bytes (32 bytes reduced to 1 byte if you use an account that already exists in the transaction) but incurs a large CU cost for the CPI. The reason you can pass in an arbitrary root into the spl-account-compression program is it is ignored in the instruction since the current root will always be in the merkle tree changelogs.

Example: Assert on a leaf node in a merkle tree account.

To verify leaf using Lighthouse, fetch the proof path and generate the hash of the state you expect the leaf node to have at the end of the transaction.

Verify leaf through Lighthouse instruction

const proofPath: IAccountMeta[] = []

const ix = getAssertMerkleTreeAccountInstructionRaw(
  {
    targetMerkleTree: treePubkey,
    root: treeRoot,
    splAccountCompression: splAccountCompressionProgramId,
  },
  {
    assertion: {
      __kind: 'VerifyLeaf',
      leafIndex: leafIndex,
      leafHash: expectedLeafHash,
    },
  },
  LIGHTHOUSE_PROGRAM_ADDRESS,
  proofPath
)
Previous
Upgradeable Loader Account