Skip to content

Commit

Permalink
remove commitment from contract_id hash
Browse files Browse the repository at this point in the history
  • Loading branch information
sdbondi committed Jul 5, 2022
1 parent b997437 commit dfc70a8
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -281,8 +281,8 @@ impl OutputFeatures {
}
}

pub fn for_contract_definition(commitment: &Commitment, definition: ContractDefinition) -> OutputFeatures {
let contract_id = definition.calculate_contract_id(commitment);
pub fn for_contract_definition(definition: ContractDefinition) -> OutputFeatures {
let contract_id = definition.calculate_contract_id();

Self {
output_type: OutputType::ContractDefinition,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
use std::io::{Error, Read, Write};

use serde::{Deserialize, Serialize};
use tari_common_types::types::{Commitment, FixedHash, PublicKey};
use tari_common_types::types::{FixedHash, PublicKey};

use crate::{
consensus::{ConsensusDecoding, ConsensusEncoding, ConsensusEncodingSized, ConsensusHashWriter, MaxSizeVec},
Expand All @@ -49,12 +49,8 @@ impl ContractDefinition {
}
}

pub fn calculate_contract_id(&self, commitment: &Commitment) -> FixedHash {
ConsensusHashWriter::default()
.chain(commitment)
.chain(self)
.finalize()
.into()
pub fn calculate_contract_id(&self) -> FixedHash {
ConsensusHashWriter::default().chain(self).finalize().into()
}
}

Expand Down
9 changes: 2 additions & 7 deletions base_layer/core/src/validation/dan_validators/test_helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
use std::convert::TryInto;

use tari_common_types::types::{FixedHash, PublicKey, Signature};
use tari_crypto::commitment::HomomorphicCommitmentFactory;
use tari_p2p::Network;

use super::TxDanLayerValidator;
Expand Down Expand Up @@ -53,7 +52,6 @@ use crate::{
Transaction,
UnblindedOutput,
},
CryptoFactories,
},
txn_schema,
validation::{dan_validators::DanLayerValidationError, MempoolTransactionValidation, ValidationError},
Expand Down Expand Up @@ -159,11 +157,8 @@ pub fn create_contract_definition_schema(input: UnblindedOutput) -> (FixedHash,
public_functions: vec![],
},
};
let commitment = CryptoFactories::default()
.commitment
.commit(&input.spending_key, &input.value.into());
let contract_id = definition.calculate_contract_id(&commitment);
let definition_features = OutputFeatures::for_contract_definition(&commitment, definition);
let contract_id = definition.calculate_contract_id();
let definition_features = OutputFeatures::for_contract_definition(definition);

let tx_schema =
txn_schema!(from: vec![input], to: vec![0.into()], fee: 5.into(), lock: 0, features: definition_features);
Expand Down
32 changes: 12 additions & 20 deletions base_layer/wallet/src/assets/asset_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,20 +25,17 @@ use tari_common_types::{
transaction::TxId,
types::{Commitment, FixedHash, PublicKey, Signature},
};
use tari_core::transactions::{
transaction_components::{
CommitteeSignatures,
ContractAmendment,
ContractCheckpoint,
ContractDefinition,
ContractUpdateProposal,
OutputFeatures,
OutputType,
SideChainFeatures,
TemplateParameter,
Transaction,
},
CryptoFactories,
use tari_core::transactions::transaction_components::{
CommitteeSignatures,
ContractAmendment,
ContractCheckpoint,
ContractDefinition,
ContractUpdateProposal,
OutputFeatures,
OutputType,
SideChainFeatures,
TemplateParameter,
Transaction,
};

use crate::{
Expand Down Expand Up @@ -309,12 +306,7 @@ impl<T: OutputManagerBackend + 'static> AssetManager<T> {
.create_output_with_features(1.into(), OutputFeatures::default())
.await?;

let commitment = output.generate_commitment(&CryptoFactories::default());

output = output.with_features(OutputFeatures::for_contract_definition(
&commitment,
contract_definition,
));
output = output.with_features(OutputFeatures::for_contract_definition(contract_definition));

let (tx_id, transaction) = self
.output_manager
Expand Down
2 changes: 2 additions & 0 deletions base_layer/wallet/src/output_manager_service/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -676,6 +676,8 @@ where
features: OutputFeatures,
) -> Result<UnblindedOutputBuilder, OutputManagerError> {
let (spending_key, script_private_key) = self.get_spend_and_script_keys().await?;
let input_data = inputs!(PublicKey::from_secret_key(&script_private_key));
let script = script!(Nop);

Ok(UnblindedOutputBuilder::new(value, spending_key)
.with_features(features)
Expand Down

0 comments on commit dfc70a8

Please sign in to comment.