From 52e25a6c705dd4c2f7f2acc56847062b58b37a11 Mon Sep 17 00:00:00 2001 From: MujkicA <32431923+MujkicA@users.noreply.github.com> Date: Sat, 4 May 2024 01:56:14 +0200 Subject: [PATCH] feat: upgrade fuel-core to 0.26.0 (#1336) Upgrades fuel-core to 0.26.0 and fuel-vm to 0.49.0. Support for upgrade and upload transaction types is not fully implemented. --- .github/workflows/ci.yml | 2 +- Cargo.toml | 31 ++++--- packages/fuels-accounts/src/provider.rs | 4 +- .../src/provider/supported_versions.rs | 2 +- .../configurables_bounded_encoder.rs | 17 ++-- packages/fuels-core/src/types.rs | 9 +- .../fuels-core/src/types/core/raw_slice.rs | 2 - packages/fuels-core/src/types/core/u256.rs | 1 - .../src/types/transaction_builders.rs | 52 ++++++----- .../fuels-core/src/types/wrappers/block.rs | 4 +- .../fuels-core/src/types/wrappers/message.rs | 3 +- .../src/types/wrappers/transaction.rs | 93 ++++++++++++++++++- .../types/wrappers/transaction_response.rs | 2 + packages/fuels-core/src/utils/offsets.rs | 50 +++++++--- packages/fuels-programs/src/call_utils.rs | 2 +- packages/fuels-programs/src/script_calls.rs | 5 +- .../src/fuel_bin_service.rs | 7 +- packages/fuels/tests/providers.rs | 1 + 18 files changed, 206 insertions(+), 81 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 3dcf78e25b..ea2577c450 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -16,7 +16,7 @@ env: CARGO_TERM_COLOR: always DASEL_VERSION: https://github.com/TomWright/dasel/releases/download/v2.3.6/dasel_linux_amd64 RUSTFLAGS: "-D warnings" - FUEL_CORE_VERSION: 0.24.3 + FUEL_CORE_VERSION: 0.26.0 FUEL_CORE_PATCH_BRANCH: RUST_VERSION: 1.76.0 FORC_VERSION: 0.56.0 diff --git a/Cargo.toml b/Cargo.toml index 03797675e5..2bf4de6fe3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -53,7 +53,10 @@ itertools = "0.12.0" portpicker = "0.1.1" proc-macro2 = "1.0.70" quote = "1.0.33" -rand = { version = "0.8.5", default-features = false, features = ["std_rng", "getrandom"] } +rand = { version = "0.8.5", default-features = false, features = [ + "std_rng", + "getrandom", +] } regex = "1.10.2" semver = "1.0.20" serde = { version = "1.0.193", default-features = false } @@ -72,21 +75,21 @@ which = { version = "6.0.0", default-features = false } zeroize = "1.7.0" # Dependencies from the `fuel-core` repository: -fuel-core = { version = "0.24.3", default-features = false } -fuel-core-chain-config = { version = "0.24.3", default-features = false } -fuel-core-client = { version = "0.24.3", default-features = false } -fuel-core-poa = { version = "0.24.3", default-features = false } -fuel-core-services = { version = "0.24.3", default-features = false } -fuel-core-types = { version = "0.24.3", default-features = false } +fuel-core = { version = "0.26.0", default-features = false } +fuel-core-chain-config = { version = "0.26.0", default-features = false } +fuel-core-client = { version = "0.26.0", default-features = false } +fuel-core-poa = { version = "0.26.0", default-features = false } +fuel-core-services = { version = "0.26.0", default-features = false } +fuel-core-types = { version = "0.26.0", default-features = false } # Dependencies from the `fuel-vm` repository: -fuel-asm = { version = "0.48.0" } -fuel-crypto = { version = "0.48.0" } -fuel-merkle = { version = "0.48.0" } -fuel-storage = { version = "0.48.0" } -fuel-tx = { version = "0.48.0" } -fuel-types = { version = "0.48.0" } -fuel-vm = { version = "0.48.0" } +fuel-asm = { version = "0.49.0" } +fuel-crypto = { version = "0.49.0" } +fuel-merkle = { version = "0.49.0" } +fuel-storage = { version = "0.49.0" } +fuel-tx = { version = "0.49.0" } +fuel-types = { version = "0.49.0" } +fuel-vm = { version = "0.49.0" } # Workspace projects fuels = { version = "0.59.0", path = "./packages/fuels" } diff --git a/packages/fuels-accounts/src/provider.rs b/packages/fuels-accounts/src/provider.rs index be4915075b..c5bbcac218 100644 --- a/packages/fuels-accounts/src/provider.rs +++ b/packages/fuels-accounts/src/provider.rs @@ -291,7 +291,9 @@ impl Provider { TransactionExecutionResult::Success { receipts, .. } => { TxStatus::Success { receipts } } - TransactionExecutionResult::Failed { receipts, result } => TxStatus::Revert { + TransactionExecutionResult::Failed { + receipts, result, .. + } => TxStatus::Revert { reason: TransactionExecutionResult::reason(&receipts, &result), receipts, revert_id: 0, diff --git a/packages/fuels-accounts/src/provider/supported_versions.rs b/packages/fuels-accounts/src/provider/supported_versions.rs index 0cc09b892a..d5d55761f7 100644 --- a/packages/fuels-accounts/src/provider/supported_versions.rs +++ b/packages/fuels-accounts/src/provider/supported_versions.rs @@ -1,7 +1,7 @@ use semver::Version; fn get_supported_fuel_core_version() -> Version { - "0.24.2".parse().expect("is valid version") + "0.26.0".parse().expect("is valid version") } #[derive(Debug, PartialEq, Eq)] diff --git a/packages/fuels-core/src/codec/abi_encoder/configurables_bounded_encoder.rs b/packages/fuels-core/src/codec/abi_encoder/configurables_bounded_encoder.rs index 4ef443a5c9..b932dac865 100644 --- a/packages/fuels-core/src/codec/abi_encoder/configurables_bounded_encoder.rs +++ b/packages/fuels-core/src/codec/abi_encoder/configurables_bounded_encoder.rs @@ -241,7 +241,7 @@ impl ConfigurablesBoundedEncoder { fn encode_raw_slice(mut data: Vec) -> Result> { let len = data.len(); - zeropad_to_word_alignment(&mut data); + zeropad_to_word_alignment(&mut data)?; let encoded_data = vec![Data::Inline(data)]; @@ -261,15 +261,14 @@ impl ConfigurablesBoundedEncoder { } fn encode_string_array(arg_string: &StaticStringToken) -> Result { - Ok(Data::Inline(crate::types::pad_string( - arg_string.get_encodable_str()?, - ))) + let padded = crate::types::pad_string(arg_string.get_encodable_str()?)?; + Ok(Data::Inline(padded)) } fn encode_bytes(mut data: Vec) -> Result> { let len = data.len(); - zeropad_to_word_alignment(&mut data); + zeropad_to_word_alignment(&mut data)?; let cap = data.len() as u64; let encoded_data = vec![Data::Inline(data)]; @@ -282,7 +281,11 @@ impl ConfigurablesBoundedEncoder { } } -fn zeropad_to_word_alignment(data: &mut Vec) { - let padded_length = padded_len_usize(data.len()); +fn zeropad_to_word_alignment(data: &mut Vec) -> Result<()> { + let padded_length = padded_len_usize(data.len()) + .ok_or_else(|| error!(Codec, "data length exceeds maximum allowed length"))?; + data.resize(padded_length, 0); + + Ok(()) } diff --git a/packages/fuels-core/src/types.rs b/packages/fuels-core/src/types.rs index c79c5b9366..6f6b0e5c67 100644 --- a/packages/fuels-core/src/types.rs +++ b/packages/fuels-core/src/types.rs @@ -5,6 +5,7 @@ pub use fuel_types::{ }; pub use crate::types::{core::*, token::*, wrappers::*}; +use crate::{error, types::errors::Result}; pub mod bech32; mod core; @@ -33,12 +34,14 @@ pub fn pad_u32(value: u32) -> ByteArray { padded } -pub fn pad_string(s: &str) -> Vec { - let pad = padded_len(s.as_bytes()) - s.len(); +pub fn pad_string(s: &str) -> Result> { + let padded_len = + padded_len(s.as_bytes()).ok_or_else(|| error!(Codec, "string is too long to be padded"))?; + let pad = padded_len - s.len(); let mut padded = s.as_bytes().to_owned(); padded.extend_from_slice(&vec![0; pad]); - padded + Ok(padded) } diff --git a/packages/fuels-core/src/types/core/raw_slice.rs b/packages/fuels-core/src/types/core/raw_slice.rs index 0eb37a8fe7..859081c372 100644 --- a/packages/fuels-core/src/types/core/raw_slice.rs +++ b/packages/fuels-core/src/types/core/raw_slice.rs @@ -1,6 +1,4 @@ #[derive(Debug, PartialEq, Clone, Eq)] -// `RawSlice` is a mapping of the contract type "untyped raw slice" -- currently the only way of -// returning dynamically sized data from a script. pub struct RawSlice(pub Vec); impl From for Vec { diff --git a/packages/fuels-core/src/types/core/u256.rs b/packages/fuels-core/src/types/core/u256.rs index d2f504918f..d869c6f778 100644 --- a/packages/fuels-core/src/types/core/u256.rs +++ b/packages/fuels-core/src/types/core/u256.rs @@ -13,7 +13,6 @@ use crate::{ }; construct_uint! { - /// 256-bit unsigned integer. pub struct U256(4); } diff --git a/packages/fuels-core/src/types/transaction_builders.rs b/packages/fuels-core/src/types/transaction_builders.rs index ff70d70db1..96288a0979 100644 --- a/packages/fuels-core/src/types/transaction_builders.rs +++ b/packages/fuels-core/src/types/transaction_builders.rs @@ -21,7 +21,7 @@ use itertools::Itertools; use crate::{ constants::{SIGNATURE_WITNESS_SIZE, WITNESS_STATIC_SIZE, WORD_SIZE}, - offsets, + error, offsets, traits::Signer, types::{ bech32::Bech32Address, @@ -263,22 +263,19 @@ macro_rules! impl_tx_trait { .collect(); } - fn generate_fuel_policies(&self) -> Policies { - let mut policies = Policies::default(); + fn generate_fuel_policies(&self) -> Result { + let witness_limit = match self.tx_policies.witness_limit() { + Some(limit) => limit, + None => self.calculate_witnesses_size()?, + }; + let mut policies = Policies::default().with_witness_limit(witness_limit); + // `MaxFee` set to `tip` or `0` for `dry_run` policies.set(PolicyType::MaxFee, self.tx_policies.tip().or(Some(0))); - policies.set(PolicyType::Maturity, self.tx_policies.maturity()); - - let witness_limit = self - .tx_policies - .witness_limit() - .or_else(|| self.calculate_witnesses_size()); - policies.set(PolicyType::WitnessLimit, witness_limit); - policies.set(PolicyType::Tip, self.tx_policies.tip()); - policies + Ok(policies) } fn is_using_predicates(&self) -> bool { @@ -300,12 +297,14 @@ macro_rules! impl_tx_trait { Ok(num_witnesses as u16) } - fn calculate_witnesses_size(&self) -> Option { + fn calculate_witnesses_size(&self) -> Result { let witnesses_size = calculate_witnesses_size(&self.witnesses); let signature_size = SIGNATURE_WITNESS_SIZE * self.unresolved_witness_indexes.owner_to_idx_offset.len(); - Some(padded_len_usize(witnesses_size + signature_size) as u64) + let padded_len = padded_len_usize(witnesses_size + signature_size) + .ok_or_else(|| error!(Other, "witnesses size overflow"))?; + Ok(padded_len as u64) } async fn set_max_fee_policy( @@ -380,7 +379,7 @@ impl ScriptTransactionBuilder { async fn build(self, provider: impl DryRunner) -> Result { let is_using_predicates = self.is_using_predicates(); let base_offset = if is_using_predicates { - self.base_offset(provider.consensus_parameters()) + self.base_offset(provider.consensus_parameters())? } else { 0 }; @@ -473,7 +472,7 @@ impl ScriptTransactionBuilder { async fn resolve_fuel_tx(self, base_offset: usize, provider: impl DryRunner) -> Result