# Smart Contract Support

IBVM provides full EVM compatibility, allowing developers to deploy and execute Solidity smart contracts.

## Contract Deployment

To deploy a contract on IBVM:

1. Compile Solidity code to EVM bytecode
2. Submit a deployment transaction with:
   1. Zero recipient address
   2. Contract bytecode as data
   3. Initial value (if any)
3. The system creates a new contract account with:
   1. Address: $Address = H(sender || nonce)$
   2. Code: The deployed bytecode
   3. Storage: Initialized empty
   4. Balance: The transferred value

## Contract Execution

Smart contracts on IBVM execute using the same semantics as Ethereum:

1. Contracts can be called by users or other contracts
2. Execution follows EVM rules and opcodes
3. Gas limits prevent infinite loops or excessive computation
4. State changes are applied atomically

## Bitcoin-Specific Precompiles

IBVM extends the standard EVM precompiled contracts with Bitcoin-specific functions:

1. BTCVerify (0x10): Verify Bitcoin signatures
   1. Input: Bitcoin public key, signature, message
   2. Cost: 3000 gas
2. BTCHash (0x11): Bitcoin-style double-SHA256 hashing
   1. Input: Data to hash
   2. Cost: 30 + 6 \* (data length / 32) gas
3. BTCTxVerify (0x12): Verify Bitcoin transaction inclusion
   1. Input: Transaction, block header, Merkle proof
   2. Cost: 25000 gas

Implementation example for BTC Verify:

```
function verifyBitcoinSignature(
 bytes memory pubkey,
    bytes memory signature,
    bytes32 messageHash
) public view returns (bool) {
    (bool success, bytes memory result) = address(0x10).staticcall(
        abi.encodePacked(pubkey, signature, messageHash)
    );
    require(success, "BTCVerify call failed");
    return abi.decode(result, (bool));
}
```

&#x20; &#x20;

## Interoperability Features

IBVM includes special features for Bitcoin interoperability:

1. BTC Bridge Contract: Interface for deposit/withdrawal of BTC
   1. deposit(address recipient): Records BTC deposits
   2. withdraw(uint256 amount, bytes btcAddress): Initiates withdrawals
2. BTCRelay Contract: Tracks Bitcoin headers and validates proofs
   1. submitBlockHeader(bytes header): Submits new Bitcoin headers
   2. verifyTx(bytes txBytes, bytes proof, uint256 blockHeight): Verifies transactions
3. Fee Market Contract: Manages the dynamic fee mechanism
   1. getCurrentBaseFee(): Returns current base fee
   2. estimateGasPrice(uint256 priority): Estimates gas price for desired priority


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://ibvm.gitbook.io/ibvm-doc/smart-contract-support.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
