🌉Cross-chain Bridge
Technique Challenges
Handling various data formats across diverse blockchains
The main difficulty arises from harmonizing Bitcoin's stateless UTXO (Unspent Transaction Output) model with the stateful, account-based system used by Ethereum. We integrate a set of operational markers (confirm, unconfirm, replacement) in the depositor's UTXO wallet, along with corresponding triggers in the smart contract. This setup enables users to conduct transactions on the Bitcoin network, subsequently causing updates in the UTXO and leading to state changes in the Ethereum network's smart contracts.
Deciding which party should be responsible for fee deductions
In our method, actions start from the Bitcoin side, with the real transactions activated on this network. This leads to related state changes on the Ethereum side. Nonetheless, thanks to Gelios's approach to optimizing gas costs, fees are incurred only during withdrawals from Gelios. This strategy is adopted because Bitcoin network costs are relatively unstable and can escalate quickly with a surge in transaction volume.
Actors in the Gelios-bridge model
Transaction initiator (Bitcoin): Their primary responsibility involves encoding the transaction with OP_RETURN, related to an Ethereum-based address, like the receiver's address and operational data. This specific information is incorporated into the Bitcoin transactions and later examined by validators How to Embed Data into OP_RETURN:
function createOpReturnTransaction(senderAddress, privateKey, data, fee):
# Create a new empty transaction
transaction = new Transaction()
# Add input(s) to the transaction
# This involves selecting UTXO(s) owned by the sender
unspentOutputs = getUnspentOutputs(senderAddress)
selectedInputs = selectInputsForTransaction(unspentOutputs, fee)
transaction.addInputs(selectedInputs)
# Calculate total input value
totalInputValue = calculateTotalValue(selectedInputs)
# Create an OP_RETURN output with the data to embed
opReturnOutput = createOpReturnOutput(data)
transaction.addOutput(opReturnOutput)
# Create a change output if necessary
changeValue = totalInputValue - fee
if changeValue > 0:
changeOutput = createOutput(senderAddress, changeValue)
transaction.addOutput(changeOutput)
# Sign the transaction
transaction.sign(privateKey)
# Return the signed transaction
return transaction
function createOpReturnOutput(data):
# OP_RETURN outputs have a value of 0
value = 0
# Create a script that contains OP_RETURN followed by the data
script = "OP_RETURN " + encodeData(data)
# Create and return the output
return new TransactionOutput(value, script)
Multisig Contract: The contract which interact with the middleware protocol, specify the contract operations that are triggerable via Bitcoin network-related transactions. Additionally, they keep track of the state changes announced by validators. Implement with EIP191: A specification about how to handle signed data in Ethereum contracts. EIP734: A multisignature key manager
Middleware Validator: These validators play a crucial role in ensuring the middleware protocol is executed correctly. Their responsibilities encompass enlisting themselves, decoding and verifying Bitcoin network transactions, and overseeing updates to smart contract states. They are also involved in consensus mechanisms. Decoding OP_RETURN:
function decodeOpReturn(transaction):
# Loop through each output in the transaction
for output in transaction.outputs:
# Check if the output script starts with OP_RETURN
if startsWithOpReturn(output.script):
# Extract and return the data following OP_RETURN
data = extractDataFromOpReturn(output.script)
return data
# Return null or an equivalent if no OP_RETURN output is found
return null
function startsWithOpReturn(script):
# Check if the script starts with the OP_RETURN opcode
# (Typically represented by '0x6a' in hexadecimal)
return script.startsWith("OP_RETURN") or script.startsWith("0x6a")
function extractDataFromOpReturn(script):
# Extract and return the data part of the script
# This involves removing the OP_RETURN opcode and any length bytes
# The exact method depends on the script format
return script.removeOpReturnOpcodeAndLengthBytes()
Middleware Operator: Operators are tasked with establishing and managing the middleware protocol. Their duties include configuring system parameters like the size of the validator committee, determining the block confirmation for consensus and state updates, establishing multi-signature validation rules, and implementing additional security measures.
Last updated