-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Bitcoin Bridge Smart Contract Implementation #1
Open
peter-curl
wants to merge
18
commits into
main
Choose a base branch
from
implementation
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- Implemented a smart contract for bridging Bitcoin to a wrapped token (wBTC) on the Stacks blockchain. - Added error constants for various failure scenarios including authorization, invalid amounts, insufficient balance, paused bridge, duplicate transactions, and oracle validation failures. - Defined storage variables for bridge configuration and state management. - Implemented oracle management functions to add and remove authorized oracles. - Added pausing mechanism for emergency scenarios. - Implemented bridge fee management functionality. - Created functions for depositing Bitcoin with oracle validation and minting wBTC. - Added withdrawal function for burning wBTC and releasing Bitcoin. - Included read-only functions for bridge transparency and user balance checks.
- Defined `bridge-owner` to store the principal of the bridge owner. - Added `is-bridge-paused` to track the paused state of the bridge. - Introduced `total-locked-bitcoin` to keep track of the total amount of Bitcoin locked in the bridge. - Implemented `bridge-fee-percentage` to store the bridge fee percentage, initialized to 0.1%.
- Defined `authorized-oracles` map to store the principals of authorized oracles. - Added `processed-transactions` map to track processed Bitcoin transactions using their transaction hashes.
- Defined `wrapped-bitcoin` as a fungible token to represent wrapped Bitcoin (wBTC). - Added `user-balances` map to track the balance of wBTC for each user.
- Implemented a read-only function `is-bridge-owner` to check if the given sender is the bridge owner.
- Implemented `add-oracle` function to add a new oracle, ensuring only the bridge owner can perform this action. - Implemented `remove-oracle` function to remove an oracle, ensuring only the bridge owner can perform this action.
- Implemented `pause-bridge` function to pause the bridge, ensuring only the bridge owner can perform this action. - Implemented `unpause-bridge` function to unpause the bridge, ensuring only the bridge owner can perform this action.
- Implemented `update-bridge-fee` function to update the bridge fee percentage, ensuring only the bridge owner can perform this action. - Added validation to ensure the new fee is less than 100%.
- Implemented `get-user-balance-amount` function to retrieve the balance of a user from the `user-balances` map. - Returns the balance amount if it exists, otherwise returns 0.
- Implemented `deposit-bitcoin` function to handle Bitcoin deposits and mint wrapped Bitcoin tokens (wBTC). - Calculates the bridge fee and net amount to be minted. - Ensures the bridge is not paused before proceeding. - Validates that the Bitcoin transaction has not been processed before. - Simulates oracle validation for the Bitcoin transaction. - Mints the net amount of wBTC to the recipient. - Marks the Bitcoin transaction as processed. - Updates the total locked Bitcoin amount.
- Implemented `withdraw-bitcoin` function to handle the withdrawal process by burning wrapped Bitcoin tokens (wBTC) and releasing the equivalent Bitcoin. - Calculates the bridge fee and net amount to be released. - Ensures the bridge is not paused before proceeding. - Validates that the user has sufficient balance to withdraw the specified amount. - Burns the specified amount of wBTC from the user's balance. - Reduces the total locked Bitcoin amount accordingly. - Updates the user's balance in the `user-balances` map.
- Implemented `validate-bitcoin-transaction` function to validate Bitcoin transactions using oracles. - Checks if the caller is an authorized oracle. - Placeholder for additional validation logic, such as checking the Bitcoin blockchain for transaction confirmation.
- Implemented `check-is-bridge-owner` function to verify if the transaction sender is the bridge owner. - Ensures that only the bridge owner can perform certain actions by asserting the sender's identity.
- Implemented `get-total-locked-bitcoin` function to retrieve the total amount of Bitcoin locked in the bridge. - Implemented `get-user-balance` function to retrieve the wBTC balance of a specified user. - Implemented `is-oracle-authorized` function to check if a specified oracle is authorized.
- Provided an overview of the Bitcoin Bridge Smart Contract, highlighting its purpose and core functionality. - Detailed the main features, including Bitcoin deposits, fee management, oracle-based validation, and recipient whitelisting. - Explained advanced security mechanisms such as bridge pausability, maximum deposit limit, transaction duplicate prevention, and extensive error handling. - Listed key contract components, including error constants and data structures. - Described main functions for deposit functionality, oracle and access management, and bridge administration. - Outlined security considerations, including owner-only administration functions, comprehensive input validation, oracle-based transaction verification, whitelisting mechanism, and transaction replay protection. - Included read-only functions for bridge transparency. - Provided error handling details with specific error codes. - Added a usage example for depositing Bitcoin. - Mentioned configuration options and potential improvements. - Listed dependencies required for the contract.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Overview
This pull request introduces a comprehensive Bitcoin Bridge Smart Contract for the Stacks blockchain, enabling secure wrapping of Bitcoin tokens with robust security and management features.
Key Features
Implemented Functionalities
Security and Access Control
Transaction Management
Detailed Changes
Smart Contract Components
Key Functions
deposit-bitcoin
: Secure Bitcoin deposit and wBTC mintingvalidate-bitcoin-transaction
: Oracle-based transaction validationadd-oracle
/remove-oracle
: Dynamic oracle managementpause-bridge
/unpause-bridge
: Emergency control mechanismupdate-bridge-fee
: Flexible fee configurationSecurity Considerations
Error Handling
Implemented granular error codes covering:
Potential Improvements
Testing Recommendations
Dependencies
Checklist