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

Increase Safety when introspecting transactions #6418

Merged
merged 12 commits into from
Aug 16, 2024
Merged

Conversation

bitzoic
Copy link
Member

@bitzoic bitzoic commented Aug 15, 2024

Description

When using thetx.sw library of the std-lib, if a bad input was given to the functions or a transaction did not exist, the functions would revert. Instead, they now return options so error may be caught.

Fixes

  • WITNESS_LIMIT_POLICY and MATURITY_POLICY did not follow the fuel VM specs
  • tx_maturity() did not follow the fuel VM specs
  • tx_witness_pointer() now returns a pointer and is private
  • tx_script_start_pointer() and tx_script_data_start_pointer() are now private

Breaking

There are a number of breaking changes in function return types.

  • tx_maturity() now returns an Option<u32>.
    Before:
let my_tx_maturity: u64 = tx_maturity().unwrap()

After:

let my_tx_maturity: u32 = tx_maturity().unwrap()
  • tx_script_length() now returns an Option<u64>
    Before:
let my_tx_script_length: u64 = tx_script_length();

After:

let my_tx_script_length: u64 = tx_script_length().unwrap();
  • tx_script_data_length() now returns an Option<u64>
    Before:
let my_tx_script_data_length: u64 = tx_script_data_length();

After:

let my_tx_script_data_length: u64 = tx_script_data_length().unwrap();
  • tx_witness_pointer() now returns an Option<raw_ptr> and is private
    Before:
let my_tx_witness_pointer: u64 = tx_witness_pointer(0);

After:

let my_tx_witness_pointer: raw_ptr = tx_witness_pointer(0).unwrap();
  • tx_witness_data_length() now returns an Option<u64>
    Before:
let my_tx_witness_data_length: u64 = tx_witness_data_length(0);

After:

let my_tx_witness_data_length: u64 = tx_witness_data_length(0).unwrap();
  • tx_witness_data() now returns an Option<T>
    Before:
let my_tx_witness_data: u64 = tx_witness_data::<u64>();

After:

let my_tx_witness_data: u64 = tx_witness_data::<u64>().unwrap();
  • tx_script_start_pointer() now returns an Option<raw_ptr> and is private
let my_tx_script_start_pointer: raw_ptr = tx_script_start_pointer();

After:

let my_tx_script_start_pointer: raw_ptr = tx_script_start_pointer().unwrap();
  • tx_script_data_start_pointer() now returns an Option<raw_ptr> and is private
    Before:
let my_tx_script_data_start_pointer: raw_ptr = tx_script_data_start_pointer();

After:

let my_tx_script_data_start_pointer: raw_ptr = tx_script_data_start_pointer().unwrap();
  • tx_script_data() now returns an Option<T>
    Before:
let my_tx_script_data: u64 = tx_script_data::<u64>();

After:

let my_tx_script_data: u64 = tx_script_data::<u64>().unwrap();
  • tx_script_bytecode() now returns an Option<T>
    Before:
let my_tx_script_bytecode: u64 = tx_script_bytecode::<u64>();

After:

let my_tx_script_bytecode: u64 = tx_script_bytecode::<u64>().unwrap();
  • tx_script_bytecode_hash() now returns an Option<b256>
    Before:
let my_tx_script_bytecode_hash: b256 = tx_script_bytecode_hash();

After:

let my_tx_script_bytecode_hash: b256 = tx_script_bytecode_hash().unwrap()

Checklist

  • I have linked to any relevant issues.
  • I have commented my code, particularly in hard-to-understand areas.
  • I have updated the documentation where relevant (API docs, the reference, and the Sway book).
  • I have added tests that prove my fix is effective or that my feature works.
  • I have added (or requested a maintainer to add) the necessary Breaking* or New Feature labels where relevant.
  • I have done my best to ensure that my PR adheres to the Fuel Labs Code Review Standards.
  • I have requested a review from the relevant team or maintainers.

@bitzoic bitzoic added lib: std Standard library breaking May cause existing user code to break. Requires a minor or major release. labels Aug 15, 2024
@bitzoic bitzoic self-assigned this Aug 15, 2024
@bitzoic bitzoic marked this pull request as ready for review August 15, 2024 12:00
@bitzoic bitzoic requested review from a team as code owners August 15, 2024 12:00
K1-R1
K1-R1 previously approved these changes Aug 15, 2024
@K1-R1 K1-R1 requested a review from a team August 15, 2024 21:11
Voxelot
Voxelot previously approved these changes Aug 15, 2024
@JoshuaBatty JoshuaBatty enabled auto-merge (squash) August 16, 2024 01:25
@JoshuaBatty JoshuaBatty disabled auto-merge August 16, 2024 01:30
@bitzoic bitzoic dismissed stale reviews from K1-R1 and Voxelot via 8f8f4b4 August 16, 2024 08:00
@bitzoic bitzoic requested review from K1-R1 and Voxelot August 16, 2024 08:02
alfiedotwtf
alfiedotwtf previously approved these changes Aug 16, 2024
@K1-R1 K1-R1 requested a review from a team August 16, 2024 09:11
@bitzoic bitzoic enabled auto-merge (squash) August 16, 2024 09:36
@bitzoic bitzoic merged commit 40bd0af into master Aug 16, 2024
35 of 36 checks passed
@bitzoic bitzoic deleted the bitzoic-tx-saftey branch August 16, 2024 20:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking May cause existing user code to break. Requires a minor or major release. lib: std Standard library
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants