This repository includes the contracts implemented to perform the IBE decryption process on Arbitrum chain.
The decryption process involves 5 contracts. Below is a breakdown of each contract and their respective gas consumption:
- Functionality: Verifies the correctness of the ciphertext based on the Boneh-Franklin Identity-Based Encryption (BF-IBE) algorithm. It calculates a hash over the message and sigma, multiplies it by
P
, and verifies that the result matches theU
component in the ciphertext. - Gas Consumption: ~1,587,000
- Key Contributor: Scalar and G1 point multiplication, consuming 1,366,619 gas.
- Functionality: Decrypts the ciphertext and recovers the message (which is the symmetric key for the second layer of encryption). It leverages the IBE Contract (Hashing) for ciphertext validation.
- Gas Consumption: ~1,742,000(~1,587,000 of this comes from the IBE Contract (Hashing))
- Note: The majority of the gas consumption comes from the hashing contract.
- Functionality: Computes the MAC for the ciphertext header using the key and ciphertext body.
- Gas Consumption: ~72,000
- Note: Minimal gas usage.
- Functionality: Performs symmetric key decryption using the provided key and returns the plaintext.
- Gas Consumption: ~55,000
- Note: Minimal gas usage.
- Functionality: Serves as the main interface for the decryption process. It accepts the decryption key and ciphertext, invoking the appropriate contracts to perform the full decryption.
- Gas Consumption: ~9,189,000
- Breakdown:
- IBE, MAC, and ChaCha20 contracts: As described above.
- ~1,565,000: Deserializing the decryption key.
- ~5,445,000: Pairing operation.
- Breakdown:
This project contains multiple contracts, each with its own test scripts and examples for deployment and interaction on the blockchain. These tests demonstrate how the contracts can be used both independently and from within another contract (e.g., an application contract).
- Rust Contract: Implements a basic auction application where bids are encrypted and decrypted using decrypter contracts once the decryption key is provided. For simplicity, some checks have been removed. This example is only to demonstrate how to use the decryption contracts and is not suitable for production use.
- Solidity Contract: Implements a contract that allows the submission of encrypted messages and decrypts them once a key is submitted.
Both contracts can be tested using their respective test.sh
files in their corresponding folders.
By default, all contracts will be deployed on the Arbitrum testnet. However, the RPC URL can be modified in the test.sh
scripts if you wish to use another network.
Addresses for the deployed contracts are hardcoded in the decrypter contract and ibe contract. You can modify these addresses by replacing them with newly deployed contract addresses if necessary. Ensure that you have a private key (sk
) set to an account on the Arbitrum testnet (if testing on the testnet) that has enough funds to cover gas fees for deploying and interacting with the contracts.
Before running the tests, ensure that the following dependencies and tools are installed:
The test scripts use a specific nightly version of Rust. Install and configure Rust by running:
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
rustup install nightly-2024-05-20
rustup override set nightly-2024-05-20
You also need to install the following target:
rustup target add wasm32-unknown-unknown
Foundry is used for deploying Solidity contracts and interacting with the blockchain. Install Foundry and initialize it:
curl -L https://foundry.paradigm.xyz | bash
foundryup
Verify that both forge and cast are installed correctly:
forge --version
cast --version
Stylus is required for deploying Rust contracts. Install it via Cargo:
cargo install --force cargo-stylus
You will need a private key to interact with the blockchain. You can replace the <PRIVATE_KEY> placeholder in the scripts.
Navigate to the contract folder:
cd <contract-folder>
Run the test script:
./test.sh