From b8c05e558b63b07bb12d3297e7e11ec63d794647 Mon Sep 17 00:00:00 2001 From: xgreenx Date: Fri, 3 Nov 2023 00:35:50 +0000 Subject: [PATCH 01/18] Removed subtraction of predicate used gas from the gas limit. --- fuel-vm/src/checked_transaction.rs | 16 +++++----------- fuel-vm/src/checked_transaction/types.rs | 18 ++---------------- fuel-vm/src/interpreter.rs | 22 ---------------------- fuel-vm/src/interpreter/initialization.rs | 16 +++------------- 4 files changed, 10 insertions(+), 62 deletions(-) diff --git a/fuel-vm/src/checked_transaction.rs b/fuel-vm/src/checked_transaction.rs index 7e69aa5ae6..a5f4f9ffbe 100644 --- a/fuel-vm/src/checked_transaction.rs +++ b/fuel-vm/src/checked_transaction.rs @@ -38,7 +38,6 @@ pub use types::*; use crate::{ error::PredicateVerificationFailed, - interpreter::CheckedMetadata as CheckedMetadataAccessTrait, prelude::*, }; @@ -317,10 +316,8 @@ where params: &CheckPredicateParams, ) -> Result { if !self.checks_bitmask.contains(Checks::Predicates) { - let checked = - Interpreter::::check_predicates(&self, params)?; + Interpreter::::check_predicates(&self, params)?; self.checks_bitmask.insert(Checks::Predicates); - self.metadata.set_gas_used_by_predicates(checked.gas_used()); } Ok(self) } @@ -333,15 +330,12 @@ where E: ParallelExecutor, { if !self.checks_bitmask.contains(Checks::Predicates) { - let predicates_checked = - Interpreter::::check_predicates_async::( - &self, params, - ) - .await?; + Interpreter::::check_predicates_async::( + &self, params, + ) + .await?; self.checks_bitmask.insert(Checks::Predicates); - self.metadata - .set_gas_used_by_predicates(predicates_checked.gas_used()); Ok(self) } else { diff --git a/fuel-vm/src/checked_transaction/types.rs b/fuel-vm/src/checked_transaction/types.rs index ddfbaf7993..1c724935ee 100644 --- a/fuel-vm/src/checked_transaction/types.rs +++ b/fuel-vm/src/checked_transaction/types.rs @@ -72,10 +72,7 @@ pub mod create { FormatValidityChecks, TransactionFee, }; - use fuel_types::{ - BlockHeight, - Word, - }; + use fuel_types::BlockHeight; /// Metdata produced by checking [`fuel_tx::Create`]. #[derive(Debug, Clone, Eq, PartialEq, Hash)] @@ -86,9 +83,6 @@ pub mod create { pub block_height: BlockHeight, /// The fees and gas usage pub fee: TransactionFee, - /// If predicates have been checked, this is how much gas checking them used. - /// This must be zero if the predicates have not been checked yet. - pub gas_used_by_predicates: Word, } impl IntoChecked for Create { @@ -123,7 +117,6 @@ pub mod create { free_balances: NonRetryableFreeBalances(non_retryable_balances), block_height, fee, - gas_used_by_predicates: 0, }; Ok(Checked::basic(self, metadata)) @@ -185,10 +178,7 @@ pub mod script { Script, TransactionFee, }; - use fuel_types::{ - BlockHeight, - Word, - }; + use fuel_types::BlockHeight; /// Metdata produced by checking [`fuel_tx::Script`]. #[derive(Debug, Clone, Eq, PartialEq, Hash)] @@ -201,9 +191,6 @@ pub mod script { pub block_height: BlockHeight, /// The fees and gas usage pub fee: TransactionFee, - /// If predicates have been checked, this is how much gas checking them used. - /// This must be zero if the predicates have not been checked yet. - pub gas_used_by_predicates: Word, } impl IntoChecked for Script { @@ -238,7 +225,6 @@ pub mod script { }, block_height, fee, - gas_used_by_predicates: 0, }; Ok(Checked::basic(self, metadata)) diff --git a/fuel-vm/src/interpreter.rs b/fuel-vm/src/interpreter.rs index ff03e6dc0f..2666f96373 100644 --- a/fuel-vm/src/interpreter.rs +++ b/fuel-vm/src/interpreter.rs @@ -547,12 +547,6 @@ pub struct InitialBalances { pub trait CheckedMetadata { /// Returns the initial balances from the checked metadata of the transaction. fn balances(&self) -> InitialBalances; - - /// Get gas used by predicates. Returns zero if the predicates haven't been checked. - fn gas_used_by_predicates(&self) -> Word; - - /// Set gas used by predicates after checking them. - fn set_gas_used_by_predicates(&mut self, gas_used: Word); } impl CheckedMetadata for ScriptCheckedMetadata { @@ -562,14 +556,6 @@ impl CheckedMetadata for ScriptCheckedMetadata { retryable: Some(self.retryable_balance), } } - - fn gas_used_by_predicates(&self) -> Word { - self.gas_used_by_predicates - } - - fn set_gas_used_by_predicates(&mut self, gas_used: Word) { - self.gas_used_by_predicates = gas_used; - } } impl CheckedMetadata for CreateCheckedMetadata { @@ -579,14 +565,6 @@ impl CheckedMetadata for CreateCheckedMetadata { retryable: None, } } - - fn gas_used_by_predicates(&self) -> Word { - self.gas_used_by_predicates - } - - fn set_gas_used_by_predicates(&mut self, gas_used: Word) { - self.gas_used_by_predicates = gas_used; - } } pub(crate) struct InputContracts<'vm, I> { diff --git a/fuel-vm/src/interpreter/initialization.rs b/fuel-vm/src/interpreter/initialization.rs index de0cdf6af8..c9507baca4 100644 --- a/fuel-vm/src/interpreter/initialization.rs +++ b/fuel-vm/src/interpreter/initialization.rs @@ -11,10 +11,7 @@ use crate::{ }, consts::*, context::Context, - error::{ - Bug, - InterpreterError, - }, + error::InterpreterError, prelude::RuntimeError, storage::InterpreterStorage, }; @@ -22,10 +19,7 @@ use crate::{ use fuel_asm::RegId; use fuel_types::Word; -use crate::{ - error::BugVariant::GlobalGasUnderflow, - interpreter::CheckedMetadata, -}; +use crate::interpreter::CheckedMetadata; impl Interpreter where @@ -115,13 +109,9 @@ where self.context = Context::Script { block_height }; - let gas_used_by_predicates = checked.metadata().gas_used_by_predicates(); let (mut tx, metadata): (Tx, Tx::Metadata) = checked.into(); tx.prepare_init_script(); - let gas_limit = tx - .limit() - .checked_sub(gas_used_by_predicates) - .ok_or_else(|| Bug::new(GlobalGasUnderflow))?; + let gas_limit = tx.limit(); let initial_balances = metadata.balances(); let runtime_balances = initial_balances.try_into()?; From 0b6d2960404cb4ffd58a92da520bd9112581f3da Mon Sep 17 00:00:00 2001 From: xgreenx Date: Fri, 3 Nov 2023 01:01:59 +0000 Subject: [PATCH 02/18] Updated values of teh GTF --- fuel-asm/src/args.rs | 178 ++++++++++++++-------------- fuel-vm/src/interpreter/metadata.rs | 2 +- fuel-vm/src/tests/metadata.rs | 2 +- 3 files changed, 93 insertions(+), 89 deletions(-) diff --git a/fuel-asm/src/args.rs b/fuel-asm/src/args.rs index 91eb0ce629..f7b0d0eb46 100644 --- a/fuel-asm/src/args.rs +++ b/fuel-asm/src/args.rs @@ -50,218 +50,221 @@ crate::enum_try_from! { /// Set `$rA` to `tx.type` Type = 0x001, - /// Set `$rA` to `tx.gasPrice` - ScriptGasPrice = 0x002, - /// Set `$rA` to `tx.gasLimit` - ScriptGasLimit = 0x003, - - /// Set `$rA` to `tx.maturity` - ScriptMaturity = 0x004, + ScriptGasLimit = 0x002, /// Set `$rA` to `tx.scriptLength` - ScriptLength = 0x005, + ScriptLength = 0x003, /// Set `$rA` to `tx.scriptDataLength` - ScriptDataLength = 0x006, + ScriptDataLength = 0x004, /// Set `$rA` to `tx.inputsCount` - ScriptInputsCount = 0x007, + ScriptInputsCount = 0x005, /// Set `$rA` to `tx.outputsCount` - ScriptOutputsCount = 0x008, + ScriptOutputsCount = 0x006, /// Set `$rA` to `tx.witnessesCount` - ScriptWitnessesCound = 0x009, + ScriptWitnessesCount = 0x007, /// Set `$rA` to `Memory address of tx.receiptsRoot` - ScriptReceiptsRoot = 0x00A, + ScriptReceiptsRoot = 0x008, /// Set `$rA` to `Memory address of tx.script` - Script = 0x00B, + Script = 0x009, /// Set `$rA` to `Memory address of tx.scriptData` - ScriptData = 0x00C, + ScriptData = 0x00A, /// Set `$rA` to `Memory address of tx.inputs[$rB]` - ScriptInputAtIndex = 0x00D, + ScriptInputAtIndex = 0x00B, /// Set `$rA` to `Memory address of t.outputs[$rB]` - ScriptOutputAtIndex = 0x00E, + ScriptOutputAtIndex = 0x00C, /// Set `$rA` to `Memory address of tx.witnesses[$rB]` - ScriptWitnessAtIndex = 0x00F, - - /// Set `$rA` to `tx.gasPrice` - CreateGasPrice = 0x010, - - /// Set `$rA` to `tx.gasLimit` - CreateGasLimit = 0x011, - - /// Set `$rA` to `tx.maturity` - CreateMaturity = 0x012, + ScriptWitnessAtIndex = 0x00D, /// Set `$rA` to `tx.bytecodeLength` - CreateBytecodeLength = 0x013, + CreateBytecodeLength = 0x100, /// Set `$rA` to `tx.bytecodeWitnessIndex` - CreateBytecodeWitnessIndex = 0x014, + CreateBytecodeWitnessIndex = 0x101, /// Set `$rA` to `tx.storageSlotsCount` - CreateStorageSlotsCount = 0x015, + CreateStorageSlotsCount = 0x102, /// Set `$rA` to `tx.inputsCount` - CreateInputsCount = 0x016, + CreateInputsCount = 0x103, /// Set `$rA` to `tx.outputsCount` - CreateOutputsCount = 0x017, + CreateOutputsCount = 0x104, /// Set `$rA` to `tx.witnessesCount` - CreateWitnessesCount = 0x018, + CreateWitnessesCount = 0x105, /// Set `$rA` to `Memory address of tx.salt` - CreateSalt = 0x019, + CreateSalt = 0x106, /// Set `$rA` to `Memory address of tx.storageSlots[$rB]` - CreateStorageSlotAtIndex = 0x01A, + CreateStorageSlotAtIndex = 0x107, /// Set `$rA` to `Memory address of tx.inputs[$rB]` - CreateInputAtIndex = 0x01B, + CreateInputAtIndex = 0x108, /// Set `$rA` to `Memory address of t.outputs[$rB]` - CreateOutputAtIndex = 0x01C, + CreateOutputAtIndex = 0x109, /// Set `$rA` to `Memory address of tx.witnesses[$rB]` - CreateWitnessAtIndex = 0x01D, + CreateWitnessAtIndex = 0x10A, /// Set `$rA` to `tx.inputs[$rB].type` - InputType = 0x101, + InputType = 0x200, /// Set `$rA` to `Memory address of tx.inputs[$rB].txID` - InputCoinTxId = 0x102, + InputCoinTxId = 0x201, /// Set `$rA` to `tx.inputs[$rB].outputIndex` - InputCoinOutputIndex = 0x103, + InputCoinOutputIndex = 0x202, /// Set `$rA` to `Memory address of tx.inputs[$rB].owner` - InputCoinOwner = 0x104, + InputCoinOwner = 0x203, /// Set `$rA` to `tx.inputs[$rB].amount` - InputCoinAmount = 0x105, + InputCoinAmount = 0x204, /// Set `$rA` to `Memory address of tx.inputs[$rB].asset_id` - InputCoinAssetId = 0x106, + InputCoinAssetId = 0x205, /// Set `$rA` to `Memory address of tx.inputs[$rB].txPointer` - InputCoinTxPointer = 0x107, + InputCoinTxPointer = 0x206, /// Set `$rA` to `tx.inputs[$rB].witnessIndex` - InputCoinWitnessIndex = 0x108, + InputCoinWitnessIndex = 0x207, /// Set `$rA` to `tx.inputs[$rB].maturity` - InputCoinMaturity = 0x109, + InputCoinMaturity = 0x208, /// Set `$rA` to `tx.inputs[$rB].predicateLength` - InputCoinPredicateLength = 0x10A, + InputCoinPredicateLength = 0x209, /// Set `$rA` to `tx.inputs[$rB].predicateDataLength` - InputCoinPredicateDataLength = 0x10B, + InputCoinPredicateDataLength = 0x20A, /// Set `$rA` to `Memory address of tx.inputs[$rB].predicate` - InputCoinPredicate = 0x10C, + InputCoinPredicate = 0x20B, /// Set `$rA` to `Memory address of tx.inputs[$rB].predicateData` - InputCoinPredicateData = 0x10D, + InputCoinPredicateData = 0x20C, /// Set `$rA` to `Memory address of tx.inputs[$rB].predicateGasUsed` - InputCoinPredicateGasUsed = 0x10E, + InputCoinPredicateGasUsed = 0x20D, /// Set `$rA` to `Memory address of tx.inputs[$rB].txID` - InputContractTxId = 0x10F, + InputContractTxId = 0x220, /// Set `$rA` to `tx.inputs[$rB].outputIndex` - InputContractOutputIndex = 0x110, + InputContractOutputIndex = 0x221, /// Set `$rA` to `Memory address of tx.inputs[$rB].balanceRoot` - InputContractBalanceRoot = 0x111, + InputContractBalanceRoot = 0x222, /// Set `$rA` to `Memory address of tx.inputs[$rB].stateRoot` - InputContractStateRoot = 0x112, + InputContractStateRoot = 0x223, /// Set `$rA` to `Memory address of tx.inputs[$rB].txPointer` - InputContractTxPointer = 0x113, + InputContractTxPointer = 0x224, /// Set `$rA` to `Memory address of tx.inputs[$rB].contractID` - InputContractId = 0x114, + InputContractId = 0x225, /// Set `$rA` to `Memory address of tx.inputs[$rB].sender` - InputMessageSender = 0x115, + InputMessageSender = 0x240, /// Set `$rA` to `Memory address of tx.inputs[$rB].recipient` - InputMessageRecipient = 0x116, + InputMessageRecipient = 0x241, /// Set `$rA` to `tx.inputs[$rB].amount` - InputMessageAmount = 0x117, + InputMessageAmount = 0x242, /// Set `$rA` to `Memory address of tx.inputs[$rB].nonce` - InputMessageNonce = 0x118, + InputMessageNonce = 0x243, /// Set `$rA` to `tx.inputs[$rB].witnessIndex` - InputMessageWitnessIndex = 0x119, + InputMessageWitnessIndex = 0x244, /// Set `$rA` to `tx.inputs[$rB].dataLength` - InputMessageDataLength = 0x11A, + InputMessageDataLength = 0x245, /// Set `$rA` to `tx.inputs[$rB].predicateLength` - InputMessagePredicateLength = 0x11B, + InputMessagePredicateLength = 0x246, /// Set `$rA` to `tx.inputs[$rB].predicateDataLength` - InputMessagePredicateDataLength = 0x11C, + InputMessagePredicateDataLength = 0x247, /// Set `$rA` to `Memory address of tx.inputs[$rB].data` - InputMessageData = 0x11D, + InputMessageData = 0x248, /// Set `$rA` to `Memory address of tx.inputs[$rB].predicate` - InputMessagePredicate = 0x11E, + InputMessagePredicate = 0x249, /// Set `$rA` to `Memory address of tx.inputs[$rB].predicateData` - InputMessagePredicateData = 0x11F, + InputMessagePredicateData = 0x24A, /// Set `$rA` to `Memory address of tx.inputs[$rB].predicateGasUsed` - InputMessagePredicateGasUsed = 0x120, + InputMessagePredicateGasUsed = 0x24B, /// Set `$rA` to `tx.outputs[$rB].type` - OutputType = 0x201, + OutputType = 0x300, /// Set `$rA` to `Memory address of tx.outputs[$rB].to` - OutputCoinTo = 0x202, + OutputCoinTo = 0x301, /// Set `$rA` to `tx.outputs[$rB].amount` - OutputCoinAmount = 0x203, + OutputCoinAmount = 0x302, /// Set `$rA` to `Memory address of tx.outputs[$rB].asset_id` - OutputCoinAssetId = 0x204, + OutputCoinAssetId = 0x303, /// Set `$rA` to `tx.outputs[$rB].inputIndex` - OutputContractInputIndex = 0x205, + OutputContractInputIndex = 0x304, /// Set `$rA` to `Memory address of tx.outputs[$rB].balanceRoot` - OutputContractBalanceRoot = 0x206, + OutputContractBalanceRoot = 0x305, /// Set `$rA` to `Memory address of tx.outputs[$rB].stateRoot` - OutputContractStateRoot = 0x207, + OutputContractStateRoot = 0x306, /// Set `$rA` to `Memory address of tx.outputs[$rB].contractID` - OutputContractCreatedContractId = 0x208, + OutputContractCreatedContractId = 0x307, /// Set `$rA` to `Memory address of tx.outputs[$rB].stateRoot` - OutputContractCreatedStateRoot = 0x209, + OutputContractCreatedStateRoot = 0x308, /// Set `$rA` to `tx.witnesses[$rB].dataLength` - WitnessDataLength = 0x301, + WitnessDataLength = 0x400, /// Set `$rA` to `Memory address of tx.witnesses[$rB].data` - WitnessData = 0x302, + WitnessData = 0x401, + + /// Set `$rA` to `count_ones(tx.policyTypes)` + PolicyCount = 0x500, + + /// Set `$rA` to `tx.policies[$rB].type` + PolicyType = 0x501, + + /// Set `$rA` to `tx.policies[0x00].gasPrice` + PolicyGasPrice = 0x502, + + /// Set `$rA` to `tx.policies[count_ones(0b11 & tx.policyTypes) - 1].witnessLimit` + PolicyWitnessLimit = 0x504, + + /// Set `$rA` to `tx.policies[count_ones(0b111 & tx.policyTypes) - 1].maturity` + PolicyMaturity = 0x505, + + /// Set `$rA` to `tx.policies[count_ones(0b1111 & tx.policyTypes) - 1].maxFee` + PolicyMaxFee = 0x506, }, Immediate12 } @@ -295,23 +298,18 @@ fn encode_gm_args() { fn encode_gtf_args() { let args = vec![ GTFArgs::Type, - GTFArgs::ScriptGasPrice, GTFArgs::ScriptGasLimit, - GTFArgs::ScriptMaturity, GTFArgs::ScriptLength, GTFArgs::ScriptDataLength, GTFArgs::ScriptInputsCount, GTFArgs::ScriptOutputsCount, - GTFArgs::ScriptWitnessesCound, + GTFArgs::ScriptWitnessesCount, GTFArgs::ScriptReceiptsRoot, GTFArgs::Script, GTFArgs::ScriptData, GTFArgs::ScriptInputAtIndex, GTFArgs::ScriptOutputAtIndex, GTFArgs::ScriptWitnessAtIndex, - GTFArgs::CreateGasPrice, - GTFArgs::CreateGasLimit, - GTFArgs::CreateMaturity, GTFArgs::CreateBytecodeLength, GTFArgs::CreateBytecodeWitnessIndex, GTFArgs::CreateStorageSlotsCount, @@ -366,6 +364,12 @@ fn encode_gtf_args() { GTFArgs::OutputContractCreatedStateRoot, GTFArgs::WitnessDataLength, GTFArgs::WitnessData, + GTFArgs::PolicyCount, + GTFArgs::PolicyType, + GTFArgs::PolicyGasPrice, + GTFArgs::PolicyWitnessLimit, + GTFArgs::PolicyMaturity, + GTFArgs::PolicyMaxFee, ]; args.into_iter().for_each(|a| { diff --git a/fuel-vm/src/interpreter/metadata.rs b/fuel-vm/src/interpreter/metadata.rs index a6e0144b23..2e2cf02f9b 100644 --- a/fuel-vm/src/interpreter/metadata.rs +++ b/fuel-vm/src/interpreter/metadata.rs @@ -163,7 +163,7 @@ impl GTFInput<'_, Tx> { GTFArgs::ScriptOutputsCount | GTFArgs::CreateOutputsCount => { tx.outputs().len() as Word } - GTFArgs::ScriptWitnessesCound | GTFArgs::CreateWitnessesCount => { + GTFArgs::ScriptWitnessesCount | GTFArgs::CreateWitnessesCount => { tx.witnesses().len() as Word } GTFArgs::ScriptInputAtIndex | GTFArgs::CreateInputAtIndex => { diff --git a/fuel-vm/src/tests/metadata.rs b/fuel-vm/src/tests/metadata.rs index ecf7f3393f..a343a993ef 100644 --- a/fuel-vm/src/tests/metadata.rs +++ b/fuel-vm/src/tests/metadata.rs @@ -506,7 +506,7 @@ fn get_transaction_fields() { op::movi(0x19, 0x00), op::movi(0x11, witnesses.len() as Immediate18), - op::gtf_args(0x10, 0x19, GTFArgs::ScriptWitnessesCound), + op::gtf_args(0x10, 0x19, GTFArgs::ScriptWitnessesCount), op::eq(0x10, 0x10, 0x11), op::and(0x20, 0x20, 0x10), From 4ad331f57fc016e3ffb867abe3d1178ede171827 Mon Sep 17 00:00:00 2001 From: xgreenx Date: Sat, 4 Nov 2023 17:22:59 +0000 Subject: [PATCH 03/18] Implemented `Policies` structure. Updated transaction validity rules according to policies. Updated fee calculation and refund logic. --- Cargo.toml | 1 + fuel-asm/Cargo.toml | 2 +- fuel-tx/Cargo.toml | 3 +- fuel-tx/src/builder.rs | 75 ++- fuel-tx/src/lib.rs | 1 + fuel-tx/src/tests/bytes.rs | 62 +-- fuel-tx/src/tests/valid_cases.rs | 2 +- fuel-tx/src/tests/valid_cases/transaction.rs | 213 +++++---- fuel-tx/src/transaction.rs | 167 ++++--- fuel-tx/src/transaction/fee.rs | 441 +++++------------- fuel-tx/src/transaction/id.rs | 10 +- fuel-tx/src/transaction/policies.rs | 309 ++++++++++++ fuel-tx/src/transaction/types/create.rs | 134 ++---- .../transaction/types/input/snapshot_tests.rs | 24 + ...shot_tests__tx_with_contract_snapshot.snap | 2 +- ...ests__tx_with_predicate_coin_snapshot.snap | 2 +- ...tests__tx_with_predicate_message_coin.snap | 2 +- ...tests__tx_with_predicate_message_data.snap | 2 +- ...t_tests__tx_with_signed_coin_snapshot.snap | 2 +- ...ot_tests__tx_with_signed_message_coin.snap | 2 +- ...ot_tests__tx_with_signed_message_data.snap | 2 +- fuel-tx/src/transaction/types/script.rs | 115 ++--- fuel-tx/src/transaction/validity.rs | 107 +++-- fuel-tx/src/transaction/validity/error.rs | 6 +- fuel-vm/Cargo.toml | 2 +- fuel-vm/src/checked_transaction.rs | 7 +- 26 files changed, 926 insertions(+), 769 deletions(-) create mode 100644 fuel-tx/src/transaction/policies.rs diff --git a/Cargo.toml b/Cargo.toml index 7431fd7f9e..793ef5a2a2 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -29,5 +29,6 @@ fuel-storage = { version = "0.40.0", path = "fuel-storage", default-features = f fuel-tx = { version = "0.40.0", path = "fuel-tx", default-features = false } fuel-types = { version = "0.40.0", path = "fuel-types", default-features = false } fuel-vm = { version = "0.40.0", path = "fuel-vm", default-features = false } +bitflags = "2" bincode = { version = "1.3", default-features = false } criterion = "0.5.0" diff --git a/fuel-asm/Cargo.toml b/fuel-asm/Cargo.toml index 099eb20aa8..b4ab088384 100644 --- a/fuel-asm/Cargo.toml +++ b/fuel-asm/Cargo.toml @@ -12,7 +12,7 @@ description = "Atomic types of the FuelVM." [dependencies] arbitrary = { version = "1.1", features = ["derive"], optional = true } -bitflags = "1.3" +bitflags = { workspace = true } fuel-types = { workspace = true } serde = { version = "1.0", default-features = false, features = ["derive"], optional = true } strum = { version = "0.24", default-features = false, features = ["derive"] } diff --git a/fuel-tx/Cargo.toml b/fuel-tx/Cargo.toml index 1ff1183df4..e0a53a31c1 100644 --- a/fuel-tx/Cargo.toml +++ b/fuel-tx/Cargo.toml @@ -11,6 +11,7 @@ repository = { workspace = true } description = "FuelVM transaction." [dependencies] +bitflags = { workspace = true } derivative = { version = "2.2.0", default-features = false, features = ["use_core"], optional = true } derive_more = { version = "0.99", default-features = false, features = ["display"] } fuel-asm = { workspace = true, default-features = false } @@ -47,4 +48,4 @@ random = ["fuel-crypto/random", "fuel-types/random", "rand"] std = ["alloc", "fuel-asm/std", "fuel-crypto/std", "fuel-merkle/std", "fuel-types/std", "itertools/default", "rand?/default", "serde?/default", "hex/std"] alloc = ["hashbrown", "fuel-types/alloc", "itertools/use_alloc", "derivative", "fuel-merkle", "num-integer", "strum", "strum_macros"] # serde is requiring alloc because its mandatory for serde_json. to avoid adding a new feature only for serde_json, we just require `alloc` here since as of the moment we don't have a use case of serde without alloc. -serde = ["alloc", "dep:serde", "fuel-asm/serde", "fuel-crypto/serde", "fuel-types/serde", "fuel-merkle/serde", "serde_json", "hashbrown/serde"] +serde = ["alloc", "dep:serde", "fuel-asm/serde", "fuel-crypto/serde", "fuel-types/serde", "fuel-merkle/serde", "serde_json", "hashbrown/serde", "bitflags/serde"] diff --git a/fuel-tx/src/builder.rs b/fuel-tx/src/builder.rs index 8819fccf94..524011f615 100644 --- a/fuel-tx/src/builder.rs +++ b/fuel-tx/src/builder.rs @@ -6,6 +6,8 @@ use crate::{ field::{ BytecodeLength, BytecodeWitnessIndex, + GasPrice, + Maturity, Witnesses, }, Chargeable, @@ -34,6 +36,17 @@ use crate::{ Signable, }; +use crate::{ + field::{ + MaxFeeLimit, + WitnessLimit, + }, + policies::Policies, +}; +use alloc::{ + collections::BTreeMap, + vec::Vec, +}; use fuel_crypto::SecretKey; use fuel_types::{ AssetId, @@ -44,21 +57,9 @@ use fuel_types::{ Word, }; -use alloc::{ - collections::BTreeMap, - vec::Vec, -}; - pub trait BuildableAloc where - Self: Default - + Clone - + Executable - + Chargeable - + field::GasLimit - + field::GasPrice - + field::Maturity - + Into, + Self: Default + Clone + Executable + Chargeable + field::Policies + Into, { } @@ -80,31 +81,17 @@ where self.witnesses_mut().push(witness); } - /// Set the gas price - fn set_gas_price(&mut self, price: Word) { - *self.gas_price_mut() = price; - } - /// Set the gas limit - fn set_gas_limit(&mut self, limit: Word) { + fn set_gas_limit(&mut self, limit: Word) + where + Self: field::GasLimit, + { *self.gas_limit_mut() = limit; } - - /// Set the maturity - fn set_maturity(&mut self, maturity: BlockHeight) { - *self.maturity_mut() = maturity; - } } impl BuildableAloc for T where - Self: Default - + Clone - + Executable - + Chargeable - + field::GasLimit - + field::GasPrice - + field::Maturity - + Into + Self: Default + Clone + Executable + Chargeable + field::Policies + Into { } @@ -129,11 +116,10 @@ pub struct TransactionBuilder { impl TransactionBuilder