HDP Module

HDP Is the Herodotus Data Processor, it is what allows us to in a cryptographically verifiable manner, check what data is a available on another chain, via a storage proof system.

Contract

The contract is implemented as a Starknet module. It uses the HDP Cairo library for interacting with EVM storage, and Keccak to compute storage slots for Solidity mappings.

If you're curious about why we need to calculate storage slots, you can learn more about how storage works in Solidity smart contracts here.

Fulfillment records are stored in a Solidity mapping within the Payment Registry. In Solidity, a mapping value is stored at slot keccak(abi.encode(key, mappingSlotIndex)). In our case:

  • key is the fulfillment_keccak_hash from each order (u256)

  • mappingSlotIndex is a constant FULFILLMENTS_MAPPING_SLOT = 2 (from the Payment Registry storage layout)

We compute keccak(encode(fulfillment_keccak_hash, 2)) to derive the storage slot for each order’s fulfillment record.

Main Function

This is the core verification function which iterates through a set of fulfilled intents and checks whether each one has been successfully recorded in the Payment Registry contract. It takes in parameters like the HDP module instance for storage access, the destination chain id, the payment registry address on which the fulfillment was made, the block number, which acts as the point in time, and the array of orders that have been fulfilled.

Workflow

  1. The function initializes is_verified_correctly to true.

  2. It iterates over the provided orders and computes the EVM storage slot for each order’s fulfillment status using Keccak:

let mut bytes: Bytes = BytesTrait::new(0, array![]);
bytes.append_u256(order.fulfillment_keccak_hash);
bytes.append_u256(FULFILLMENTS_MAPPING_SLOT); // 2
let slot = bytes.keccak();
  1. It queries the HDP EVM storage module for the slot’s value:

let storage_slot_value = hdp.evm.storage_get_slot(
    @StorageKey {
        chain_id: destination_chain_id,
        block_number: block_number.into(),
        address: payment_registry_address,
        storage_slot: slot,
    },
);
  1. If the retrieved value is zero, it means the fulfillment has not been recorded (the mapping stores the MM’s source address as a non-zero bytes32). In that case, is_verified_correctly is set to false.

  2. The function returns true if all fulfillment records are present (non-zero), otherwise false.

Data Structures

  • OrderData { fulfillment_keccak_hash: u256 }: the key used to look up each order’s fulfillment status in the Payment Registry mapping.

Using the HDP Module

This HDP Module, is what is called from our Escrow smart contract on the source chain when the MM claims that they have fulfilled a certain intent. This HDP Module Ensures successful fulfillments in cross-chain operations by verifying state commitments on the destination chain, and allows the MM to safely unlock the funds locked on the source chain, as a repayment for facilitating the cross chain transfer.

Last updated