Skip to main content

Documentation Index

Fetch the complete documentation index at: https://docs.skale.space/llms.txt

Use this file to discover all available pages before exploring further.

Compiler requirements: Solidity >= 0.8.27, EVM version istanbul or lower.
The BITE Solidity SDK (@skalenetwork/bite-solidity) provides smart contract interfaces for creating Conditional Transactions (CTX), encrypting data onchain, and handling decryption callbacks.

Installation

# npm
npm i @skalenetwork/bite-solidity

# forge
forge install skalenetwork/bite-solidity
echo "@skalenetwork/bite-solidity/=lib/bite-solidity/" >> remappings.txt

Imports

import { BITE } from "@skalenetwork/bite-solidity/BITE.sol";
import { IBiteSupplicant }
    from "@skalenetwork/bite-solidity/interfaces/IBiteSupplicant.sol";

BITE.submitCTX()

Creates a Conditional Transaction that requests decryption of encrypted data. The decrypted result is delivered to your contract’s onDecrypt callback in the next block.
function submitCTX(
    address precompileAddress,  // use BITE.SUBMIT_CTX_ADDRESS
    uint256 gasLimit,           // gas allocated for the callback
    bytes[] memory encryptedArgs,   // encrypted data to decrypt
    bytes[] memory plaintextArgs    // plaintext data to pass through
) external payable returns (address payable);
Returns: The address of the ephemeral wallet that will call onDecrypt. Each call generates a unique address. Parameters:
  • precompileAddress: Use BITE.SUBMIT_CTX_ADDRESS (0x1B)
  • gasLimit: Gas for callback (in gas units, use msg.value / tx.gasprice)
  • encryptedArgs: Array of encrypted byte arrays to decrypt
  • plaintextArgs: Array of unencrypted byte arrays passed through to callback

Example

pragma solidity ^0.8.24;

import { BITE } from "@skalenetwork/bite-solidity/BITE.sol";
import { IBiteSupplicant }
    from "@skalenetwork/bite-solidity/interfaces/IBiteSupplicant.sol";
import { Address } from "@openzeppelin/contracts/utils/Address.sol";

contract MyContract is IBiteSupplicant {
    using Address for address payable;

    mapping(address => bool) private _canCallOnDecrypt;

    function revealSecret(bytes calldata encrypted) external payable {
        bytes[] memory encryptedArgs = new bytes[](1);
        encryptedArgs[0] = encrypted;

        address payable ctxSender = BITE.submitCTX(
            BITE.SUBMIT_CTX_ADDRESS,
            msg.value / tx.gasprice,
            encryptedArgs,
            new bytes[](0)
        );

        _canCallOnDecrypt[ctxSender] = true;
        payable(ctxSender).sendValue(msg.value);
    }

    function onDecrypt(
        bytes[] calldata decryptedArgs,
        bytes[] calldata
    ) external override {
        require(_canCallOnDecrypt[msg.sender], "Unauthorized");
        _canCallOnDecrypt[msg.sender] = false;
        // Use decryptedArgs[0] in your logic
    }
}

IBiteSupplicant.onDecrypt()

Callback that your contract must implement. Called by SKALE consensus with decrypted data in the block after submitCTX.
function onDecrypt(
    bytes[] calldata decryptedArgs,  // decrypted versions of encryptedArgs
    bytes[] calldata plaintextArgs   // plaintextArgs passed through
) external;
Security: Always restrict access to only authorized ephemeral wallets using a mapping(address => bool) pattern. See Security: Protect onDecrypt.

BITE.encryptTE()

Encrypts data using the network’s BLS threshold key. Only the validator committee can decrypt (via CTX callback).
function encryptTE(
    address precompileAddress,  // use BITE.ENCRYPT_TE_ADDRESS (0x1D)
    bytes memory data           // data to encrypt (32-byte aligned)
) external returns (bytes memory encrypted, uint256 errorCode);
Error Codes:
CodeError
1InputTooLarge
2InputTooShort
3InputNot32ByteAligned
4InvalidDataOffset
5DataLengthMismatch
6TrailingPaddingNotZeros

BITE.encryptECIES()

Encrypts data for a specific viewer’s secp256k1 public key. Only the holder of the corresponding private key can decrypt off-chain.
function encryptECIES(
    address precompileAddress,  // use BITE.ENCRYPT_ECIES_ADDRESS (0x1C)
    bytes memory data,          // data to encrypt
    PublicKey memory publicKey  // viewer's public key (x, y)
) external returns (bytes memory encrypted, uint256 errorCode);
Error Codes:
CodeError
1-6Same as EncryptTE
7InvalidPublicKey
8EncryptionFailed

PublicKey Struct

struct PublicKey {
    bytes32 x;
    bytes32 y;
}
The public key is an uncompressed secp256k1 point (without the 0x04 prefix).

Constants

ConstantAddressDescription
BITE.SUBMIT_CTX_ADDRESS0x1BCTX precompile for requesting decryption
BITE.ENCRYPT_TE_ADDRESS0x1DThreshold encryption precompile
BITE.ENCRYPT_ECIES_ADDRESS0x1CECIES encryption precompile

Resources