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

Return PredicateVerificationFailed error to the user #628

Merged
merged 32 commits into from
Nov 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
b8c05e5
Removed subtraction of predicate used gas from the gas limit.
xgreenx Nov 3, 2023
0b6d296
Updated values of teh GTF
xgreenx Nov 3, 2023
4ad331f
Implemented `Policies` structure.
xgreenx Nov 4, 2023
044b3a1
Applied change for VM.
xgreenx Nov 4, 2023
17242eb
Minor nits
xgreenx Nov 6, 2023
9d78719
Fix test in `fuel-core`
xgreenx Nov 7, 2023
482deaf
Merge branch 'master' into feature/transaction-policy
xgreenx Nov 7, 2023
db58054
Fixed review ocmments
xgreenx Nov 7, 2023
a36e555
Update fuel-tx/src/transaction/types/create.rs
xgreenx Nov 7, 2023
9ceebb5
Fixed comments from the PR.
xgreenx Nov 7, 2023
d4814bb
Merge remote-tracking branch 'origin/feature/transaction-policy' into…
xgreenx Nov 7, 2023
dfa9320
Added a test for refund
xgreenx Nov 7, 2023
0b7eaad
Merge branch 'master' into feature/transaction-policy
xgreenx Nov 8, 2023
3cec325
Apply suggestions from code review
xgreenx Nov 8, 2023
5f69fbd
Renamed `GasLimit` to `ScriptGasLimit`
xgreenx Nov 8, 2023
bb41836
Update CHANGELOG.md
xgreenx Nov 8, 2023
ac8047c
Update CHANGELOG.md
xgreenx Nov 8, 2023
9d6c3e1
Return `PredicateVerificationFailed` error to the user
xgreenx Nov 8, 2023
3efa7dd
Renamed `gas_limit` to `script_gas_limit`
xgreenx Nov 8, 2023
9a488a6
Merge remote-tracking branch 'origin/feature/transaction-policy' into…
xgreenx Nov 8, 2023
089fdd9
Renamed `gas_limit` to `script_gas_limit`
xgreenx Nov 8, 2023
69c08ef
Use correct values for policies GTF
xgreenx Nov 8, 2023
6f320d5
Update CHANGELOG.md
xgreenx Nov 8, 2023
3b6ff3d
Merge branch 'feature/transaction-policy' into feature/predicate-verf…
xgreenx Nov 8, 2023
e8d7bcc
Address comments
xgreenx Nov 8, 2023
379869e
Merge branch 'master' into feature/transaction-policy
xgreenx Nov 9, 2023
25e0a5e
Merge branch 'master' into feature/transaction-policy
xgreenx Nov 9, 2023
318cc11
Merge branch 'feature/transaction-policy' into feature/predicate-verf…
xgreenx Nov 9, 2023
ba2506c
Merge branch 'master' into feature/predicate-verfiicaiton-error
xgreenx Nov 9, 2023
c6466df
Fix CI
xgreenx Nov 9, 2023
ade866a
Merge branch 'master' into feature/predicate-verfiicaiton-error
xgreenx Nov 9, 2023
d002cff
Merge branch 'master' into feature/predicate-verfiicaiton-error
xgreenx Nov 9, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
#### Breaking

