Skip to content

Commit

Permalink
Revert breaking changes
Browse files Browse the repository at this point in the history
  • Loading branch information
bitzoic committed Aug 30, 2024
1 parent 74ab168 commit f5726cd
Show file tree
Hide file tree
Showing 15 changed files with 757 additions and 539 deletions.
44 changes: 0 additions & 44 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,50 +48,6 @@ Description of the upcoming release here.

### Breaking v0.24.0

- [#285](https://github.com/FuelLabs/sway-libs/pull/285) Removes `_with_configurables()` functions from Bytecode Library in favor of using an `Option`.

The following demonstrates the breaking change.

Before:

```sway
// Compute bytecode root
let root_no_configurables: BytecodeRoot = compute_bytecode_root(my_bytecode);
let root_with_configurables: BytecodeRoot = compute_bytecode_root_with_configurables(my_bytecode, my_configurables);
// Compute predicate address
let address_no_configurables: Address = compute_predicate_address(my_bytecode);
let address_with_configurables: Address = compute_predicate_address_with_configurables(my_bytecode, my_configurables);
// Verify contract bytecode
verify_contract_bytecode(my_contract_id, my_bytecode); // No configurables
verify_contract_bytecode_with_configurables(my_contract_id, my_bytecode, my_configurables); // With configurables
// Verify predicate address
verify_predicate_address(my_predicate_address, my_bytecode); // No configurables
verify_predicate_address_with_configurables(my_predicate_address, my_bytecode, my_configurables); // With configurables
```

After:

```sway
// Compute bytecode root
let root_no_configurables: BytecodeRoot = compute_bytecode_root(my_bytecode, None);
let root_with_configurables: BytecodeRoot = compute_bytecode_root(my_bytecode, Some(my_configurables));
// Compute predicate address
let address_no_configurables: Address = compute_predicate_address(my_bytecode, None);
let address_with_configurables: Address = compute_predicate_address(my_bytecode, Some(my_configurables));
// Verify contract bytecode
verify_contract_bytecode(my_contract_id, my_bytecode, None); // No configurables
verify_contract_bytecode(my_contract_id, my_bytecode, Some(my_configurables)); // With configurables
// Verify predicate address
verify_predicate_address(my_predicate_address, my_bytecode, None); // No configurables
verify_predicate_address(my_predicate_address, my_bytecode, Some(my_configurables)); // With configurables
```

- [#286](https://github.com/FuelLabs/sway-libs/pull/286) The support functions for `Metadata` have been removed. They have been moved to sway-standards.

Before:
Expand Down
12 changes: 8 additions & 4 deletions docs/book/src/bytecode/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,15 @@ To import the Bytecode Library to your Sway Smart Contract, add the following to
Once imported, using the Bytecode Library is as simple as calling the desired function. Here is a list of function definitions that you may use.

- `compute_bytecode_root()`
- `compute_bytecode_root_with_configurables()`
- `compute_predicate_address()`
- `compute_predicate_address_with_configurables()`
- `predicate_address_from_root()`
- `swap_configurables()`
- `verify_contract_bytecode()`
- `verify_contract_bytecode_with_configurables()`
- `verify_predicate_address()`
- `verify_predicate_address_with_configurables()`

## Known Issues

Expand All @@ -51,15 +55,15 @@ Given some bytecode, you may swap the configurables of both Contracts and Predic

### Computing the Bytecode Root

To compute a contract's bytecode root you may call the `compute_bytecode_root()` function.
To compute a contract's bytecode root you may call the `compute_bytecode_root()` or `compute_bytecode_root_with_configurables()` functions.

```sway
{{#include ../../../../examples/bytecode/src/main.sw:compute_bytecode_root}}
```

### Verifying a Contract's Bytecode Root

To verify a contract's bytecode root you may call `verify_bytecode_root()` function.
To verify a contract's bytecode root you may call `verify_bytecode_root()` or `verify_contract_bytecode_with_configurables()` functions.

```sway
{{#include ../../../../examples/bytecode/src/main.sw:verify_contract_bytecode}}
Expand All @@ -69,7 +73,7 @@ To verify a contract's bytecode root you may call `verify_bytecode_root()` funct

### Computing the Address from Bytecode

To compute a predicates's address you may call the `compute_predicate_address()` function.
To compute a predicates's address you may call the `compute_predicate_address()` or `compute_predicate_address_with_configurables()` functions.

```sway
{{#include ../../../../examples/bytecode/src/main.sw:compute_predicate_address}}
Expand All @@ -85,7 +89,7 @@ If you have the root of a predicate, you may compute it's corresponding predicat

### Verifying the Address

To verify a predicates's address you may call `verify_predicate_address()` function.
To verify a predicates's address you may call `verify_predicate_address()` or `verify_predicate_address_with_configurables()` functions.

```sway
{{#include ../../../../examples/bytecode/src/main.sw:verify_predicate_address}}
Expand Down
46 changes: 29 additions & 17 deletions examples/bytecode/src/main.sw
Original file line number Diff line number Diff line change
Expand Up @@ -23,41 +23,48 @@ fn make_mutable(not_mutable_bytecode: Vec<u8>) {
// ANCHOR_END: known_issue

// ANCHOR: swap_configurables
fn swap(my_bytecode: Vec<u8>, my_configurables: Vec<(u64, Vec<u8>)>) {
fn swap(my_bytecode: Vec<u8>, my_configurables: ContractConfigurables) {
let mut my_bytecode = my_bytecode;
let resulting_bytecode: Vec<u8> = swap_configurables(my_bytecode, my_configurables);
}
// ANCHOR_END: swap_configurables

// ANCHOR: compute_bytecode_root
fn compute_bytecode(
my_bytecode: Vec<u8>,
my_configurables: Option<ContractConfigurables>,
) {
fn compute_bytecode(my_bytecode: Vec<u8>) {
let root: BytecodeRoot = compute_bytecode_root(my_bytecode);
}

fn compute_bytecode_configurables(my_bytecode: Vec<u8>, my_configurables: ContractConfigurables) {
let mut my_bytecode = my_bytecode;
let root: BytecodeRoot = compute_bytecode_root(my_bytecode, my_configurables);
let root: BytecodeRoot = compute_bytecode_root_with_configurables(my_bytecode, my_configurables);
}
// ANCHOR_END: compute_bytecode_root

// ANCHOR: verify_contract_bytecode
fn verify_contract(
fn verify_contract(my_contract: ContractId, my_bytecode: Vec<u8>) {
verify_contract_bytecode(my_contract, my_bytecode);
// By reaching this line the contract has been verified to match the bytecode provided.
}

fn verify_contract_configurables(
my_contract: ContractId,
my_bytecode: Vec<u8>,
my_configurables: Option<ContractConfigurables>,
my_configurables: ContractConfigurables,
) {
let mut my_bytecode = my_bytecode;
verify_contract_bytecode(my_contract, my_bytecode, my_configurables);
verify_contract_bytecode_with_configurables(my_contract, my_bytecode, my_configurables);
// By reaching this line the contract has been verified to match the bytecode provided.
}
// ANCHOR_END: verify_contract_bytecode

// ANCHOR: compute_predicate_address
fn compute_predicate(
my_bytecode: Vec<u8>,
my_configurables: Option<ContractConfigurables>,
) {
fn compute_predicate(my_bytecode: Vec<u8>) {
let address: Address = compute_predicate_address(my_bytecode);
}

fn compute_predicate_configurables(my_bytecode: Vec<u8>, my_configurables: ContractConfigurables) {
let mut my_bytecode = my_bytecode;
let address: Address = compute_predicate_address(my_bytecode, my_configurables);
let address: Address = compute_predicate_address_with_configurables(my_bytecode, my_configurables);
}
// ANCHOR_END: compute_predicate_address

Expand All @@ -68,13 +75,18 @@ fn predicate_address(my_root: BytecodeRoot) {
// ANCHOR_END: predicate_address_from_root

// ANCHOR: verify_predicate_address
fn verify_predicate(
fn verify_predicate(my_predicate: Address, my_bytecode: Vec<u8>) {
verify_predicate_address(my_predicate, my_bytecode);
// By reaching this line the predicate bytecode matches the address provided.
}

fn verify_predicate_configurables(
my_predicate: Address,
my_bytecode: Vec<u8>,
my_configurables: Option<ContractConfigurables>,
my_configurables: ContractConfigurables,
) {
let mut my_bytecode = my_bytecode;
verify_predicate_address(my_predicate, my_bytecode, my_configurables);
verify_predicate_address_with_configurables(my_predicate, my_bytecode, my_configurables);
// By reaching this line the predicate bytecode matches the address provided.
}
// ANCHOR_END: verify_predicate_address
Loading

0 comments on commit f5726cd

Please sign in to comment.