lockaes_gcm_encrypt

On-chain AES-256-GCM encryption

Encrypt data on-chain using Mercury EVM's AES-GCM encryption precompile.

Overview

The AES-GCM encryption precompile at address 0x66 performs AES-256-GCM authenticated encryption. The ciphertext includes a 16-byte authentication tag that ensures integrity and authenticity.

circle-info

The SeismicSignedProvider filler pipeline uses this precompile internally to encrypt calldata before sending shielded transactions. You can also call it directly for custom encryption workflows.

Precompile Address

0x0000000000000000000000000000000000000066

Input Encoding

Field
Size
Description

key

32 bytes

AES-256 encryption key

nonce

12 bytes

Unique nonce (must never be reused with the same key)

plaintext

Variable

Data to encrypt

The input is the concatenation of key (32 bytes) + nonce (12 bytes) + plaintext (variable length).

Output Format

Field
Size
Description

ciphertext

len(plaintext) bytes

Encrypted data

tag

16 bytes

Authentication tag (appended to ciphertext)

Total output length = len(plaintext) + 16.

Parameters

Parameter
Type
Required
Description

key

[u8; 32]

Yes

32-byte AES-256 encryption key

nonce

[u8; 12]

Yes

12-byte nonce (must be unique per key)

plaintext

&[u8]

Yes

Data to encrypt

Examples

Basic Usage

Encrypt with Integer Nonce

Encrypt-Decrypt Round Trip

With ECDH-Derived Key

How It Works

  1. Encode parameters -- Concatenates 32-byte key + 12-byte nonce + plaintext

  2. Call precompile -- Issues an eth_call to address 0x66 with estimated gas

  3. Encrypt data -- Precompile performs AES-256-GCM encryption

  4. Return ciphertext -- Returns encrypted data with 16-byte authentication tag appended

Gas Cost

Gas cost is calculated as:

For example:

Plaintext Size
Gas Cost

16 bytes

1030

64 bytes

1120

256 bytes

1480

Notes

  • Uses AES-256-GCM authenticated encryption

  • Nonce must be unique for each encryption with the same key

  • Ciphertext length = plaintext length + 16 bytes (authentication tag)

  • The authentication tag ensures ciphertext integrity and authenticity

  • Reusing a nonce with the same key breaks security

Warnings

  • Nonce reuse -- NEVER reuse the same nonce with the same key. This breaks confidentiality and can leak the plaintext.

  • Key security -- Keep AES keys secure and never expose them in logs or error messages

  • Authentication tag -- The 16-byte tag is appended to the ciphertext and must be included when decrypting

  • Counter management -- When using integer nonces, ensure they are sequential and never repeated

See Also

Last updated