Skip to content
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

Eots refactor 2 #33

Merged
merged 8 commits into from
Aug 6, 2024
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions contracts/babylon/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,11 @@ pub fn execute(
// TODO: Add events
Ok(Response::new())
}
ExecuteMsg::Slashing { fp_btc_pk, block_height, secret_key } => {
ExecuteMsg::Slashing {
fp_btc_pk,
block_height,
secret_key,
} => {
// This is an internal routing message from the `btc-staking` contract
// Check sender
let btc_staking = CONFIG
Expand All @@ -173,7 +177,8 @@ pub fn execute(
}
// Send over IBC to the Provider (Babylon)
let channel = IBC_CHANNEL.load(deps.storage)?;
let msg = ibc_packet::slashing_msg(&env, &channel, &fp_btc_pk, block_height, &secret_key)?;
let msg =
ibc_packet::slashing_msg(&env, &channel, &fp_btc_pk, block_height, &secret_key)?;
// TODO: Add events
Ok(Response::new().add_message(msg))
}
Expand Down
25 changes: 15 additions & 10 deletions contracts/babylon/src/ibc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,11 +141,14 @@ pub(crate) mod ibc_packet {
use super::*;
use crate::state::config::CONFIG;
use babylon_apis::ibc_consumer::{consumer_packet_data, ConsumerPacketData};
use babylon_apis::{btc_staking_api::{
ActiveBtcDelegation, BtcUndelegationInfo, CovenantAdaptorSignatures,
FinalityProviderDescription, NewFinalityProvider, ProofOfPossessionBtc, SignatureInfo,
UnbondedBtcDelegation,
}, ibc_consumer};
use babylon_apis::{
btc_staking_api::{
ActiveBtcDelegation, BtcUndelegationInfo, CovenantAdaptorSignatures,
FinalityProviderDescription, NewFinalityProvider, ProofOfPossessionBtc, SignatureInfo,
UnbondedBtcDelegation,
},
ibc_consumer,
};
use babylon_proto::babylon::btcstaking::v1::BtcStakingIbcPacket;
use cosmwasm_std::{to_json_binary, Decimal, IbcChannel, IbcMsg, WasmMsg};
use std::str::FromStr;
Expand Down Expand Up @@ -311,11 +314,13 @@ pub(crate) mod ibc_packet {
block_height: u64,
secret_key: &[u8],
) -> Result<IbcMsg, ContractError> {
let packet = ConsumerPacketData { packet: consumer_packet_data::Packet::Slashing(ibc_consumer::Slashing {
fp_btc_pk: fp_btc_pk.to_vec(),
block_height,
secret_key: secret_key.to_vec(),
}), };
let packet = ConsumerPacketData {
packet: consumer_packet_data::Packet::Slashing(ibc_consumer::Slashing {
fp_btc_pk: fp_btc_pk.to_vec(),
block_height,
secret_key: secret_key.to_vec(),
}),
};
let msg = IbcMsg::SendPacket {
channel_id: channel.endpoint.channel_id.clone(),
data: to_json_binary(&packet)?,
Expand Down
6 changes: 3 additions & 3 deletions contracts/babylon/src/msg/contract.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use cosmwasm_schema::{cw_serde, QueryResponses};
use cosmwasm_std::{Binary, StdError, StdResult};
use babylon_apis::Bytes;
use crate::msg::btc_header::{BtcHeader, BtcHeaderResponse, BtcHeadersResponse};
use crate::msg::cz_header::CzHeaderResponse;
use crate::msg::epoch::EpochResponse;
use crate::state::config::Config;
use babylon_apis::Bytes;
use cosmwasm_schema::{cw_serde, QueryResponses};
use cosmwasm_std::{Binary, StdError, StdResult};

const BABYLON_TAG_BYTES: usize = 4;

Expand Down
37 changes: 19 additions & 18 deletions contracts/btc-staking/src/finality.rs
Original file line number Diff line number Diff line change
Expand Up @@ -274,15 +274,15 @@ fn slash_finality_provider(

// Extract BTC SK using the evidence
let pk = eots::PublicKey::from_hex(fp_btc_pk_hex)?;
let btc_sk = eots::extract(
&pk,
&evidence.pub_rand,
&evidence.canonical_app_hash,
&evidence.canonical_finality_sig,
&evidence.fork_app_hash,
&evidence.fork_finality_sig,
)
.map_err(|err| ContractError::SecretKeyExtractionError(err.to_string()))?;
let btc_sk = pk
.extract(
&evidence.pub_rand,
&evidence.canonical_app_hash,
&evidence.canonical_finality_sig,
&evidence.fork_app_hash,
&evidence.fork_finality_sig,
)
.map_err(|err| ContractError::SecretKeyExtractionError(err.to_string()))?;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm extract is probably not suitable to be a function under the public key. Why not just keep it as is?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was thinking the same. What about calling it extract_secret_key?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sg


// Emit slashing event.
// Raises slashing event to babylon over IBC.
Expand Down Expand Up @@ -1050,15 +1050,16 @@ pub(crate) mod tests {
// Assert the slashing event is proper
assert_eq!(res.events[0].ty, "slashed_finality_provider".to_string());
// Extract the secret key to compare it
let btc_sk = eots::extract(
&eots::PublicKey::from_hex(&pk_hex).unwrap(),
&pub_rand_one,
&add_finality_signature.block_app_hash,
&finality_signature,
&add_finality_signature_2.block_app_hash,
&add_finality_signature_2.finality_sig,
)
.unwrap();
let pk = eots::PublicKey::from_hex(&pk_hex).unwrap();
let btc_sk = pk
.extract(
&pub_rand_one,
&add_finality_signature.block_app_hash,
&finality_signature,
&add_finality_signature_2.block_app_hash,
&add_finality_signature_2.finality_sig,
)
.unwrap();
assert_eq!(
res.messages[0],
SubMsg::new(WasmMsg::Execute {
Expand Down
2 changes: 1 addition & 1 deletion packages/apis/src/ibc_consumer.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use cosmwasm_schema::cw_serde;
use crate::Bytes;
use cosmwasm_schema::cw_serde;

/// ConsumerPacketData is the message that defines the IBC packets a Consumer can send to Babylon's
/// ZoneConcierge module.
Expand Down
Loading