Feature/verify bte proof (#1866)
* Update lock file * Include bte public key verification
This commit is contained in:
committed by
GitHub
parent
1500d27ce5
commit
e1b511e788
Generated
+1
-1
@@ -6537,7 +6537,7 @@ checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f"
|
||||
|
||||
[[package]]
|
||||
name = "vesting-contract"
|
||||
version = "1.1.0"
|
||||
version = "1.1.2"
|
||||
dependencies = [
|
||||
"contracts-common",
|
||||
"cosmwasm-std",
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
#[derive(Debug, Eq, PartialEq)]
|
||||
pub(crate) enum ComplaintReason {
|
||||
MalformedBTEPublicKey,
|
||||
InvalidBTEPublicKey,
|
||||
MissingDealing,
|
||||
MalformedDealing,
|
||||
DealingVerificationError,
|
||||
|
||||
@@ -54,6 +54,7 @@ pub(crate) async fn dealing_exchange(
|
||||
#[cfg(test)]
|
||||
pub(crate) mod tests {
|
||||
use super::*;
|
||||
use crate::coconut::dkg::complaints::ComplaintReason;
|
||||
use crate::coconut::tests::DummyClient;
|
||||
use crate::coconut::KeyPair;
|
||||
use coconut_dkg_common::dealer::DealerDetails;
|
||||
@@ -148,4 +149,51 @@ pub(crate) mod tests {
|
||||
.clone();
|
||||
assert_eq!(dealings, new_dealings);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
#[ignore] // expensive test
|
||||
async fn invalid_bte_proof_dealing_posted() {
|
||||
let self_index = 2;
|
||||
let dealer_details_db = Arc::new(RwLock::new(HashMap::new()));
|
||||
let dealings_db = Arc::new(RwLock::new(HashMap::new()));
|
||||
let dkg_client = DkgClient::new(
|
||||
DummyClient::new(AccountId::from_str(TEST_VALIDATORS_ADDRESS[0]).unwrap())
|
||||
.with_dealer_details(&dealer_details_db)
|
||||
.with_dealings(&dealings_db),
|
||||
);
|
||||
let params = setup();
|
||||
let mut state = State::new(
|
||||
Url::parse("localhost:8000").unwrap(),
|
||||
DkgKeyPair::new(¶ms, OsRng),
|
||||
KeyPair::new(),
|
||||
);
|
||||
state.set_node_index(Some(self_index));
|
||||
insert_dealers(¶ms, &dealer_details_db);
|
||||
|
||||
dealer_details_db
|
||||
.write()
|
||||
.unwrap()
|
||||
.entry(TEST_VALIDATORS_ADDRESS[1].to_string())
|
||||
.and_modify(|details| {
|
||||
let mut bytes = bs58::decode(details.bte_public_key_with_proof.clone())
|
||||
.into_vec()
|
||||
.unwrap();
|
||||
let last_byte = bytes.last_mut().unwrap();
|
||||
*last_byte += 1;
|
||||
details.bte_public_key_with_proof = bs58::encode(&bytes).into_string();
|
||||
});
|
||||
|
||||
dealing_exchange(&dkg_client, &mut state, OsRng)
|
||||
.await
|
||||
.unwrap();
|
||||
assert_eq!(
|
||||
*state
|
||||
.all_dealers()
|
||||
.get(&Addr::unchecked(TEST_VALIDATORS_ADDRESS[1]))
|
||||
.unwrap()
|
||||
.as_ref()
|
||||
.unwrap_err(),
|
||||
ComplaintReason::InvalidBTEPublicKey
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,6 +30,10 @@ impl TryFrom<DealerDetails> for DkgParticipant {
|
||||
.map_err(|_| ComplaintReason::MalformedBTEPublicKey)?
|
||||
.map_err(|_| ComplaintReason::MalformedBTEPublicKey)?;
|
||||
|
||||
if !bte_public_key_with_proof.verify() {
|
||||
return Err(ComplaintReason::InvalidBTEPublicKey);
|
||||
}
|
||||
|
||||
Ok(DkgParticipant {
|
||||
_address: dealer.address,
|
||||
bte_public_key_with_proof,
|
||||
|
||||
Reference in New Issue
Block a user