-
Notifications
You must be signed in to change notification settings - Fork 49
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
Qubic Bridge SC in develop. testnet #231
base: main
Are you sure you want to change the base?
Qubic Bridge SC in develop. testnet #231
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the clear contract description and easy-to-read code!
Here is some feedback. I haven’t read everything in detail, but you can start improving some things right now.
First, about the name. Because this is in Qubic, we don’t need Qubic in the name, but rather Ethereum, because this is what is connected here. I suggest to name the file EthBridge.h
and the contract state struct ETHBRIDGE
(please rename BridgeContract
). The state struct name in capital case letters, because it is used in many constants and macros.
Second, please include the contract in contract_core/contract_def.h
by adding the following behind #include "contracts/QVAULT.h"
:
#undef CONTRACT_INDEX
#undef CONTRACT_STATE_TYPE
#undef CONTRACT_STATE2_TYPE
#define ETHBRIDGE_CONTRACT_INDEX 11
#define CONTRACT_INDEX ETHBRIDGE_CONTRACT_INDEX
#define CONTRACT_STATE_TYPE ETHBRIDGE
#define CONTRACT_STATE2_TYPE ETHBRIDGE2
#include "contracts/EthBridge.h"
After that, you can compile the core with MS Visual C++ 2022 and get compiler errors / warnings about your code.
It is great that you provide detailed error information with output.message
, but unfortunately the output is not accessible for procedures if they are called through a transaction (only available when called from other contract).
But I recommend provide the error information via logging. Like with:
struct EthBridgeLogger
{
uint32 _contractIndex;
uint32 _errorCode;
// Other data go here
char _terminator; // Only data before "_terminator" are logged
};
With an enum of error code you can emit a log entry by: LOG_INFO(QuotteryLogger{CONTRACT_INDEX, EthBridgeError::onlyManagersCanCompleteOrders});
Here is the current draft of the contract dev docs: https://github.com/qubic/core/blob/d67fc559557793b8abe0efa56fe0c04e54c63fce/doc/contracts.md |
…r, avoiding the use of regular stack and general code clean-up
…ocal variables. Defined 'placeholderMemo' as constexpr to replace the memo strings in copyMemory
…r additions and current manager removed
…ied, so local variables are moved into the corresponding locals structs. Andthe logic with 'totalReceivedTokens' and 'lockedTokens' is updated. Some events are included as Logs
Hi @krypdkat and @philipwerner, I’ve resolved all the comments and addressed the requested changes. Please review the updates when you have time. Let me know if there’s anything else that needs adjustment. Thank you! |
Thanks, I will review the updates when I have time. One important thing that I can tell you now, is that you have to implement tests with GoogleTest in the test project. See https://github.com/qubic/core/blob/main/doc/contracts.md |
…om/vottundev/core into testnets/2024-12-05-bridge-develop
…' included in EthBridge in SC
… EthBridge with compiling errors due to hashmap2
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for your revision.
Please add contract_ethbridge.cpp to the test project and EthBridge.h to the contracts filter in the Qubic project. The files will then appear in the *.vcxproj and *.vcxproj.filters files as in https://github.com/qubic/core/pull/237/files
Please compile the test project, fix the compiler warnings, and revise the tests based on my comments. And run it to make sure all tests pass without error. Running the debug build will help you to debug the tests.
Please change the PR target branch to qubic:develop. It is qubic:main at the moment. See https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/proposing-changes-to-your-work-with-pull-requests/changing-the-base-branch-of-a-pull-request
For the finalizing the PR, you will have to remove the testnet config commit.
…And transactionFee type change to solve warnings
…m/vottundev/core into testnets/2024-12-05-bridge-develop
… and vcxproject.filters
…fore adding it to the list of managers.
This is the PR for the Qubic Bridge Smart Contract (QUBIC to Ethereum and vice versa)
Purpose of the Qubic Bridge Contract
The Qubic Bridge Contract ensures seamless and secure transfer of native QUBIC tokens between the Qubic network and Ethereum using a lock-and-mint mechanism:
QUBIC tokens are locked in the contract, and equivalent wrapped QUBIC (WQUBIC) tokens are minted on Ethereum.
WQUBIC tokens are burned on Ethereum, and equivalent QUBIC tokens are unlocked on the Qubic network.
Design Features
Single-contract solution
Tokens are locked and managed directly in this contract without relying on an external locking contract, simplifying the architecture.
Role-based access control
The contract includes role-based permissions for secure and decentralized operations:
Efficient order management
The contract uses a
HashMap
for rapid order lookups and tracks the lifecycle of each order, ensuring data integrity.Comprehensive state tracking
The contract maintains variables to monitor locked tokens, total received tokens, and order states, preventing invalid state transitions.
Roles and Permissions
Admin
setAdmin
).addManager
,removeManager
).Managers
completeOrder
).refundOrder
).Users
createOrder
).getOrder
).Core Functionalities
User Functions
createOrder
ethAddress
(Ethereum destination address).amount
(number of tokens to transfer).fromQubicToEthereum
(transfer direction flag).orderId
for tracking the order.orderId
for further processing.getOrder
orderId
(order identifier).OrderResponse
).Manager Functions
completeOrder
refundOrder
Admin Functions
setAdmin
: Assigns a new admin to the contract.addManager
: Adds a new manager for operational tasks.removeManager
: Removes an existing manager.Additional Utility Methods
transferToContract
: Allows users to deposit tokens into the contract.Security Considerations
How the Contract Works
Initialization
Upon deployment, key variables such as
nextOrderId
andlockedTokens
are initialized, and the deploying address is set as the admin.Qubic-to-Ethereum Transfer
Users call
createOrder
, which locks QUBIC tokens. Managers confirm the order by minting WQUBIC tokens on Ethereum.Managers call
completeOrder
to finalize the transaction, updating the order state and transferring/minting tokens.Refunds
If the transfer cannot proceed, managers can call
refundOrder
to return the locked tokens to the sender.Frontend Requirements
User Inputs
ethAddress
,amount
, andfromQubicToEthereum
.orderId
.Admin/Manager Inputs
setAdmin
: New admin's address.addManager
/removeManager
: Manager's address.completeOrder
/refundOrder
:orderId
.