Skip to content

Commit

Permalink
WIP withdrawal checks
Browse files Browse the repository at this point in the history
  • Loading branch information
ozankaymak committed Sep 9, 2024
1 parent 3a0df10 commit b4c8072
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 4 deletions.
3 changes: 3 additions & 0 deletions core/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,9 @@ pub enum BridgeError {

#[error("InvalidInputUTXO: {0}, {1}")]
InvalidInputUTXO(Txid, Txid),

#[error("InvalidOperatorIndex: {0}, {1}")]
InvalidOperatorIndex(usize, usize),
}

impl From<BridgeError> for ErrorObject<'static> {
Expand Down
23 changes: 20 additions & 3 deletions core/src/operator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ where
];
let response: String = self.citrea_client.request("eth_call", params).await?;
let txid_response = &response[2..66];
let mut txid = hex::decode(txid_response).unwrap();
let txid = hex::decode(txid_response).unwrap();
// txid.reverse(); // TODO: we should need to reverse this, test this with declareWithdrawalFiller
let txid = Txid::from_slice(&txid).unwrap();
if txid != input_utxo.outpoint.txid || 0 != input_utxo.outpoint.vout {
Expand Down Expand Up @@ -430,11 +430,28 @@ where

async fn withdrawal_proved_on_citrea(
&self,
_withdrawal_idx: usize,
withdrawal_idx: u32,
deposit_outpoint: OutPoint,
) -> Result<Vec<String>, BridgeError> {
// call withdrawFillers(withdrawal_idx) check the returned id is our operator id.
// calculate the move_txid, txIdToDepositId(move_txid) check the returned id is withdrawal_idx
if !self.config.citrea_rpc_url.is_empty() {
let params = rpc_params![
json!({
"to": "0x3100000000000000000000000000000000000002",
"data": format!("0xc045577b00000000000000000000000000000000000000000000000000000000{}", hex::encode(withdrawal_idx.to_be_bytes())), // See: https://gist.github.com/okkothejawa/a9379b02a16dada07a2b85cbbd3c1e80
}),
"latest"
];
let response: String = self.citrea_client.request("eth_call", params).await?;
let operator_idx_response = &response[58..66];
let operator_idx_as_vec = hex::decode(operator_idx_response).unwrap();
let operator_idx = u32::from_be_bytes(operator_idx_as_vec.try_into().unwrap());
if operator_idx != self.idx as u32 {
return Err(BridgeError::InvalidOperatorIndex(operator_idx as usize, self.idx));
}
}

let kickoff_utxo = self
.db
.get_kickoff_utxo(None, deposit_outpoint)
Expand Down Expand Up @@ -646,7 +663,7 @@ where

async fn withdrawal_proved_on_citrea_rpc(
&self,
withdrawal_idx: usize,
withdrawal_idx: u32,
deposit_outpoint: OutPoint,
) -> Result<Vec<String>, BridgeError> {
self.withdrawal_proved_on_citrea(withdrawal_idx, deposit_outpoint)
Expand Down
2 changes: 1 addition & 1 deletion core/src/traits/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ pub trait OperatorRpc {
/// 3- If it is, send operator_take_txs
async fn withdrawal_proved_on_citrea_rpc(
&self,
withdrawal_idx: usize,
withdrawal_idx: u32,
deposit_outpoint: OutPoint,
) -> Result<Vec<String>, BridgeError>;

Expand Down

0 comments on commit b4c8072

Please sign in to comment.