From 72862cb6b7cdc873d985c746e111e20c4583ad82 Mon Sep 17 00:00:00 2001 From: Voxelot Date: Tue, 21 Mar 2023 19:08:40 -0700 Subject: [PATCH 01/10] use chain id for predicate root --- fuel-tx/src/tests/valid_cases/input.rs | 12 ++++---- fuel-tx/src/tests/valid_cases/transaction.rs | 12 ++++---- fuel-tx/src/transaction.rs | 4 +-- .../src/transaction/consensus_parameters.rs | 30 +++++++++++++++++++ fuel-tx/src/transaction/types/create.rs | 4 +-- fuel-tx/src/transaction/types/input.rs | 18 +++++++---- fuel-tx/src/transaction/types/mint.rs | 2 +- fuel-tx/src/transaction/types/script.rs | 4 +-- fuel-tx/src/transaction/validity.rs | 26 ++++++++++------ fuel-vm/src/checked_transaction.rs | 10 +++---- fuel-vm/src/interpreter/executors/main.rs | 2 +- fuel-vm/src/tests/metadata.rs | 4 +-- fuel-vm/src/tests/predicate.rs | 12 ++++---- 13 files changed, 92 insertions(+), 48 deletions(-) diff --git a/fuel-tx/src/tests/valid_cases/input.rs b/fuel-tx/src/tests/valid_cases/input.rs index 8c42ed7549..eaea1f05ef 100644 --- a/fuel-tx/src/tests/valid_cases/input.rs +++ b/fuel-tx/src/tests/valid_cases/input.rs @@ -108,7 +108,7 @@ fn coin_predicate() { let txhash: Bytes32 = rng.gen(); let predicate = generate_nonempty_padded_bytes(rng); - let owner = (*Contract::root_from_code(&predicate)).into(); + let owner = Input::predicate_owner(&predicate, &ConsensusParameters::DEFAULT); Input::coin_predicate( rng.gen(), @@ -124,7 +124,7 @@ fn coin_predicate() { .unwrap(); let predicate = vec![]; - let owner = (*Contract::root_from_code(&predicate)).into(); + let owner = Input::predicate_owner(&predicate, &ConsensusParameters::DEFAULT); let err = Input::coin_predicate( rng.gen(), @@ -220,7 +220,7 @@ fn message_metadata() { let txhash: Bytes32 = rng.gen(); let predicate = generate_nonempty_padded_bytes(rng); - let recipient = (*Contract::root_from_code(&predicate)).into(); + let recipient = Input::predicate_owner(&predicate, &ConsensusParameters::DEFAULT); Input::message_data_predicate( rng.gen(), @@ -248,7 +248,7 @@ fn message_metadata() { assert_eq!(CheckError::InputWitnessIndexBounds { index: 0 }, err,); let mut predicate = generate_nonempty_padded_bytes(rng); - let recipient = (*Contract::root_from_code(&predicate)).into(); + let recipient = Input::predicate_owner(&predicate, &ConsensusParameters::DEFAULT); predicate[0] = predicate[0].wrapping_add(1); let err = Input::message_data_predicate( @@ -327,7 +327,7 @@ fn message_message_coin() { let txhash: Bytes32 = rng.gen(); let predicate = generate_nonempty_padded_bytes(rng); - let recipient = (*Contract::root_from_code(&predicate)).into(); + let recipient = Input::predicate_owner(&predicate, &ConsensusParameters::DEFAULT); Input::message_coin_predicate( rng.gen(), @@ -353,7 +353,7 @@ fn message_message_coin() { assert_eq!(CheckError::InputWitnessIndexBounds { index: 0 }, err,); let mut predicate = generate_nonempty_padded_bytes(rng); - let recipient = (*Contract::root_from_code(&predicate)).into(); + let recipient = Input::predicate_owner(&predicate, &ConsensusParameters::DEFAULT); predicate[0] = predicate[0].wrapping_add(1); let err = Input::message_coin_predicate( diff --git a/fuel-tx/src/tests/valid_cases/transaction.rs b/fuel-tx/src/tests/valid_cases/transaction.rs index 859b017834..6f90e829ea 100644 --- a/fuel-tx/src/tests/valid_cases/transaction.rs +++ b/fuel-tx/src/tests/valid_cases/transaction.rs @@ -771,7 +771,7 @@ mod inputs { let predicate = (0..1000).map(|_| rng.gen()).collect_vec(); // The predicate is an owner of the coin - let owner: Address = (*Contract::root_from_code(&predicate)).into(); + let owner: Address = Input::predicate_owner(&predicate, &ConsensusParameters::DEFAULT); let tx = TransactionBuilder::create(generate_bytes(rng).into(), rng.gen(), vec![]) .gas_limit(PARAMS.max_gas_per_tx) @@ -789,7 +789,7 @@ mod inputs { )) .finalize(); - assert!(tx.check_predicate_owners()); + assert!(tx.check_predicate_owners(&ConsensusParameters::DEFAULT)); } #[test] @@ -814,7 +814,7 @@ mod inputs { )) .finalize(); - assert!(!tx.check_predicate_owners()); + assert!(!tx.check_predicate_owners(&ConsensusParameters::DEFAULT)); } #[test] @@ -823,7 +823,7 @@ mod inputs { let predicate = (0..1000).map(|_| rng.gen()).collect_vec(); // The predicate is an recipient(owner) of the message - let recipient: Address = (*Contract::root_from_code(&predicate)).into(); + let recipient: Address = Input::predicate_owner(&predicate, &ConsensusParameters::DEFAULT); let tx = TransactionBuilder::create(generate_bytes(rng).into(), rng.gen(), vec![]) .gas_limit(PARAMS.max_gas_per_tx) @@ -840,7 +840,7 @@ mod inputs { )) .finalize(); - assert!(tx.check_predicate_owners()); + assert!(tx.check_predicate_owners(&ConsensusParameters::DEFAULT)); } #[test] @@ -864,6 +864,6 @@ mod inputs { )) .finalize(); - assert!(!tx.check_predicate_owners()); + assert!(!tx.check_predicate_owners(&ConsensusParameters::DEFAULT)); } } diff --git a/fuel-tx/src/transaction.rs b/fuel-tx/src/transaction.rs index 4a5947e7f4..4439f07567 100644 --- a/fuel-tx/src/transaction.rs +++ b/fuel-tx/src/transaction.rs @@ -254,7 +254,7 @@ pub trait Executable: field::Inputs + field::Outputs + field::Witnesses { /// Checks that all owners of inputs in the predicates are valid. #[cfg(feature = "std")] - fn check_predicate_owners(&self) -> bool { + fn check_predicate_owners(&self, parameters: &ConsensusParameters) -> bool { self.inputs() .iter() .filter_map(|i| match i { @@ -265,7 +265,7 @@ pub trait Executable: field::Inputs + field::Outputs + field::Witnesses { _ => None, }) .fold(true, |result, (owner, predicate)| { - result && Input::is_predicate_owner_valid(owner, predicate) + result && Input::is_predicate_owner_valid(owner, predicate, parameters) }) } diff --git a/fuel-tx/src/transaction/consensus_parameters.rs b/fuel-tx/src/transaction/consensus_parameters.rs index 0ed14131e1..962e3e9af6 100644 --- a/fuel-tx/src/transaction/consensus_parameters.rs +++ b/fuel-tx/src/transaction/consensus_parameters.rs @@ -32,6 +32,8 @@ pub struct ConsensusParameters { pub gas_per_byte: u64, /// Maximum length of message data, in bytes. pub max_message_data_length: u64, + /// The unique identifier of this chain + pub chain_id: u64, } impl ConsensusParameters { @@ -50,6 +52,7 @@ impl ConsensusParameters { gas_price_factor: 1_000_000_000, gas_per_byte: 4, max_message_data_length: 1024 * 1024, + chain_id: 0, }; /// Transaction memory offset in VM runtime @@ -75,6 +78,7 @@ impl ConsensusParameters { gas_price_factor, gas_per_byte, max_message_data_length, + chain_id, .. } = self; @@ -92,6 +96,7 @@ impl ConsensusParameters { gas_price_factor, gas_per_byte, max_message_data_length, + chain_id, } } @@ -110,6 +115,7 @@ impl ConsensusParameters { gas_price_factor, gas_per_byte, max_message_data_length, + chain_id, .. } = self; @@ -127,6 +133,7 @@ impl ConsensusParameters { gas_price_factor, gas_per_byte, max_message_data_length, + chain_id, } } @@ -145,6 +152,7 @@ impl ConsensusParameters { gas_price_factor, gas_per_byte, max_message_data_length, + chain_id, .. } = self; @@ -162,6 +170,7 @@ impl ConsensusParameters { gas_price_factor, gas_per_byte, max_message_data_length, + chain_id, } } @@ -180,6 +189,7 @@ impl ConsensusParameters { gas_price_factor, gas_per_byte, max_message_data_length, + chain_id, .. } = self; @@ -197,6 +207,7 @@ impl ConsensusParameters { gas_price_factor, gas_per_byte, max_message_data_length, + chain_id, } } @@ -215,6 +226,7 @@ impl ConsensusParameters { gas_price_factor, gas_per_byte, max_message_data_length, + chain_id, .. } = self; @@ -232,6 +244,7 @@ impl ConsensusParameters { gas_price_factor, gas_per_byte, max_message_data_length, + chain_id, } } @@ -250,6 +263,7 @@ impl ConsensusParameters { gas_price_factor, gas_per_byte, max_message_data_length, + chain_id, .. } = self; @@ -267,6 +281,7 @@ impl ConsensusParameters { gas_price_factor, gas_per_byte, max_message_data_length, + chain_id, } } @@ -285,6 +300,7 @@ impl ConsensusParameters { gas_price_factor, gas_per_byte, max_message_data_length, + chain_id, .. } = self; @@ -302,6 +318,7 @@ impl ConsensusParameters { gas_price_factor, gas_per_byte, max_message_data_length, + chain_id, } } @@ -320,6 +337,7 @@ impl ConsensusParameters { gas_price_factor, gas_per_byte, max_message_data_length, + chain_id, .. } = self; @@ -337,6 +355,7 @@ impl ConsensusParameters { gas_price_factor, gas_per_byte, max_message_data_length, + chain_id, } } @@ -355,6 +374,7 @@ impl ConsensusParameters { gas_price_factor, gas_per_byte, max_message_data_length, + chain_id, .. } = self; @@ -372,6 +392,7 @@ impl ConsensusParameters { gas_price_factor, gas_per_byte, max_message_data_length, + chain_id, } } @@ -390,6 +411,7 @@ impl ConsensusParameters { gas_price_factor, gas_per_byte, max_message_data_length, + chain_id, .. } = self; @@ -407,6 +429,7 @@ impl ConsensusParameters { gas_price_factor, gas_per_byte, max_message_data_length, + chain_id, } } @@ -425,6 +448,7 @@ impl ConsensusParameters { max_predicate_data_length, gas_per_byte, max_message_data_length, + chain_id, .. } = self; @@ -442,6 +466,7 @@ impl ConsensusParameters { gas_price_factor, gas_per_byte, max_message_data_length, + chain_id, } } @@ -459,6 +484,7 @@ impl ConsensusParameters { max_predicate_data_length, gas_price_factor, max_message_data_length, + chain_id, .. } = self; @@ -476,6 +502,7 @@ impl ConsensusParameters { gas_price_factor, gas_per_byte, max_message_data_length, + chain_id, } } @@ -494,6 +521,7 @@ impl ConsensusParameters { max_predicate_data_length, gas_price_factor, gas_per_byte, + chain_id, .. } = self; @@ -511,6 +539,7 @@ impl ConsensusParameters { gas_price_factor, gas_per_byte, max_message_data_length, + chain_id, } } } @@ -540,4 +569,5 @@ pub mod default_parameters { pub const GAS_PRICE_FACTOR: u64 = ConsensusParameters::DEFAULT.gas_price_factor; pub const GAS_PER_BYTE: u64 = ConsensusParameters::DEFAULT.gas_per_byte; pub const MAX_MESSAGE_DATA_LENGTH: u64 = ConsensusParameters::DEFAULT.max_message_data_length; + pub const CHAIN_ID: u64 = ConsensusParameters::DEFAULT.chain_id; } diff --git a/fuel-tx/src/transaction/types/create.rs b/fuel-tx/src/transaction/types/create.rs index 5593d51ff8..b027cfc17f 100644 --- a/fuel-tx/src/transaction/types/create.rs +++ b/fuel-tx/src/transaction/types/create.rs @@ -98,7 +98,7 @@ impl Chargeable for Create { impl FormatValidityChecks for Create { #[cfg(feature = "std")] - fn check_signatures(&self) -> Result<(), CheckError> { + fn check_signatures(&self, parameters: &ConsensusParameters) -> Result<(), CheckError> { use crate::UniqueIdentifier; let id = self.id(); @@ -106,7 +106,7 @@ impl FormatValidityChecks for Create { self.inputs() .iter() .enumerate() - .try_for_each(|(index, input)| input.check_signature(index, &id, &self.witnesses))?; + .try_for_each(|(index, input)| input.check_signature(index, &id, &self.witnesses, parameters))?; Ok(()) } diff --git a/fuel-tx/src/transaction/types/input.rs b/fuel-tx/src/transaction/types/input.rs index d9ae8afd53..504e1fe145 100644 --- a/fuel-tx/src/transaction/types/input.rs +++ b/fuel-tx/src/transaction/types/input.rs @@ -1,9 +1,9 @@ -use crate::{TxPointer, UtxoId}; +use crate::{ConsensusParameters, TxPointer, UtxoId}; use alloc::vec::Vec; use coin::*; use consts::*; use contract::*; -use fuel_crypto::PublicKey; +use fuel_crypto::{Hasher, PublicKey}; use fuel_types::bytes::{SizedBytes, WORD_SIZE}; use fuel_types::{bytes, Nonce}; use fuel_types::{Address, AssetId, Bytes32, ContractId, MessageId, Word}; @@ -566,7 +566,7 @@ impl Input { compute_message_id(sender, recipient, nonce, amount, data) } - pub fn predicate_owner

(predicate: P) -> Address + pub fn predicate_owner

(predicate: P, params: &ConsensusParameters) -> Address where P: AsRef<[u8]>, { @@ -574,15 +574,21 @@ impl Input { let root = Contract::root_from_code(predicate); - (*root).into() + let mut hasher = Hasher::default(); + + hasher.input(ContractId::SEED); + hasher.input(params.chain_id.to_be_bytes()); + hasher.input(root); + + (*hasher.digest()).into() } #[cfg(feature = "std")] - pub fn is_predicate_owner_valid

(owner: &Address, predicate: P) -> bool + pub fn is_predicate_owner_valid

(owner: &Address, predicate: P, params: &ConsensusParameters) -> bool where P: AsRef<[u8]>, { - owner == &Self::predicate_owner(predicate) + owner == &Self::predicate_owner(predicate, params) } /// Prepare the output for VM predicate execution diff --git a/fuel-tx/src/transaction/types/mint.rs b/fuel-tx/src/transaction/types/mint.rs index 3852977e79..00a763cdfe 100644 --- a/fuel-tx/src/transaction/types/mint.rs +++ b/fuel-tx/src/transaction/types/mint.rs @@ -100,7 +100,7 @@ impl crate::UniqueIdentifier for Mint { impl FormatValidityChecks for Mint { #[cfg(feature = "std")] - fn check_signatures(&self) -> Result<(), CheckError> { + fn check_signatures(&self, _: &ConsensusParameters) -> Result<(), CheckError> { Ok(()) } diff --git a/fuel-tx/src/transaction/types/script.rs b/fuel-tx/src/transaction/types/script.rs index a867c4fc7b..18a710647a 100644 --- a/fuel-tx/src/transaction/types/script.rs +++ b/fuel-tx/src/transaction/types/script.rs @@ -126,7 +126,7 @@ impl Chargeable for Script { impl FormatValidityChecks for Script { #[cfg(feature = "std")] - fn check_signatures(&self) -> Result<(), CheckError> { + fn check_signatures(&self, parameters: &ConsensusParameters) -> Result<(), CheckError> { use crate::UniqueIdentifier; let id = self.id(); @@ -134,7 +134,7 @@ impl FormatValidityChecks for Script { self.inputs() .iter() .enumerate() - .try_for_each(|(index, input)| input.check_signature(index, &id, &self.witnesses))?; + .try_for_each(|(index, input)| input.check_signature(index, &id, &self.witnesses, parameters))?; Ok(()) } diff --git a/fuel-tx/src/transaction/validity.rs b/fuel-tx/src/transaction/validity.rs index 544a58ac01..055f57b959 100644 --- a/fuel-tx/src/transaction/validity.rs +++ b/fuel-tx/src/transaction/validity.rs @@ -29,13 +29,19 @@ impl Input { parameters: &ConsensusParameters, ) -> Result<(), CheckError> { self.check_without_signature(index, outputs, witnesses, parameters)?; - self.check_signature(index, txhash, witnesses)?; + self.check_signature(index, txhash, witnesses, parameters)?; Ok(()) } #[cfg(feature = "std")] - pub fn check_signature(&self, index: usize, txhash: &Bytes32, witnesses: &[Witness]) -> Result<(), CheckError> { + pub fn check_signature( + &self, + index: usize, + txhash: &Bytes32, + witnesses: &[Witness], + parameters: &ConsensusParameters, + ) -> Result<(), CheckError> { match self { Self::CoinSigned(CoinSigned { witness_index, owner, .. @@ -83,7 +89,9 @@ impl Input { recipient: owner, predicate, .. - }) if !Input::is_predicate_owner_valid(owner, predicate) => Err(CheckError::InputPredicateOwner { index }), + }) if !Input::is_predicate_owner_valid(owner, predicate, parameters) => { + Err(CheckError::InputPredicateOwner { index }) + } _ => Ok(()), } @@ -183,14 +191,14 @@ pub trait FormatValidityChecks { /// of fields according to rules in the specification and validity of signatures. fn check(&self, block_height: Word, parameters: &ConsensusParameters) -> Result<(), CheckError> { self.check_without_signatures(block_height, parameters)?; - self.check_signatures()?; + self.check_signatures(parameters)?; Ok(()) } #[cfg(feature = "std")] /// Validates that all required signatures are set in the transaction and that they are valid. - fn check_signatures(&self) -> Result<(), CheckError>; + fn check_signatures(&self, parameters: &ConsensusParameters) -> Result<(), CheckError>; /// Validates the transactions according to rules from the specification: /// https://github.com/FuelLabs/fuel-specs/blob/master/src/protocol/tx_format/transaction.md#transaction @@ -199,11 +207,11 @@ pub trait FormatValidityChecks { impl FormatValidityChecks for Transaction { #[cfg(feature = "std")] - fn check_signatures(&self) -> Result<(), CheckError> { + fn check_signatures(&self, parameters: &ConsensusParameters) -> Result<(), CheckError> { match self { - Transaction::Script(script) => script.check_signatures(), - Transaction::Create(create) => create.check_signatures(), - Transaction::Mint(mint) => mint.check_signatures(), + Transaction::Script(script) => script.check_signatures(parameters), + Transaction::Create(create) => create.check_signatures(parameters), + Transaction::Mint(mint) => mint.check_signatures(parameters), } } diff --git a/fuel-vm/src/checked_transaction.rs b/fuel-vm/src/checked_transaction.rs index 51311a8798..42cd62b056 100644 --- a/fuel-vm/src/checked_transaction.rs +++ b/fuel-vm/src/checked_transaction.rs @@ -91,9 +91,9 @@ impl Checked { } /// Performs check of signatures, if not yet done. - pub fn check_signatures(mut self) -> Result { + pub fn check_signatures(mut self, parameters: &ConsensusParameters) -> Result { if !self.checks_bitmask.contains(Checks::Signatures) { - self.transaction.check_signatures()?; + self.transaction.check_signatures(parameters)?; self.checks_bitmask.insert(Checks::Signatures); } Ok(self) @@ -157,7 +157,7 @@ pub trait IntoChecked: FormatValidityChecks + Sized { Checked: CheckPredicates, { self.into_checked_basic(block_height, params)? - .check_signatures()? + .check_signatures(params)? .check_predicates(params, gas_costs) } @@ -772,7 +772,7 @@ mod tests { .into_checked_basic(block_height, ¶ms) .unwrap() // Sets Checks::Signatures - .check_signatures() + .check_signatures(¶ms) .unwrap(); assert!(checked.checks().contains(Checks::Basic | Checks::Signatures)); @@ -851,7 +851,7 @@ mod tests { fn predicate_tx(rng: &mut StdRng, gas_price: u64, gas_limit: u64, fee_input_amount: u64) -> Script { let asset = AssetId::default(); let predicate = vec![op::ret(1)].into_iter().collect::>(); - let owner = Input::predicate_owner(&predicate); + let owner = Input::predicate_owner(&predicate, &ConsensusParameters::DEFAULT); TransactionBuilder::script(vec![], vec![]) .gas_price(gas_price) .gas_limit(gas_limit) diff --git a/fuel-vm/src/interpreter/executors/main.rs b/fuel-vm/src/interpreter/executors/main.rs index 866ba5596f..ced4fb99a7 100644 --- a/fuel-vm/src/interpreter/executors/main.rs +++ b/fuel-vm/src/interpreter/executors/main.rs @@ -50,7 +50,7 @@ impl Interpreter { Tx: ExecutableTransaction, ::Metadata: CheckedMetadata, { - if !checked.transaction().check_predicate_owners() { + if !checked.transaction().check_predicate_owners(¶ms) { return Err(PredicateVerificationFailed::InvalidOwner); } diff --git a/fuel-vm/src/tests/metadata.rs b/fuel-vm/src/tests/metadata.rs index 8379cee3f9..31ed053af3 100644 --- a/fuel-vm/src/tests/metadata.rs +++ b/fuel-vm/src/tests/metadata.rs @@ -207,7 +207,7 @@ fn get_transaction_fields() { rng.fill(predicate_data.as_mut_slice()); - let owner = (*Contract::root_from_code(&predicate)).into(); + let owner = Input::predicate_owner(&predicate, &ConsensusParameters::DEFAULT); let input_coin_predicate = Input::coin_predicate( rng.gen(), owner, @@ -232,7 +232,7 @@ fn get_transaction_fields() { rng.fill(m_data.as_mut_slice()); rng.fill(m_predicate_data.as_mut_slice()); - let owner = Input::predicate_owner(&m_predicate); + let owner = Input::predicate_owner(&m_predicate, ¶ms); let message_predicate = Input::message_data_predicate( rng.gen(), owner, diff --git a/fuel-vm/src/tests/predicate.rs b/fuel-vm/src/tests/predicate.rs index 108da18202..c2f20b104e 100644 --- a/fuel-vm/src/tests/predicate.rs +++ b/fuel-vm/src/tests/predicate.rs @@ -1,5 +1,5 @@ use fuel_asm::{op, GMArgs, GTFArgs, Instruction, RegId}; -use fuel_tx::TransactionBuilder; +use fuel_tx::{ConsensusParameters, TransactionBuilder}; use rand::{rngs::StdRng, Rng, SeedableRng}; use fuel_vm::prelude::*; @@ -27,7 +27,7 @@ where let height = 0; let params = ConsensusParameters::default(); - let owner = Input::predicate_owner(&predicate); + let owner = Input::predicate_owner(&predicate, ¶ms); let input = Input::coin_predicate( utxo_id, owner, @@ -133,7 +133,7 @@ fn execute_gas_metered_predicates(predicates: Vec>) -> Result Date: Tue, 21 Mar 2023 19:32:30 -0700 Subject: [PATCH 02/10] include chain id in tx id --- fuel-tx/src/builder.rs | 48 ++++++------ fuel-tx/src/tests/bytes.rs | 4 +- fuel-tx/src/tests/offset.rs | 2 +- fuel-tx/src/tests/prepared_init.rs | 2 +- fuel-tx/src/tests/valid_cases/input.rs | 15 ++-- fuel-tx/src/tests/valid_cases/transaction.rs | 74 +++++++++---------- fuel-tx/src/transaction/id.rs | 44 +++++++---- fuel-tx/src/transaction/metadata.rs | 15 ++-- fuel-tx/src/transaction/types/create.rs | 16 ++-- .../transaction/types/input/snapshot_tests.rs | 14 ++-- fuel-tx/src/transaction/types/mint.rs | 18 +++-- fuel-tx/src/transaction/types/script.rs | 16 ++-- fuel-tx/test-helpers/src/lib.rs | 9 ++- fuel-vm/src/checked_transaction.rs | 18 ++--- fuel-vm/src/checked_transaction/builder.rs | 4 +- fuel-vm/src/checked_transaction/types.rs | 6 +- fuel-vm/src/interpreter/initialization.rs | 2 +- fuel-vm/src/tests/blockchain.rs | 2 +- 18 files changed, 171 insertions(+), 138 deletions(-) diff --git a/fuel-tx/src/builder.rs b/fuel-tx/src/builder.rs index 0ab08f4b8d..fb5e4213b1 100644 --- a/fuel-tx/src/builder.rs +++ b/fuel-tx/src/builder.rs @@ -1,6 +1,6 @@ use crate::transaction::field::{BytecodeLength, BytecodeWitnessIndex, Witnesses}; use crate::transaction::{field, Chargeable, Create, Executable, Script}; -use crate::{Cacheable, Input, Mint, Output, StorageSlot, Transaction, TxPointer, Witness}; +use crate::{Cacheable, ConsensusParameters, Input, Mint, Output, StorageSlot, Transaction, TxPointer, Witness}; #[cfg(feature = "std")] use crate::Signable; @@ -276,25 +276,25 @@ impl TransactionBuilder { } #[cfg(feature = "std")] - pub fn _finalize(&mut self) -> Tx { + pub fn _finalize(&mut self, parameters: &ConsensusParameters) -> Tx { self.prepare_finalize(); let mut tx = core::mem::take(&mut self.tx); - self.sign_keys.iter().for_each(|k| tx.sign_inputs(k)); + self.sign_keys.iter().for_each(|k| tx.sign_inputs(k, parameters)); - tx.precompute(); + tx.precompute(parameters); tx } #[cfg(feature = "std")] - pub fn _finalize_without_signature(&mut self) -> Tx { + pub fn _finalize_without_signature(&mut self, parameters: &ConsensusParameters) -> Tx { self.prepare_finalize(); let mut tx = core::mem::take(&mut self.tx); - tx.precompute(); + tx.precompute(parameters); tx } @@ -308,43 +308,43 @@ impl TransactionBuilder { } pub trait Finalizable { - fn finalize(&mut self) -> Tx; + fn finalize(&mut self, parameters: &ConsensusParameters) -> Tx; - fn finalize_without_signature(&mut self) -> Tx; + fn finalize_without_signature(&mut self, parameters: &ConsensusParameters) -> Tx; } #[cfg(feature = "std")] impl Finalizable for TransactionBuilder { - fn finalize(&mut self) -> Mint { + fn finalize(&mut self, parameters: &ConsensusParameters) -> Mint { let mut tx = core::mem::take(&mut self.tx); - tx.precompute(); + tx.precompute(parameters); tx } - fn finalize_without_signature(&mut self) -> Mint { - self.finalize() + fn finalize_without_signature(&mut self, parameters: &ConsensusParameters) -> Mint { + self.finalize(parameters) } } #[cfg(feature = "std")] impl Finalizable for TransactionBuilder { - fn finalize(&mut self) -> Create { - self._finalize() + fn finalize(&mut self, parameters: &ConsensusParameters) -> Create { + self._finalize(parameters) } - fn finalize_without_signature(&mut self) -> Create { - self._finalize_without_signature() + fn finalize_without_signature(&mut self, parameters: &ConsensusParameters) -> Create { + self._finalize_without_signature(parameters) } } #[cfg(feature = "std")] impl Finalizable