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
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.
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.
getblockcount
Gas Cost:
2000
Gas Limit:
N/A
Note: using the
--data
flag is not necessary. Simply pass the method id.
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.
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.
Last updated