solanaanchor-solana

Why are emit_cpi calls prefixed with e4 45 a5 2e 51 cb 9a 1d (hex)?


I keep seeing this pattern where if a function in an Anchor program uses emit_cpi it is always prefixed with the 8 byte discriminator e4 45 a5 2e 51 cb 9a 1d.

I'm aware that Solana Anchor programs prefix their data with the 8 byte discriminators that are the results of a pattern like global:functiona_name hashed and truncated to the first 8 bytes. Having the IDL I can map to and from the binary data.

However with the emit_cpi I'm lost. It's part of a program I can deploy to the network, but the prefix is not something that maps back to the program's IDL.

Is there a resource for emit_cpi and perhaps other prefixes and how to map them?

Here's an example transaction with the result.


Solution

  • In the coral-xyz/anchor repository there's a file lang/src/event.rs and in there there's the same byte sequence, only in reverse.

    // Sha256(anchor:event)[..8]
    pub const EVENT_IX_TAG: u64 = 0x1d9acb512ea545e4;
    pub const EVENT_IX_TAG_LE: &[u8] = EVENT_IX_TAG.to_le_bytes().as_slice();
    

    I have no idea however why is the sequence reversed with to_le_bytes(). And also they're using the anchor namespace, which again isn't documented anywhere.

    So this is where that discriminator comes from, the source.