Skip to content

Commit

Permalink
Add new GTF args for all transactions type and deprecated specific ol…
Browse files Browse the repository at this point in the history
…d ones
  • Loading branch information
AurelienFT committed Dec 10, 2024
1 parent a80f82e commit 7ec1911
Show file tree
Hide file tree
Showing 6 changed files with 244 additions and 39 deletions.
65 changes: 65 additions & 0 deletions fuel-asm/src/args.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![allow(deprecated)]

pub mod wideint;

/// 12-bits immediate value type
Expand Down Expand Up @@ -64,12 +66,15 @@ crate::enum_try_from! {
ScriptDataLength = 0x004,

/// Set `$rA` to `tx.inputsCount`
#[deprecated(since = "0.60.0", note = "Use the generic `TxInputsCount` instead")]
ScriptInputsCount = 0x005,

/// Set `$rA` to `tx.outputsCount`
#[deprecated(since = "0.60.0", note = "Use the generic `TxOutputsCount` instead")]
ScriptOutputsCount = 0x006,

/// Set `$rA` to `tx.witnessesCount`
#[deprecated(since = "0.60.0", note = "Use the generic `TxWitnessesCount` instead")]
ScriptWitnessesCount = 0x007,

/// Set `$rA` to `Memory address of tx.script`
Expand All @@ -79,12 +84,15 @@ crate::enum_try_from! {
ScriptData = 0x00A,

/// Set `$rA` to `Memory address of tx.inputs[$rB]`
#[deprecated(since = "0.60.0", note = "Use the generic `TxInputAtIndex` instead")]
ScriptInputAtIndex = 0x00B,

/// Set `$rA` to `Memory address of t.outputs[$rB]`
#[deprecated(since = "0.60.0", note = "Use the generic `TxOutputAtIndex` instead")]
ScriptOutputAtIndex = 0x00C,

/// Set `$rA` to `Memory address of tx.witnesses[$rB]`
#[deprecated(since = "0.60.0", note = "Use the generic `TxWitnessAtIndex` instead")]
ScriptWitnessAtIndex = 0x00D,

/// Set `$rA` to size of the transaction in memory, in bytes
Expand All @@ -97,12 +105,15 @@ crate::enum_try_from! {
CreateStorageSlotsCount = 0x102,

/// Set `$rA` to `tx.inputsCount`
#[deprecated(since = "0.60.0", note = "Use the generic `TxInputsCount` instead")]
CreateInputsCount = 0x103,

/// Set `$rA` to `tx.outputsCount`
#[deprecated(since = "0.60.0", note = "Use the generic `TxOutputsCount` instead")]
CreateOutputsCount = 0x104,

/// Set `$rA` to `tx.witnessesCount`
#[deprecated(since = "0.60.0", note = "Use the generic `TxWitnessesCount` instead")]
CreateWitnessesCount = 0x105,

/// Set `$rA` to `Memory address of tx.salt`
Expand All @@ -112,12 +123,15 @@ crate::enum_try_from! {
CreateStorageSlotAtIndex = 0x107,

/// Set `$rA` to `Memory address of tx.inputs[$rB]`
#[deprecated(since = "0.60.0", note = "Use the generic `TxInputAtIndex` instead")]
CreateInputAtIndex = 0x108,

/// Set `$rA` to `Memory address of t.outputs[$rB]`
#[deprecated(since = "0.60.0", note = "Use the generic `TxOutputAtIndex` instead")]
CreateOutputAtIndex = 0x109,

/// Set `$rA` to `Memory address of tx.witnesses[$rB]`
#[deprecated(since = "0.60.0", note = "Use the generic `TxWitnessAtIndex` instead")]
CreateWitnessAtIndex = 0x10A,

/// Set `$rA` to `tx.inputs[$rB].type`
Expand Down Expand Up @@ -248,6 +262,57 @@ crate::enum_try_from! {

/// Set `$rA` to `tx.policies[count_ones(0b11111 & tx.policyTypes) - 1].expiration`
PolicyExpiration = 0x505,

/// Set `$rA` to `Memory address of tx.root`
UploadRoot = 0x600,

/// Set `$rA` to `tx.witnessIndex`
UploadWitnessIndex = 0x601,

/// Set `$rA` to `tx.subsectionIndex`
UploadSubsectionIndex = 0x602,

/// Set `$rA` to `tx.subsectionsNumber`
UploadSubsectionsCount = 0x603,

/// Set `$rA` to `tx.proofSetCount`
UploadProofSetCount = 0x604,

/// Set `$rA` to `Memory address of tx.proofSet[$rB]`
UploadProofSetAtIndex = 0x605,

/// Set `$rA` to `Memory address of tx.id`
BlobId = 0x700,

/// Set `$rA` to `tx.witnessIndex`
BlobWitnessIndex = 0x701,

/// Set `$rA` to `tx.purpose.root` if `tx.purpose.type == StateTransition`
UpgradeStateTransitionRoot = 0x800,

/// Set `$rA` to `tx.purpose.witnessIndex` if `tx.purpose.type == ConsensusParameters`
UpgradeConsensusParametersWitnessIndex = 0x801,

/// Set `$rA` to `Memory address of tx.purpose.checksum` if `tx.purpose.type == ConsensusParameters`
UpgradeConsensusParametersChecksum = 0x802,

/// Set `$rA` to `tx.inputsCount`
TxInputsCount = 0x900,

/// Set `$rA` to `tx.outputsCount`
TxOutputsCount = 0x901,

/// Set `$rA` to `tx.witnessesCount`
TxWitnessesCount = 0x902,

/// Set `$rA` to `Memory address of tx.inputs[$rB]`
TxInputAtIndex = 0x903,

/// Set `$rA` to `Memory address of t.outputs[$rB]`
TxOutputAtIndex = 0x904,

/// Set `$rA` to `Memory address of tx.witnesses[$rB]`
TxWitnessAtIndex = 0x905,
},
Immediate12
}
Expand Down
8 changes: 8 additions & 0 deletions fuel-asm/src/panic_reason.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,14 @@ enum_from! {
InvalidEllipticCurvePoint = 0x3b,
/// Given input contract does not exist.
InputContractDoesNotExist = 0x3c,
/// Invalid transaction type.
InvalidTransactionType = 0x3d,
/// Storage slot in Create not found
StorageSlotsNotFound = 0x3e,
/// Proof in Upload not found
ProofInUploadNotFound = 0x3f,
/// Invalid purpose type in Upgrade
InvalidUpgradePurposeType = 0x40,
}
}

Expand Down
3 changes: 3 additions & 0 deletions fuel-tx/src/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1099,6 +1099,9 @@ pub mod field {
}

fn proof_set_offset_static() -> usize;

/// Returns the offset to the `Bytes32` at `idx` index, if any.
fn proof_set_offset_at(&self, idx: usize) -> Option<usize>;
}
}

