Precompiles

On the Hyperstate network, all Bitcoin precompiles are found at address 0x0000000000000000000000000000000000000999 this address accepts a bytes payload of data. The payload consists of a 'method identifier' with correlates to the specific the Bitcoin action that should be performed. Some method identifiers require additional data to be passed so the specific Bitcoin action indicated can be completed. For example if you want to broadcast a transaction on Bitcoin, you need to provide the signed Bitcoin transaction to be executed. Reference the table below for all available method identifiers and their data requirements.

Additionally, import https://github.com/OnCorsa/corsa-contracts to import and use these precompiles in your solidity contracts.

Available Precompiles

Name
Method ID (bytes)
Data (bytes)
Description

sendrawtransaction

0x00000000

Signed raw transaction data

Sends a raw Bitcoin transaction

getblockcount

0x00000001

N/A

Retrieves the current block count

decoderawtransaction

0x00000002

Signed raw transaction data

Decodes a raw Bitcoin transaction

verifysignature

0x00000003

Signed raw transaction data

Verifies the signature of a Bitcoin transaction

Usage

For Foundry users, one way to interact with the precompile is to use cast. Below are examples for each precompile call using cast. Another way is to import corsa-contracts as a dependency in your smart contract.

import {ERC721} from "@corsa/corsa-contracts/precompiles/PrecompileHelpers.sol";

sendrawtransaction

  • Gas Cost: 10,000 + 3 * input.len()

  • Gas Limit: 100,000

Note: --data is prefixed with 0x00000000. After the prefix is the raw signed btc transaction.

cast call 0x0000000000000000000000000000000000000999 \
--data 0x0000000002000000000101b161898f2ef6bd36e1cee4b9d68c5a1937a5001306e81a0fc30e99b44e8f835a00000000000000000001c0aff629010000001600148267b14c9fc90545c5828cbb9d26e12a9ecb8c160247304402205709263844829d625759b202ecf8d85fc6a2c07f958555d5b32c98e9c8b33c8a02200a6132106329e8dcc9c54bc7444075a90f505909bffb63b65f93257cbe23c9040121025912be1b355b604d151f36348c91976c4cda0c3c9c7fcb4469cdf0213fa216e900000000 \
--rpc-url http://localhost:8545

getblockcount

  • Gas Cost: 2000

  • Gas Limit: N/A

Note: using the --data flag is not necessary. Simply pass the method id.

cast call 0x0000000000000000000000000000000000000999 \
0x00000001 \
--rpc-url http://localhost:8545

decoderawsignature

  • Gas Cost: 4000 + 3 * input.len()

  • Gas Limit: 100,000

Note: --data is prefixed with 0x00000002. After the prefix is the raw signed btc transaction to decode.

cast call 0x0000000000000000000000000000000000000999 \
--data 0x0000000202000000000101b161898f2ef6bd36e1cee4b9d68c5a1937a5001306e81a0fc30e99b44e8f835a00000000000000000001c0aff629010000001600148267b14c9fc90545c5828cbb9d26e12a9ecb8c160247304402205709263844829d625759b202ecf8d85fc6a2c07f958555d5b32c98e9c8b33c8a02200a6132106329e8dcc9c54bc7444075a90f505909bffb63b65f93257cbe23c9040121025912be1b355b604d151f36348c91976c4cda0c3c9c7fcb4469cdf0213fa216e900000000 \
--rpc-url http://localhost:8545

verifysignature

  • Gas Cost: 6,000 + 3 * input.len()

  • Gas Limit: 100,000

Note: --data is prefixed with 0x00000003. After the prefix is the raw signed btc transaction to verify.

cast call 0x0000000000000000000000000000000000000999 \
--data 0x0000000302000000000101b161898f2ef6bd36e1cee4b9d68c5a1937a5001306e81a0fc30e99b44e8f835a00000000000000000001c0aff629010000001600148267b14c9fc90545c5828cbb9d26e12a9ecb8c160247304402205709263844829d625759b202ecf8d85fc6a2c07f958555d5b32c98e9c8b33c8a02200a6132106329e8dcc9c54bc7444075a90f505909bffb63b65f93257cbe23c9040121025912be1b355b604d151f36348c91976c4cda0c3c9c7fcb4469cdf0213fa216e900000000 \
--rpc-url http://localhost:8545

Last updated