- [#629](https://github.com/FuelLabs/fuel-vm/pull/629): Charge the user for VM initialization.
- [#628](https://github.com/FuelLabs/fuel-vm/pull/628): Renamed `transaction::CheckError` to `transaction::ValidityError`.
Created a new `checked_transaction::CheckError` that combines `ValidityError`
and `PredicateVerificationFailed` errors into one. It allows the return of the
`PredicateVerificationFailed` to the end user instead of losing the reason why predicate verification failed.
- [#623](https://github.com/FuelLabs/fuel-vm/pull/623):
Added support for transaction policies. The `Script` and `Create`
transactions received a new field, `policies`. Policies allow the addition
Expand Down
6 changes: 3 additions & 3 deletions fuel-tx/src/contract.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::{
CheckError,
StorageSlot,
Transaction,
ValidityError,
};

use derivative::Derivative;
Expand Down Expand Up @@ -172,12 +172,12 @@ impl AsMut<[u8]> for Contract {
}

impl TryFrom<&Transaction> for Contract {
type Error = CheckError;
type Error = ValidityError;

fn try_from(tx: &Transaction) -> Result<Self, Self::Error> {
match tx {
Transaction::Create(create) => TryFrom::try_from(create),
_ => Err(CheckError::TransactionScriptOutputContractCreated { index: 0 }),
_ => Err(ValidityError::TransactionScriptOutputContractCreated { index: 0 }),
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion fuel-tx/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ pub use transaction::{
policies,
Cacheable,
Chargeable,
CheckError,
ConsensusParameters,
ContractParameters,
Create,
Expand All @@ -98,6 +97,7 @@ pub use transaction::{
TxId,
TxParameters,
UtxoId,
ValidityError,
Witness,
};

Expand Down
42 changes: 21 additions & 21 deletions fuel-tx/src/tests/valid_cases/input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ fn input_coin_message_signature() {
fn test<Tx: Buildable>(txs: &mut impl Iterator<Item = (Tx, Vec<SecretKey>)>) {
let rng = &mut StdRng::seed_from_u64(8586);

fn check_inputs<Tx: Buildable>(tx: Tx) -> Result<(), CheckError> {
fn check_inputs<Tx: Buildable>(tx: Tx) -> Result<(), ValidityError> {
let chain_id = ChainId::default();
let txhash = tx.id(&chain_id);
let outputs = tx.outputs();
Expand Down Expand Up @@ -57,7 +57,7 @@ fn input_coin_message_signature() {
rng: &mut R,
mut iter: I,
f: F,
) -> Result<(), CheckError>
) -> Result<(), ValidityError>
where
R: Rng + CryptoRng,
I: Iterator<Item = (Tx, Vec<SecretKey>)>,
Expand Down Expand Up @@ -160,7 +160,7 @@ fn coin_signed() {
.check(block_height, &ConsensusParameters::standard())
.expect_err("Expected failure");

assert_eq!(CheckError::InputWitnessIndexBounds { index: 0 }, err);
assert_eq!(ValidityError::InputWitnessIndexBounds { index: 0 }, err);
}

#[test]
Expand Down Expand Up @@ -244,7 +244,7 @@ fn coin_predicate() {
.err()
.unwrap();

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

let mut predicate = generate_nonempty_padded_bytes(rng);
let owner = (*Contract::root_from_code(&predicate)).into();
Expand All @@ -265,7 +265,7 @@ fn coin_predicate() {
.err()
.unwrap();

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

#[test]
Expand All @@ -291,7 +291,7 @@ fn contract() {
.unwrap();

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

Expand All @@ -308,7 +308,7 @@ fn contract() {
.unwrap();

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

Expand All @@ -325,7 +325,7 @@ fn contract() {
.unwrap();

assert_eq!(
CheckError::InputContractAssociatedOutputContract { index: 1 },
ValidityError::InputContractAssociatedOutputContract { index: 1 },
err
);
}
Expand Down Expand Up @@ -373,7 +373,7 @@ fn message_metadata() {
.check(block_height, &ConsensusParameters::standard())
.expect_err("Expected failure");

assert_eq!(CheckError::InputWitnessIndexBounds { index: 0 }, err,);
assert_eq!(ValidityError::InputWitnessIndexBounds { index: 0 }, err,);

let mut predicate = generate_nonempty_padded_bytes(rng);
let recipient = Input::predicate_owner(&predicate);
Expand All @@ -392,7 +392,7 @@ fn message_metadata() {
.check(1, &txhash, &[], &[], &Default::default(), &mut None)
.expect_err("Expected failure");

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

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

Expand All @@ -414,7 +414,7 @@ fn message_metadata() {
)
.expect_err("expected max data length error");

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

let err = Input::message_data_predicate(
rng.gen(),
Expand All @@ -429,7 +429,7 @@ fn message_metadata() {
.check(1, &txhash, &[], &[], &Default::default(), &mut None)
.expect_err("expected max data length error");

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

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

Expand All @@ -446,7 +446,7 @@ fn message_metadata() {
.check(1, &txhash, &[], &[], &Default::default(), &mut None)
.expect_err("expected max predicate length error");

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

let predicate_data =
vec![0xff; PREDICATE_PARAMS.max_predicate_data_length as usize + 1];
Expand All @@ -464,7 +464,7 @@ fn message_metadata() {
.check(1, &txhash, &[], &[], &Default::default(), &mut None)
.expect_err("expected max predicate data length error");

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

#[test]
Expand Down Expand Up @@ -498,7 +498,7 @@ fn message_message_coin() {
.check(block_height, &ConsensusParameters::standard())
.expect_err("Expected failure");

assert_eq!(CheckError::InputWitnessIndexBounds { index: 0 }, err,);
assert_eq!(ValidityError::InputWitnessIndexBounds { index: 0 }, err,);

let mut predicate = generate_nonempty_padded_bytes(rng);
let recipient = Input::predicate_owner(&predicate);
Expand All @@ -516,7 +516,7 @@ fn message_message_coin() {
.check(1, &txhash, &[], &[], &Default::default(), &mut None)
.expect_err("Expected failure");

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

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

Expand All @@ -532,7 +532,7 @@ fn message_message_coin() {
.check(1, &txhash, &[], &[], &Default::default(), &mut None)
.expect_err("expected max predicate length error");

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

let predicate_data =
vec![0xff; PREDICATE_PARAMS.max_predicate_data_length as usize + 1];
Expand All @@ -549,7 +549,7 @@ fn message_message_coin() {
.check(1, &txhash, &[], &[], &Default::default(), &mut None)
.expect_err("expected max predicate data length error");

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

#[test]
Expand Down Expand Up @@ -584,7 +584,7 @@ fn transaction_with_duplicate_coin_inputs_is_invalid() {
.check_without_signatures(Default::default(), &ConsensusParameters::standard())
.expect_err("Expected checkable failure");

assert_eq!(err, CheckError::DuplicateInputUtxoId { utxo_id });
assert_eq!(err, ValidityError::DuplicateInputUtxoId { utxo_id });
}

#[test]
Expand Down Expand Up @@ -622,7 +622,7 @@ fn transaction_with_duplicate_message_inputs_is_invalid() {
)
.expect_err("Expected checkable failure");

assert_eq!(err, CheckError::DuplicateMessageInputId { message_id });
assert_eq!(err, ValidityError::DuplicateMessageInputId { message_id });
}

#[test]
Expand Down Expand Up @@ -655,7 +655,7 @@ fn transaction_with_duplicate_contract_inputs_is_invalid() {
.check_without_signatures(Default::default(), &ConsensusParameters::standard())
.expect_err("Expected checkable failure");

assert_eq!(err, CheckError::DuplicateInputContractId { contract_id });
assert_eq!(err, ValidityError::DuplicateInputContractId { contract_id });
}

#[test]
Expand Down
4 changes: 2 additions & 2 deletions fuel-tx/src/tests/valid_cases/output.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ fn contract() {
.err()
.unwrap();

assert_eq!(CheckError::OutputContractInputIndex { index: 2 }, err);
assert_eq!(ValidityError::OutputContractInputIndex { index: 2 }, err);

let err = Output::contract(2, rng.gen(), rng.gen())
.check(
Expand All @@ -79,7 +79,7 @@ fn contract() {
.err()
.unwrap();

assert_eq!(CheckError::OutputContractInputIndex { index: 2 }, err);
assert_eq!(ValidityError::OutputContractInputIndex { index: 2 }, err);
}

#[test]
Expand Down
Loading