Expand Down
21 changes: 21 additions & 0 deletions fuel-tx/src/transaction/repr.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
use fuel_asm::{
PanicReason,
Word,
};

use crate::Transaction;

#[derive(
Expand Down Expand Up @@ -33,3 +38,19 @@ impl From<&Transaction> for TransactionRepr {
}
}
}

impl TryFrom<Word> for TransactionRepr {
type Error = PanicReason;

fn try_from(value: Word) -> Result<Self, Self::Error> {
match value {
0x00 => Ok(Self::Script),
0x01 => Ok(Self::Create),
0x02 => Ok(Self::Mint),
0x03 => Ok(Self::Upgrade),
0x04 => Ok(Self::Upload),
0x05 => Ok(Self::Blob),
_ => Err(PanicReason::InvalidTransactionType),
}
}
}
12 changes: 12 additions & 0 deletions fuel-tx/src/transaction/types/upload.rs
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,18 @@ mod field {
+ WORD_SIZE, // Witnesses size
)
}

#[inline(always)]
fn proof_set_offset_at(&self, idx: usize) -> Option<usize> {
if idx < self.body.proof_set.len() {
Some(
Self::proof_set_offset_static()
.checked_add(idx.checked_mul(Bytes32::LEN)?)?,
)
} else {
None
}
}
}

impl ChargeableBody<UploadBody> for Upload {
Expand Down
Loading

0 comments on commit 7ec1911

Please sign in to comment.