Skip to content

Commit

Permalink
fix: hash versions
Browse files Browse the repository at this point in the history
  • Loading branch information
gluax committed May 13, 2024
1 parent 50d0aa2 commit b3183c7
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
7 changes: 7 additions & 0 deletions packages/common/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use schemars::{
schema::{Schema, SchemaObject, SingleOrVec},
JsonSchema,
};
use semver::Version;
use serde::{Deserialize, Serialize};
use serde_big_array::BigArray;
use sha3::{Digest, Keccak256};
Expand All @@ -24,6 +25,12 @@ impl SimpleHash for String {
hasher.finalize().into()
}
}

impl SimpleHash for Version {
fn simple_hash(&self) -> Hash {
self.to_string().simple_hash()
}
}
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
pub struct Signature(#[serde(with = "BigArray")] pub(crate) [u8; 65]);

Expand Down
6 changes: 3 additions & 3 deletions packages/data-requests/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use common::error::ContractError;
use common::msg::StakingQueryMsg;
use common::msg::{IsDataRequestExecutorEligibleResponse, PostDataRequestArgs};
use common::state::DataRequest;
use common::types::{Bytes, Hash, Secpk256k1PublicKey};
use common::types::{Bytes, Hash, Secpk256k1PublicKey, SimpleHash};
use cosmwasm_std::{to_json_binary, Addr, DepsMut, QueryRequest, WasmQuery};
use sha3::{Digest, Keccak256};

Expand Down Expand Up @@ -40,7 +40,7 @@ pub fn hash_data_request(posted_dr: &PostDataRequestArgs) -> Hash {

// hash data request
let mut dr_hasher = Keccak256::new();
dr_hasher.update(posted_dr.version.to_string().as_bytes());
dr_hasher.update(posted_dr.version.simple_hash());
dr_hasher.update(posted_dr.dr_binary_id);
dr_hasher.update(dr_inputs_hash);
dr_hasher.update(posted_dr.tally_binary_id);
Expand Down Expand Up @@ -70,7 +70,7 @@ pub fn hash_data_result(

// hash data result
let mut dr_hasher = Keccak256::new();
dr_hasher.update(dr.version.to_string().as_bytes());
dr_hasher.update(dr.version.simple_hash());
dr_hasher.update(dr.id);
dr_hasher.update(block_height.to_be_bytes());
dr_hasher.update(exit_code.to_be_bytes());
Expand Down

0 comments on commit b3183c7

Please sign in to comment.