Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
17 changes: 17 additions & 0 deletions packages/rs-dpp/src/identity/identity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,23 @@ impl Identity {
not_found_public_keys: Default::default(),
}
}

/// Convenience method to get Partial Identity Info
pub fn into_partial_identity_info_no_balance(self) -> PartialIdentity {
let Identity {
id,
public_keys,
revision,
..
} = self;
PartialIdentity {
id,
loaded_public_keys: public_keys,
balance: None,
revision: Some(revision),
not_found_public_keys: Default::default(),
}
}
}

impl TryFrom<Value> for Identity {
Expand Down
4 changes: 2 additions & 2 deletions packages/rs-dpp/src/identity/identity_public_key/key_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ impl KeyType {
let secret_key = dashcore::secp256k1::SecretKey::new(&mut rng);
let private_key = dashcore::PrivateKey::new(secret_key, Network::Dash);
(
ripemd160_sha256(private_key.public_key(&secp).to_bytes().as_slice()),
ripemd160_sha256(private_key.public_key(&secp).to_bytes().as_slice()).to_vec(),
private_key.to_bytes(),
)
}
Expand All @@ -149,7 +149,7 @@ impl KeyType {
let secret_key = dashcore::secp256k1::SecretKey::new(&mut rng);
let private_key = dashcore::PrivateKey::new(secret_key, Network::Dash);
(
ripemd160_sha256(private_key.public_key(&secp).to_bytes().as_slice()),
ripemd160_sha256(private_key.public_key(&secp).to_bytes().as_slice()).to_vec(),
private_key.to_bytes(),
)
}
Expand Down
9 changes: 5 additions & 4 deletions packages/rs-dpp/src/identity/identity_public_key/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use anyhow::anyhow;
#[cfg(feature = "cbor")]
use ciborium::value::Value as CborValue;
use dashcore::PublicKey as ECDSAPublicKey;
use platform_value::{BinaryData, ReplacementType, Value, ValueMapHelper};
use platform_value::{BinaryData, Bytes20, ReplacementType, Value, ValueMapHelper};
use serde::{Deserialize, Deserializer, Serialize, Serializer};
use serde_json::Value as JsonValue;

Expand All @@ -27,6 +27,7 @@ use crate::util::cbor_value::{CborCanonicalMap, CborMapExtension};
use crate::util::hash::ripemd160_sha256;
use crate::Convertible;
use bincode::{config, Decode, Encode};
use dashcore::hashes::Hash;

use crate::identity::state_transition::identity_public_key_transitions::IdentityPublicKeyInCreation;
use crate::util::vec;
Expand Down Expand Up @@ -142,7 +143,7 @@ impl IdentityPublicKey {
}

/// Get the original public key hash
pub fn hash(&self) -> Result<Vec<u8>, ProtocolError> {
pub fn hash(&self) -> Result<[u8; 20], ProtocolError> {
if self.data.is_empty() {
return Err(ProtocolError::EmptyPublicKeyDataError);
}
Expand All @@ -160,7 +161,7 @@ impl IdentityPublicKey {
)));
}
};
Ok(key.pubkey_hash().to_vec())
Ok(key.pubkey_hash().into_inner())
}
KeyType::BLS12_381 => {
if self.data.len() != 48 {
Expand All @@ -173,7 +174,7 @@ impl IdentityPublicKey {
}
}
KeyType::ECDSA_HASH160 | KeyType::BIP13_SCRIPT_HASH | KeyType::EDDSA_25519_HASH160 => {
Ok(self.data.to_vec())
Ok(Bytes20::from_vec(self.data.to_vec())?.into_buffer())
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,9 @@ impl IdentityPublicKeyInCreation {

/// Get the original public key hash
pub fn hash_as_vec(&self) -> Result<Vec<u8>, ProtocolError> {
Into::<IdentityPublicKey>::into(self).hash()
Into::<IdentityPublicKey>::into(self)
.hash()
.map(|hash| hash.to_vec())
}

/// Get the original public key hash
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ where
let public_key_compressed = get_compressed_public_ec_key(private_key)?;
let pub_key_hash = ripemd160_sha256(&public_key_compressed);

if pub_key_hash != identity_public_key.data {
if identity_public_key.data != pub_key_hash {
return Err(ProtocolError::InvalidSignaturePublicKeyError(
InvalidSignaturePublicKeyError::new(identity_public_key.data.to_vec()),
));
Expand Down Expand Up @@ -473,7 +473,7 @@ mod test {
let mut keys = get_test_keys();
keys.identity_public_key.key_type = KeyType::ECDSA_HASH160;
keys.identity_public_key.data =
BinaryData::new(ripemd160_sha256(keys.identity_public_key.data.as_slice()));
BinaryData::new(ripemd160_sha256(keys.identity_public_key.data.as_slice()).to_vec());

st.sign(&keys.identity_public_key, &keys.ec_private, &bls)
.unwrap();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ mod from_raw_object {
"type": KeyType::BIP13_SCRIPT_HASH,
"purpose": Purpose::AUTHENTICATION,
"securityLevel": SecurityLevel::MASTER,
"data": "AuryIuMtRrl/VviQuyLD1l4nmxi9ogPzC9LT7tdpo0di",
"data": "n6I3y1cTf2efmnf3/oFvAmjpGQ8=",
"readOnly": false
});

Expand All @@ -72,8 +72,8 @@ mod from_raw_object {
assert_eq!(
public_key.hash().unwrap(),
[
2, 234, 242, 34, 227, 45, 70, 185, 127, 86, 248, 144, 187, 34, 195, 214, 94, 39,
155, 24, 189, 162, 3, 243, 11, 210, 211, 238, 215, 105, 163, 71, 98
159, 162, 55, 203, 87, 19, 127, 103, 159, 154, 119, 247, 254, 129, 111, 2, 104,
233, 25, 15,
]
);
}
Expand Down
4 changes: 2 additions & 2 deletions packages/rs-dpp/src/util/hash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ pub fn hash(payload: impl AsRef<[u8]>) -> [u8; 32] {
Sha256::digest(Sha256::digest(payload)).into()
}

pub fn ripemd160_sha256(data: &[u8]) -> Vec<u8> {
ripemd160::Hash::hash(&sha256::Hash::hash(data)).to_vec()
pub fn ripemd160_sha256(data: &[u8]) -> [u8; 20] {
ripemd160::Hash::hash(&sha256::Hash::hash(data)).into_inner()
}
36 changes: 26 additions & 10 deletions packages/rs-drive-abci/src/abci/handlers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@

use crate::abci::server::AbciApplication;
use crate::error::execution::ExecutionError;
use crate::error::query::QueryError;
use crate::error::Error;
use crate::execution::block_proposal::BlockProposal;
use crate::execution::engine::BlockExecutionOutcome;
Expand Down Expand Up @@ -526,31 +527,46 @@ where
}

fn query(&self, request: RequestQuery) -> Result<ResponseQuery, ResponseException> {
let RequestQuery {
data, path, prove, ..
} = request;
let RequestQuery { data, path, .. } = &request;

let result = self.platform.query(path.as_str(), data.as_slice(), prove)?;
let result = self.platform.query(path.as_str(), data.as_slice())?;

let (code, data) = if result.is_valid() {
(0, result.data.unwrap_or_default())
let (code, data, log) = if result.is_valid() {
(
0,
result.data.unwrap_or_default(),
"query success".to_string(),
)
} else {
(1, vec![])
let mut buffer: Vec<u8> = Vec::new();
ciborium::ser::into_writer(
&result
.errors
.iter()
.map(|e| e.to_string())
.collect::<Vec<_>>(),
&mut buffer,
)
.map_err(|e| e.to_string())?;
(1, buffer, format!("{:?}", result.errors))
};

Ok(ResponseQuery {
let response = ResponseQuery {
//todo: right now just put GRPC error codes,
// later we will use own error codes
code,
log: "".to_string(),
log,
info: "".to_string(),
index: 0,
key: vec![],
value: data,
proof_ops: None,
height: self.platform.state.read().unwrap().height() as i64,
codespace: "".to_string(),
})
};
tracing::trace!(method = "query", ?request, ?response);

Ok(response)
}
}
//
Expand Down
7 changes: 6 additions & 1 deletion packages/rs-drive-abci/src/abci/mimic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ pub struct MimicExecuteBlockOutcome {
pub withdrawal_transactions: Vec<dashcore_rpc::dashcore::Transaction>,
/// The next validators hash
pub next_validator_set_hash: Vec<u8>,
/// Root App hash
pub root_app_hash: [u8; 32],
}

/// Options for execution
Expand Down Expand Up @@ -326,7 +328,7 @@ impl<'a, C: CoreRPCLike> AbciApplication<'a, C> {
next_validators_hash: next_validator_set_hash.clone(),
consensus_hash: [0; 32].to_vec(),
next_consensus_hash: [0; 32].to_vec(),
app_hash,
app_hash: app_hash.clone(),
results_hash: [0; 32].to_vec(),
evidence_hash: vec![],
proposed_app_version: 0,
Expand Down Expand Up @@ -356,6 +358,9 @@ impl<'a, C: CoreRPCLike> AbciApplication<'a, C> {
Ok(MimicExecuteBlockOutcome {
withdrawal_transactions: withdrawals,
next_validator_set_hash,
root_app_hash: app_hash
.try_into()
.expect("expected 32 bytes for the root hash"),
})
}
}
9 changes: 9 additions & 0 deletions packages/rs-drive-abci/src/error/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use drive::error::proof::ProofError;
use drive::error::query::QuerySyntaxError as SyntaxError;
use drive::error::Error as DriveError;
use prost::DecodeError;
use tenderdash_abci::proto::abci::ResponseException;

/// Errors
#[derive(Debug, thiserror::Error)]
Expand Down Expand Up @@ -31,3 +32,11 @@ pub enum QueryError {
#[error("protobuf decoding error: {0}")]
ProtobufDecode(#[from] DecodeError),
}

impl From<QueryError> for ResponseException {
fn from(value: QueryError) -> Self {
Self {
error: value.to_string(),
}
}
}
1 change: 0 additions & 1 deletion packages/rs-drive-abci/src/query/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@ impl<C> Platform<C> {
&self,
query_path: &str,
query_data: &[u8],
_prove: bool,
) -> Result<QueryValidationResult<Vec<u8>>, Error> {
let state = self.state.read().unwrap();
let metadata = ResponseMetadata {
Expand Down
15 changes: 15 additions & 0 deletions packages/rs-drive-abci/tests/strategy_tests/execution.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use crate::masternodes;
use crate::masternodes::{GenerateTestMasternodeUpdates, MasternodeListItemWithUpdates};
use crate::operations::FinalizeBlockOperation::IdentityAddKeys;
use crate::query::ProofVerification;
use crate::signer::SimpleSigner;
use crate::strategy::{
ChainExecutionOutcome, ChainExecutionParameters, Strategy, StrategyRandomness,
Expand Down Expand Up @@ -655,6 +656,7 @@ pub(crate) fn continue_chain_for_strategy(
let MimicExecuteBlockOutcome {
withdrawal_transactions: mut withdrawals_this_block,
next_validator_set_hash,
root_app_hash,
} = abci_app
.mimic_execute_block(
proposer.pro_tx_hash.into_inner(),
Expand Down Expand Up @@ -692,6 +694,19 @@ pub(crate) fn continue_chain_for_strategy(

current_time_ms += config.block_spacing_ms;

if let Some(query_strategy) = &strategy.query_testing {
query_strategy.query_chain_for_strategy(
&ProofVerification {
root_app_hash: &root_app_hash,
block_signature: &vec![], //todo
quorum_hash: &current_quorum_with_test_info.quorum_hash.into_inner(),
},
&current_identities,
&abci_app,
StrategyRandomness::RNGEntropy(rng.clone()),
)
}

let next_quorum_hash = QuorumHash::from_inner(next_validator_set_hash.try_into().unwrap());
if current_quorum_hash != next_quorum_hash {
current_quorum_hash = next_quorum_hash;
Expand Down
1 change: 1 addition & 0 deletions packages/rs-drive-abci/tests/strategy_tests/failures.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ mod tests {
deterministic_start_seed: Some(99),
dont_finalize_block: true,
}),
query_testing: None,
};
let config = PlatformConfig {
verify_sum_trees: true,
Expand Down
Loading