Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add owner policy #872

Draft
wants to merge 13 commits into
base: master
Choose a base branch
from
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/).

## [Unreleased]

### Added
- [871](https://github.com/FuelLabs/fuel-vm/pull/871): Add `expiration` policy that prevent a transaction to be inserted after a given block height.
- [872](https://github.com/FuelLabs/fuel-vm/pull/872): Add `owner` policy to specify a primary owner of the transaction. We use the index of an input to identify the owner.

### Fixed
- [860](https://github.com/FuelLabs/fuel-vm/pull/860): Fixed missing fuzzing coverage report in CI.

Expand Down
8 changes: 8 additions & 0 deletions fuel-asm/src/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,12 @@ crate::enum_try_from! {

/// Set `$rA` to `tx.policies[count_ones(0b1111 & tx.policyTypes) - 1].maxFee`
PolicyMaxFee = 0x504,

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

/// Set `$rA` to `tx.policies[count_ones(0b111111 & tx.policyTypes) - 1].owner`
AurelienFT marked this conversation as resolved.
Show resolved Hide resolved
PolicyOwner = 0x506,
},
Immediate12
}
Expand Down Expand Up @@ -340,7 +346,9 @@ fn encode_gtf_args() {
GTFArgs::PolicyTip,
GTFArgs::PolicyWitnessLimit,
GTFArgs::PolicyMaturity,
GTFArgs::PolicyExpiration,
GTFArgs::PolicyMaxFee,
GTFArgs::PolicyOwner,
];

args.into_iter().for_each(|a| {
Expand Down
14 changes: 14 additions & 0 deletions fuel-tx/src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ use crate::{
field::{
self,
BytecodeWitnessIndex,
Expiration,
Maturity,
Owner,
Tip,
Witnesses,
},
Expand Down Expand Up @@ -376,6 +378,12 @@ impl<Tx: Buildable> TransactionBuilder<Tx> {
self
}

pub fn expiration(&mut self, expiration: BlockHeight) -> &mut Self {
self.tx.set_expiration(expiration);

self
}

pub fn witness_limit(&mut self, witness_limit: Word) -> &mut Self {
self.tx.set_witness_limit(witness_limit);

Expand All @@ -388,6 +396,12 @@ impl<Tx: Buildable> TransactionBuilder<Tx> {
self
}

pub fn owner(&mut self, owner: Word) -> &mut Self {
self.tx.set_owner(owner);

self
}

pub fn add_unsigned_coin_input(
&mut self,
secret: SecretKey,
Expand Down
64 changes: 48 additions & 16 deletions fuel-tx/src/tests/bytes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -383,8 +383,10 @@ fn transaction_serde_serialization_deserialization() {
Policies::new()
.with_tip(Word::MAX >> 1)
.with_maturity((u32::MAX >> 3).into())
.with_expiration((u32::MAX >> 2).into())
.with_witness_limit(Word::MAX >> 4)
.with_max_fee(Word::MAX >> 5),
.with_max_fee(Word::MAX >> 5)
.with_owner(Word::MAX >> 6),
vec![i.clone()],
vec![o],
vec![w.clone()],
Expand All @@ -397,8 +399,10 @@ fn transaction_serde_serialization_deserialization() {
Policies::new()
.with_tip(Word::MAX >> 1)
.with_maturity((u32::MAX >> 3).into())
.with_expiration((u32::MAX >> 2).into())
.with_witness_limit(Word::MAX >> 4)
.with_max_fee(Word::MAX >> 5),
.with_max_fee(Word::MAX >> 5)
.with_owner(Word::MAX >> 6),
vec![],
vec![o],
vec![w.clone()],
Expand All @@ -411,8 +415,10 @@ fn transaction_serde_serialization_deserialization() {
Policies::new()
.with_tip(Word::MAX >> 1)
.with_maturity((u32::MAX >> 3).into())
.with_expiration((u32::MAX >> 2).into())
.with_witness_limit(Word::MAX >> 4)
.with_max_fee(Word::MAX >> 5),
.with_max_fee(Word::MAX >> 5)
.with_owner(Word::MAX >> 6),
vec![],
vec![],
vec![w.clone()],
Expand All @@ -425,8 +431,10 @@ fn transaction_serde_serialization_deserialization() {
Policies::new()
.with_tip(Word::MAX >> 1)
.with_maturity((u32::MAX >> 3).into())
.with_expiration((u32::MAX >> 2).into())
.with_witness_limit(Word::MAX >> 4)
.with_max_fee(Word::MAX >> 5),
.with_max_fee(Word::MAX >> 5)
.with_owner(Word::MAX >> 6),
vec![],
vec![],
vec![],
Expand All @@ -438,8 +446,10 @@ fn transaction_serde_serialization_deserialization() {
Policies::new()
.with_tip(Word::MAX >> 1)
.with_maturity((u32::MAX >> 3).into())
.with_expiration((u32::MAX >> 2).into())
.with_witness_limit(Word::MAX >> 4)
.with_max_fee(Word::MAX >> 5),
.with_max_fee(Word::MAX >> 5)
.with_owner(Word::MAX >> 6),
vec![i.clone()],
vec![o],
vec![w.clone()],
Expand All @@ -451,8 +461,10 @@ fn transaction_serde_serialization_deserialization() {
Policies::new()
.with_tip(Word::MAX >> 1)
.with_maturity((u32::MAX >> 3).into())
.with_expiration((u32::MAX >> 2).into())
.with_witness_limit(Word::MAX >> 4)
.with_max_fee(Word::MAX >> 5),
.with_max_fee(Word::MAX >> 5)
.with_owner(Word::MAX >> 6),
vec![],
vec![o],
vec![w.clone()],
Expand All @@ -464,8 +476,10 @@ fn transaction_serde_serialization_deserialization() {
Policies::new()
.with_tip(Word::MAX >> 1)
.with_maturity((u32::MAX >> 3).into())
.with_expiration((u32::MAX >> 2).into())
.with_witness_limit(Word::MAX >> 4)
.with_max_fee(Word::MAX >> 5),
.with_max_fee(Word::MAX >> 5)
.with_owner(Word::MAX >> 6),
vec![],
vec![],
vec![w.clone()],
Expand All @@ -477,8 +491,10 @@ fn transaction_serde_serialization_deserialization() {
Policies::new()
.with_tip(Word::MAX >> 1)
.with_maturity((u32::MAX >> 3).into())
.with_expiration((u32::MAX >> 2).into())
.with_witness_limit(Word::MAX >> 4)
.with_max_fee(Word::MAX >> 5),
.with_max_fee(Word::MAX >> 5)
.with_owner(Word::MAX >> 6),
vec![],
vec![],
vec![],
Expand All @@ -496,8 +512,10 @@ fn transaction_serde_serialization_deserialization() {
Policies::new()
.with_tip(Word::MAX >> 1)
.with_maturity((u32::MAX >> 3).into())
.with_expiration((u32::MAX >> 2).into())
.with_witness_limit(Word::MAX >> 4)
.with_max_fee(Word::MAX >> 5),
.with_max_fee(Word::MAX >> 5)
.with_owner(Word::MAX >> 6),
vec![i.clone()],
vec![o],
vec![w.clone()],
Expand All @@ -513,8 +531,10 @@ fn transaction_serde_serialization_deserialization() {
Policies::new()
.with_tip(Word::MAX >> 1)
.with_maturity((u32::MAX >> 3).into())
.with_expiration((u32::MAX >> 2).into())
.with_witness_limit(Word::MAX >> 4)
.with_max_fee(Word::MAX >> 5),
.with_max_fee(Word::MAX >> 5)
.with_owner(Word::MAX >> 6),
vec![],
vec![o],
vec![w.clone()],
Expand All @@ -530,8 +550,10 @@ fn transaction_serde_serialization_deserialization() {
Policies::new()
.with_tip(Word::MAX >> 1)
.with_maturity((u32::MAX >> 3).into())
.with_expiration((u32::MAX >> 2).into())
.with_witness_limit(Word::MAX >> 4)
.with_max_fee(Word::MAX >> 5),
.with_max_fee(Word::MAX >> 5)
.with_owner(Word::MAX >> 6),
vec![],
vec![],
vec![w.clone()],
Expand All @@ -547,8 +569,10 @@ fn transaction_serde_serialization_deserialization() {
Policies::new()
.with_tip(Word::MAX >> 1)
.with_maturity((u32::MAX >> 3).into())
.with_expiration((u32::MAX >> 2).into())
.with_witness_limit(Word::MAX >> 4)
.with_max_fee(Word::MAX >> 5),
.with_max_fee(Word::MAX >> 5)
.with_owner(Word::MAX >> 6),
vec![],
vec![],
vec![],
Expand All @@ -566,8 +590,10 @@ fn transaction_serde_serialization_deserialization() {
Policies::new()
.with_tip(Word::MAX >> 1)
.with_maturity((u32::MAX >> 3).into())
.with_expiration((u32::MAX >> 2).into())
.with_witness_limit(Word::MAX >> 4)
.with_max_fee(Word::MAX >> 5),
.with_max_fee(Word::MAX >> 5)
.with_owner(Word::MAX >> 6),
vec![i.clone()],
vec![o],
vec![w.clone()],
Expand All @@ -583,8 +609,10 @@ fn transaction_serde_serialization_deserialization() {
Policies::new()
.with_tip(Word::MAX >> 1)
.with_maturity((u32::MAX >> 3).into())
.with_expiration((u32::MAX >> 2).into())
.with_witness_limit(Word::MAX >> 4)
.with_max_fee(Word::MAX >> 5),
.with_max_fee(Word::MAX >> 5)
.with_owner(Word::MAX >> 6),
vec![],
vec![o],
vec![w.clone()],
Expand All @@ -600,8 +628,10 @@ fn transaction_serde_serialization_deserialization() {
Policies::new()
.with_tip(Word::MAX >> 1)
.with_maturity((u32::MAX >> 3).into())
.with_expiration((u32::MAX >> 2).into())
.with_witness_limit(Word::MAX >> 4)
.with_max_fee(Word::MAX >> 5),
.with_max_fee(Word::MAX >> 5)
.with_owner(Word::MAX >> 6),
vec![],
vec![],
vec![w.clone()],
Expand All @@ -617,8 +647,10 @@ fn transaction_serde_serialization_deserialization() {
Policies::new()
.with_tip(Word::MAX >> 1)
.with_maturity((u32::MAX >> 3).into())
.with_expiration((u32::MAX >> 2).into())
.with_witness_limit(Word::MAX >> 4)
.with_max_fee(Word::MAX >> 5),
.with_max_fee(Word::MAX >> 5)
.with_owner(Word::MAX >> 6),
vec![],
vec![],
vec![],
Expand Down
Loading
Loading