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

Versioning of sub parameters #702

Merged
merged 12 commits into from
Mar 25, 2024
460 changes: 230 additions & 230 deletions .npm/packages/fuel-tx/index.test.cjs

Large diffs are not rendered by default.

460 changes: 230 additions & 230 deletions .npm/packages/fuel-tx/index.test.mjs

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).

#### Breaking

- [#702](https://github.com/FuelLabs/fuel-vm/pull/702): Wrapped `FeeParameters`, `PredicateParameters`, `TxParameters`, `ScriptParameters` and `ContractParameters` into an enum to support versioning.
- [#701](https://github.com/FuelLabs/fuel-vm/pull/701): Wrapped `ConsensusParameters` and `GasCosts` into an enum to support versioning. Moved `block_gas_limit` from `fuel_core_chain_config::ChainConfig` to `ConsensusPataremeters`. Reduced default `MAX_SIZE` to be [110kb](https://github.com/FuelLabs/fuel-core/pull/1761) and `MAX_CONTRACT_SIZE` to be [100kb](https://github.com/FuelLabs/fuel-core/pull/1761).
- [#692](https://github.com/FuelLabs/fuel-vm/pull/692): Add GTF getters for tx size and address.
- [#698](https://github.com/FuelLabs/fuel-vm/pull/698): Store input, output and witness limits to u16, while keeping the values limited to 255.
Expand Down
2 changes: 1 addition & 1 deletion fuel-tx/src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,7 @@ impl<Tx: Buildable> TransactionBuilder<Tx> {
let witness_len = u16::try_from(self.witnesses().len())
.expect("The number of witnesses can't exceed `u16::MAX`");

if u32::from(witness_len) > self.params.tx_params().max_witnesses {
if u32::from(witness_len) > self.params.tx_params().max_witnesses() {
panic!("Max witnesses exceeded");
}

Expand Down
10 changes: 5 additions & 5 deletions fuel-tx/src/tests/valid_cases/input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,7 @@ fn message_metadata() {

assert_eq!(ValidityError::InputPredicateOwner { index: 1 }, err);

let data = vec![0xff; PREDICATE_PARAMS.max_message_data_length as usize + 1];
let data = vec![0xff; PREDICATE_PARAMS.max_message_data_length() as usize + 1];

let err = Input::message_data_signed(
rng.gen(),
Expand Down Expand Up @@ -417,7 +417,7 @@ fn message_metadata() {

assert_eq!(ValidityError::InputMessageDataLength { index: 1 }, err,);

let predicate = vec![0xff; PREDICATE_PARAMS.max_predicate_length as usize + 1];
let predicate = vec![0xff; PREDICATE_PARAMS.max_predicate_length() as usize + 1];

let err = Input::message_data_predicate(
rng.gen(),
Expand All @@ -435,7 +435,7 @@ fn message_metadata() {
assert_eq!(ValidityError::InputPredicateLength { index: 1 }, err,);

let predicate_data =
vec![0xff; PREDICATE_PARAMS.max_predicate_data_length as usize + 1];
vec![0xff; PREDICATE_PARAMS.max_predicate_data_length() as usize + 1];

let err = Input::message_data_predicate(
rng.gen(),
Expand Down Expand Up @@ -503,7 +503,7 @@ fn message_message_coin() {

assert_eq!(ValidityError::InputPredicateOwner { index: 1 }, err);

let predicate = vec![0xff; PREDICATE_PARAMS.max_predicate_length as usize + 1];
let predicate = vec![0xff; PREDICATE_PARAMS.max_predicate_length() as usize + 1];

let err = Input::message_coin_predicate(
rng.gen(),
Expand All @@ -520,7 +520,7 @@ fn message_message_coin() {
assert_eq!(ValidityError::InputPredicateLength { index: 1 }, err,);

let predicate_data =
vec![0xff; PREDICATE_PARAMS.max_predicate_data_length as usize + 1];
vec![0xff; PREDICATE_PARAMS.max_predicate_data_length() as usize + 1];

let err = Input::message_coin_predicate(
rng.gen(),
Expand Down
58 changes: 29 additions & 29 deletions fuel-tx/src/tests/valid_cases/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ fn gas_limit() {
.expect("Failed to validate transaction");

let err = Transaction::script(
TX_PARAMS.max_gas_per_tx + 1,
TX_PARAMS.max_gas_per_tx() + 1,
generate_bytes(rng),
generate_bytes(rng),
Policies::new().with_max_fee(0),
Expand Down Expand Up @@ -328,11 +328,11 @@ fn max_iow() {
rng.gen(),
);

while builder.outputs().len() < TX_PARAMS.max_outputs as usize {
while builder.outputs().len() < TX_PARAMS.max_outputs() as usize {
builder.add_output(Output::coin(rng.gen(), rng.gen(), asset_id));
}

while builder.witnesses().len() < TX_PARAMS.max_witnesses as usize {
while builder.witnesses().len() < TX_PARAMS.max_witnesses() as usize {
builder.add_witness(generate_bytes(rng).into());
}

Expand All @@ -348,7 +348,7 @@ fn max_iow() {
builder.maturity(maturity);

let secrets =
cmp::min(TX_PARAMS.max_inputs as u32, TX_PARAMS.max_witnesses - 1) as usize;
cmp::min(TX_PARAMS.max_inputs() as u32, TX_PARAMS.max_witnesses() - 1) as usize;
let secrets: Vec<SecretKey> = (0..secrets - builder.inputs().len())
.map(|_| SecretKey::random(rng))
.collect();
Expand All @@ -358,11 +358,11 @@ fn max_iow() {
builder.add_unsigned_coin_input(*k, rng.gen(), rng.gen(), asset_id, rng.gen());
});

while builder.outputs().len() < TX_PARAMS.max_outputs as usize {
while builder.outputs().len() < TX_PARAMS.max_outputs() as usize {
builder.add_output(Output::coin(rng.gen(), rng.gen(), asset_id));
}

while builder.witnesses().len() < TX_PARAMS.max_witnesses as usize {
while builder.witnesses().len() < TX_PARAMS.max_witnesses() as usize {
builder.add_witness(generate_bytes(rng).into());
}

Expand All @@ -377,7 +377,7 @@ fn max_iow() {

builder.maturity(maturity);

let secrets: Vec<SecretKey> = (0..1 + TX_PARAMS.max_inputs as usize
let secrets: Vec<SecretKey> = (0..1 + TX_PARAMS.max_inputs() as usize
- builder.inputs().len())
.map(|_| SecretKey::random(rng))
.collect();
Expand All @@ -386,11 +386,11 @@ fn max_iow() {
builder.add_unsigned_coin_input(*k, rng.gen(), rng.gen(), rng.gen(), rng.gen());
});

while builder.outputs().len() < TX_PARAMS.max_outputs as usize {
while builder.outputs().len() < TX_PARAMS.max_outputs() as usize {
builder.add_output(Output::coin(rng.gen(), rng.gen(), rng.gen()));
}

while builder.witnesses().len() < TX_PARAMS.max_witnesses as usize {
while builder.witnesses().len() < TX_PARAMS.max_witnesses() as usize {
builder.add_witness(generate_bytes(rng).into());
}

Expand All @@ -407,7 +407,7 @@ fn max_iow() {

builder.maturity(maturity);

let secrets: Vec<SecretKey> = (0..TX_PARAMS.max_inputs as usize
let secrets: Vec<SecretKey> = (0..TX_PARAMS.max_inputs() as usize
- builder.inputs().len())
.map(|_| SecretKey::random(rng))
.collect();
Expand All @@ -416,11 +416,11 @@ fn max_iow() {
builder.add_unsigned_coin_input(*k, rng.gen(), rng.gen(), rng.gen(), rng.gen());
});

while builder.outputs().len() < 1 + TX_PARAMS.max_outputs as usize {
while builder.outputs().len() < 1 + TX_PARAMS.max_outputs() as usize {
builder.add_output(Output::coin(rng.gen(), rng.gen(), rng.gen()));
}

while builder.witnesses().len() < TX_PARAMS.max_witnesses as usize {
while builder.witnesses().len() < TX_PARAMS.max_witnesses() as usize {
builder.add_witness(generate_bytes(rng).into());
}

Expand All @@ -437,7 +437,7 @@ fn max_iow() {

builder.maturity(maturity);

let secrets: Vec<SecretKey> = (0..TX_PARAMS.max_inputs as usize
let secrets: Vec<SecretKey> = (0..TX_PARAMS.max_inputs() as usize
- builder.inputs().len())
.map(|_| SecretKey::random(rng))
.collect();
Expand All @@ -446,11 +446,11 @@ fn max_iow() {
builder.add_unsigned_coin_input(*k, rng.gen(), rng.gen(), rng.gen(), rng.gen());
});

while builder.outputs().len() < TX_PARAMS.max_outputs as usize {
while builder.outputs().len() < TX_PARAMS.max_outputs() as usize {
builder.add_output(Output::coin(rng.gen(), rng.gen(), rng.gen()));
}

while builder.witnesses().len() < 1 + TX_PARAMS.max_witnesses as usize {
while builder.witnesses().len() < 1 + TX_PARAMS.max_witnesses() as usize {
builder.add_witness(generate_bytes(rng).into());
}

Expand Down Expand Up @@ -542,8 +542,8 @@ fn script__check__happy_path() {
let asset_id: AssetId = rng.gen();

TransactionBuilder::script(
vec![0xfa; SCRIPT_PARAMS.max_script_length as usize],
vec![0xfb; SCRIPT_PARAMS.max_script_data_length as usize],
vec![0xfa; SCRIPT_PARAMS.max_script_length() as usize],
vec![0xfb; SCRIPT_PARAMS.max_script_data_length() as usize],
)
.maturity(maturity)
.add_unsigned_coin_input(secret, rng.gen(), rng.gen(), asset_id, rng.gen())
Expand All @@ -564,8 +564,8 @@ fn script__check__cannot_create_contract() {
let asset_id: AssetId = rng.gen();

let err = TransactionBuilder::script(
vec![0xfa; SCRIPT_PARAMS.max_script_length as usize],
vec![0xfb; SCRIPT_PARAMS.max_script_data_length as usize],
vec![0xfa; SCRIPT_PARAMS.max_script_length() as usize],
vec![0xfb; SCRIPT_PARAMS.max_script_data_length() as usize],
)
.maturity(maturity)
.add_unsigned_coin_input(secret, rng.gen(), rng.gen(), asset_id, rng.gen())
Expand All @@ -591,8 +591,8 @@ fn script__check__errors_if_script_too_long() {
let asset_id: AssetId = rng.gen();

let err = TransactionBuilder::script(
vec![0xfa; 1 + SCRIPT_PARAMS.max_script_length as usize],
vec![0xfb; SCRIPT_PARAMS.max_script_data_length as usize],
vec![0xfa; 1 + SCRIPT_PARAMS.max_script_length() as usize],
vec![0xfb; SCRIPT_PARAMS.max_script_data_length() as usize],
)
.maturity(maturity)
.add_unsigned_coin_input(secret, rng.gen(), rng.gen(), asset_id, rng.gen())
Expand All @@ -615,8 +615,8 @@ fn script__check__errors_if_script_data_too_long() {
let asset_id: AssetId = rng.gen();

let err = TransactionBuilder::script(
vec![0xfa; SCRIPT_PARAMS.max_script_length as usize],
vec![0xfb; 1 + SCRIPT_PARAMS.max_script_data_length as usize],
vec![0xfa; SCRIPT_PARAMS.max_script_length() as usize],
vec![0xfb; 1 + SCRIPT_PARAMS.max_script_data_length() as usize],
)
.maturity(maturity)
.add_unsigned_coin_input(secret, rng.gen(), rng.gen(), asset_id, rng.gen())
Expand Down Expand Up @@ -843,7 +843,7 @@ fn create__check__something_else() {
let secret = SecretKey::random(rng);

TransactionBuilder::create(
vec![0xfa; CONTRACT_PARAMS.contract_max_size as usize / 4].into(),
vec![0xfa; CONTRACT_PARAMS.contract_max_size() as usize / 4].into(),
rng.gen(),
vec![],
)
Expand All @@ -865,7 +865,7 @@ fn create__check__errors_if_witness_bytecode_too_long() {
let secret = SecretKey::random(rng);

let err = TransactionBuilder::create(
vec![0xfa; 1 + CONTRACT_PARAMS.contract_max_size as usize].into(),
vec![0xfa; 1 + CONTRACT_PARAMS.contract_max_size() as usize].into(),
rng.gen(),
vec![],
)
Expand Down Expand Up @@ -940,7 +940,7 @@ fn create__check__can_max_out_storage_slots() {

let secret = SecretKey::random(rng);

let storage_slots = (0..CONTRACT_PARAMS.max_storage_slots)
let storage_slots = (0..CONTRACT_PARAMS.max_storage_slots())
.map(|i| {
let mut slot_data = StorageSlot::default().to_bytes();
slot_data[..8].copy_from_slice(&i.to_be_bytes()); // Force ordering
Expand Down Expand Up @@ -972,7 +972,7 @@ fn create__check__cannot_exceed_max_storage_slot() {
let secret = SecretKey::random(rng);

// Test max slots can't be exceeded
let mut storage_slots_max = (0..CONTRACT_PARAMS.max_storage_slots)
let mut storage_slots_max = (0..CONTRACT_PARAMS.max_storage_slots())
.map(|i| {
let mut slot_data = StorageSlot::default().to_bytes();
slot_data[..8].copy_from_slice(&i.to_be_bytes()); // Force ordering
Expand Down Expand Up @@ -1007,7 +1007,7 @@ fn script__check__transaction_at_maximum_size_is_valid() {
let mut params = test_params();
let max_size = 1024usize;
let mut tx_params = *params.tx_params();
tx_params.max_size = max_size as u64;
tx_params.set_max_size(max_size as u64);
params.set_tx_params(tx_params);

let base_size = {
Expand Down Expand Up @@ -1041,7 +1041,7 @@ fn script__check__transaction_exceeding_maximum_size_is_invalid() {
let mut params = test_params();
let max_size = 1024usize;
let mut tx_params = *params.tx_params();
tx_params.max_size = max_size as u64;
tx_params.set_max_size(max_size as u64);
params.set_tx_params(tx_params);

let base_size = {
Expand Down
Loading
Loading