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

Support transaction policies #623

Merged
merged 24 commits into from
Nov 9, 2023
Merged
Show file tree
Hide file tree
Changes from 17 commits
Commits
Show all changes
24 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
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
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
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
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ concurrency:
env:
CARGO_TERM_COLOR: always
RUST_VERSION: 1.73.0
NIGHTLY_RUST_VERSION: nightly-2023-08-28
NIGHTLY_RUST_VERSION: nightly-2023-10-29

jobs:
check-changelog:
Expand Down
34 changes: 34 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,40 @@ and this project adheres to [Semantic Versioning](http://semver.org/).

## [Unreleased]

### Changed

#### Breaking

- [#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
of some limits to the transaction to protect the user or specify some details regarding execution.
This change makes the `GasPrice` and `Maturity` fields optional, allowing to save space in the future.
Also, this will enable us to support multidimensional prices later.
`GasLimit` was renamed to `ScriptGasLimit`.

Along with this change, we introduced two new policies:
- `WitnessLimit` - allows the limitation of the maximum size of witnesses in bytes for the contract. Because of the changes in the gas calculation model(the blockchain also charges the user for the witness data), the user should protect himself from the block producer or third parties blowing up witness data and draining the user's funds.
- `MaxFee` - allows the upper bound for the maximum fee that users agree to pay for the transaction.

This change brings the following modification to the gas model:
- The `ScriptGasLimit` only limits script execution. Previously, the `ScriptGasLimit` also limited the predicate execution time, instead predicate gas is now directly included into `min_fee`. So, it is not possible to use the `ScriptGasLimit` for transaction cost limitations. A new `MaxFee` policy is a way to do that. The `GasLimit` field was removed from the `Create` transaction because it only relates to the script execution (which the `Create` transaction doesn't have).
- The blockchain charges the user for the size of witness data (before it was free). There is no separate price for the storage, so it uses gas to charge the user. This change affects `min_gas` and `min_fee` calculation.
- A new policy called `WitnessLimit` also impacts the `max_gas` and `max_fee` calculation in addition to `ScriptGasLimit`(in the case of `Create` transaction only `WitnessLimit` affects the `max_gas` and `max_fee`).
- The minimal gas also charges the user for transaction ID calculation.

The change has the following modification to the transaction layout:
- The `Create` transaction doesn't have the `ScriptGasLimit` field anymore. Because the `Create` transaction doesn't have any script to execute
- The `Create` and `Script` transactions don't have explicit `maturity` and `gas_price` fields. Instead, these fields can be set via a new `policies` field.
- The `Create` and `Script` transactions have a new `policies` field with a unique canonical serialization and deserialization for optimal space consumption.

Other breaking changes caused by the change:
- Each transaction requires setting the `GasPrice` policy.
- Previously, `ScriptGasLimit` should be less than the `MAX_GAS_PER_TX` constant. After removing this field from the `Create` transaction, it is impossible to require it. Instead, it requires that `max_gas <= MAX_GAS_PER_TX` for any transaction. Consequently, any `Script` transaction that uses `MAX_GAS_PER_TX` as a `ScriptGasLimit` will always fail because of a new rule. Setting the estimated gas usage instead solves the problem.
- If the `max_fee > policies.max_fee`, then transaction will be rejected.
- If the `witnessses_size > policies.witness_limit`, then transaction will be rejected.
- GTF opcode changed its hardcoded constants for fields. It should be updated according to the values from the specification on the Sway side.

## [Version 0.40.0]

### Added
Expand Down
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,6 @@ fuel-storage = { version = "0.40.0", path = "fuel-storage", default-features = f
fuel-tx = { version = "0.40.0", path = "fuel-tx", default-features = false }
fuel-types = { version = "0.40.0", path = "fuel-types", default-features = false }
fuel-vm = { version = "0.40.0", path = "fuel-vm", default-features = false }
bitflags = "2"
bincode = { version = "1.3", default-features = false }
criterion = "0.5.0"
2 changes: 1 addition & 1 deletion fuel-asm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ description = "Atomic types of the FuelVM."

[dependencies]
arbitrary = { version = "1.1", features = ["derive"], optional = true }
bitflags = "1.3"
bitflags = { workspace = true }
fuel-types = { workspace = true }
serde = { version = "1.0", default-features = false, features = ["derive"], optional = true }
strum = { version = "0.24", default-features = false, features = ["derive"] }
Expand Down
Loading
Loading