## Description
closes#6599.
atty [is no longer
maintained](5bfdbe9e48),
and equivalent functionality is available in the std-lib as of rust
1.79. This PR switches to that functionality and removes `atty`
dependency.
The preamble now contains 8 bytes of offset to the configurables
section. If there is no configurable const in the data-section, then the
value of this integer will be equal to the size of the binary itself.
This also means that we now sort the data-section to have all the
non-configurables first, and then the configurables.
The preamble final asm looks like this (the offset to configurables is
0'd out here in the example):
```
;; ASM: Final program
;; Program kind: Script
.program:
move $$tmp $pc
jmpf $zero i10
DATA_SECTION_OFFSET[0..32]
DATA_SECTION_OFFSET[32..64]
CONFIGURABLES_OFFSET[0..32]
CONFIGURABLES_OFFSET[32..64]
lw $$ds $$tmp i1
add $$ds $$ds $$tmp
```
The preamble bytecode looks like this:
```
0x00000000 MOVE R60 $pc ;; [26, 240, 48, 0]
0x00000004 JMPF $zero 0xa ;; [116, 0, 0, 10]
0x00000008 ;; [0, 0, 0, 0, 0, 0, 2, 40]
0x00000010 ;; [0, 0, 0, 0, 0, 0, 0, 0]
0x00000030 LW R63 R60 0x1 ;; [93, 255, 192, 1]
0x00000034 ADD R63 R63 R60 ;; [16, 255, 255, 0]
...
```
---------
Co-authored-by: Sophie Dankel <47993817+sdankel@users.noreply.github.com>
Co-authored-by: IGI-111 <igi-111@protonmail.com>
## Description
This PR starts the implementation of
https://github.com/FuelLabs/sway-rfcs/blob/master/rfcs/0013-changes-lifecycle.md.
## CLI flags
Now, all `CLI`s, including our tests, support two new arguments
```
...
--experimental <EXPERIMENTAL>
Comma separated list of all experimental features that will be enabled [possible values: new_encoding, storage_domains]
--no-experimental <NO_EXPERIMENTAL>
Comma separated list of all experimental features that will be disabled [possible values: new_encoding, storage_domains]
...
```
Experimental features can also be enabled inside `Forc.toml` for
workspaces and individual projects.
```
experimental = { encoding-v1 = true }
```
And can be enabled using environment variables:
```
FORC_NO_EXPERIMENTAL=feature_a,feature_b FORC_EXPERIMENTAL=feature_c forc build ...
```
These configurations are applied in a very specific order to allow them
to be overwritten. The order from the weakest to the strongest is:
1 - Workspace `TOML`
2 - Project `TOML`
3 - CLI
4 - Environment variables.
The rationale is:
1 - We want an easy way to enable and/or disable a feature for the whole
workspace;
2 - But we want to allow projects to overwrite these features, when
needed.
These two are the suggested approach to configure experimental features,
but we also want to allow someone to easily turn on or off features to
test something in particular. For that one can use the CLI flags; and in
the specific case one does not have access to the CLI, for example, when
one of the `SDK` is compiling the code, one can still completely
overwrite the `TOML` files using environment variables.
We are also applying the "no experimental" first. This is to allow the
use case of exactly controlling which features will be enabled and
disabled. In this case one can use the "meta-feature" `all` to disable
everything and enable only the desired features. For example:
```
FORC_NO_EXPERIMENTAL=all FORC_EXPERIMENTAL=new_encoding your_command....
```
## Test for "-h"
This PR also introduces snapshot tests for "-h" for all forc commands at
https://github.com/FuelLabs/sway/pull/6586/files#diff-20a5e677d2ae9266a2247739b6a473d2ad0c627955187d668822e7d194f8e940
## Multiple test.toml
This PR also enables the use of multiple `test.toml`. Now each
`test.toml` will be a different test, allowing the same code to be
compiled and asserted differently.
For example, `main_args_empty` has two files: the normal `test.toml` and
a new `test.encoding_v1.toml`. One has `new_encoding` enabled and the
other disabled.
When a `test.toml` file has the `experimental` field, we do not use
fields with `_new_encoding` suffix anymore, making these files simpler:
test.toml:
```toml
category = "run"
# (1336, 1)
script_data = "0000000000000538 0000000000000001"
expected_result = { action = "return", value = 1337 }
validate_abi = true
experimental = { encoding_v1 = false }
```
test.encoding_v1.toml
```
script_data = "0000000000000538 0000000000000001"
expected_result = { action = "return_data", value = "0000000000000539" }
experimental = { new_encoding = true }
```
Test tomls with a suffix use `test.toml` as a base. So we do not need to
repeat every field in them.
Now when we run a test, we will see two tests instead of just one:
```
...
Testing should_pass/language/main_args/main_args_empty (test.encoding_v1.toml) ... ok
Testing should_pass/language/main_args/main_args_empty (test.toml) ... ok
...
```
## Conditional compilation
It is also possible to use conditional compilation using these
experimental features. Examples can be found inside `sway-lib-std`.
```sway
#[cfg(experimental_new_encoding = true)]
pub fn assert_eq<T>(v1: T, v2: T) {
...
}
```
## 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).
- [ ] If my change requires substantial documentation changes, I have
[requested support from the DevRel
team](https://github.com/FuelLabs/devrel-requests/issues/new/choose)
- [ ] 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](https://github.com/FuelLabs/rfcs/blob/master/text/code-standards/external-contributors.md).
- [ ] I have requested a review from the relevant team or maintainers.
---------
Co-authored-by: IGI-111 <igi-111@protonmail.com>
## Description
This PR addresses https://github.com/FuelLabs/sway/issues/6597.
A `cmp` trait has been added that exposes:
- `min(self, Self) -> Self`
- `max(self, Self) -> Self`
## Checklist
- [x] I have linked to any relevant issues.
- [x] 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).
- [ ] If my change requires substantial documentation changes, I have
[requested support from the DevRel
team](https://github.com/FuelLabs/devrel-requests/issues/new/choose)
- [x] 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.
- [x] I have done my best to ensure that my PR adheres to [the Fuel Labs
Code Review
Standards](https://github.com/FuelLabs/rfcs/blob/master/text/code-standards/external-contributors.md).
- [x] I have requested a review from the relevant team or maintainers.
---------
Co-authored-by: K1-R1 <77465250+K1-R1@users.noreply.github.com>
## Description
This PR improves `fn_dedup` to also deduplicate config decode functions.
Given how early this optimization was running, some optimizations were
being lost, because some functions only get identical at the final IR. I
believe we chose to run this early to decrease the pressure in other
passes, but to allow this pass to really coalesce decodes I think makes
sense to run it again at the end.
I am also deleting from the IR functions that were being replaced. This
allowed the new test to decrease around 100 bytes. Our old configurable
test went from 7600 to 7250 bytes.

## Checklist
- [ ] I have linked to any relevant issues.
- [x] 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).
- [ ] If my change requires substantial documentation changes, I have
[requested support from the DevRel
team](https://github.com/FuelLabs/devrel-requests/issues/new/choose)
- [x] 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.
- [x] I have done my best to ensure that my PR adheres to [the Fuel Labs
Code Review
Standards](https://github.com/FuelLabs/rfcs/blob/master/text/code-standards/external-contributors.md).
- [ ] I have requested a review from the relevant team or maintainers.
---------
Co-authored-by: Joshua Batty <joshpbatty@gmail.com>
Co-authored-by: IGI-111 <igi-111@protonmail.com>
Co-authored-by: Kaya Gökalp <kaya.gokalp@fuel.sh>
## Description
## 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).
- [ ] If my change requires substantial documentation changes, I have
[requested support from the DevRel
team](https://github.com/FuelLabs/devrel-requests/issues/new/choose)
- [ ] 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](https://github.com/FuelLabs/rfcs/blob/master/text/code-standards/external-contributors.md).
- [ ] I have requested a review from the relevant team or maintainers.
---------
Co-authored-by: Alfie John <alfie@alfie.wtf>
Co-authored-by: Joshua Batty <joshpbatty@gmail.com>
## Description
Pins forc-deploy chunk sizes to 100kb to fix errors while deploying
chunked contracts. To unblock an ecosystem project, the PR is marked
critical.
## Description
Thanks a lot to @hal3e for helping debug this.
With this PR, there will be an additional abi in the `out` folder for
predicates and scripts that are deployed as loaders following the
`{package_name}-loader-abi.json` naming convention.
This PR adds `loader-abi.json` file generation capability to forc. To do
so forc needs to have the old (original) and new (loader) data offsets
of the script/predicate. After getting it the difference should be
applied to all configurable slots to find out the new locations of the
configurable slots inside the loader binary.
Basically enables backwards compatibility with the older sdk releases.
Since forc can now generate a loader abi with correct configurable
offsets, it can be used to load the script as it is, (without the newer
loader stuff) and everything will be still working.
## Description
This PR adds support for deploying executables, namely predicates and
scripts. Before this PR executing `forc-deploy` on a script or predicate
was an hard error. With this PR we are enabling the deployment of them
via converting them to a loader which loads the original bytecode
deployed as a blob.
The loader binaries are serialized to disk under `out` folder for both
predicates and scripts. For predicates we also save the root of the
loader additionally. Every output related to generated `loader` is
suffixed with `-loader` so that it can be distinguished easily.
---------
Co-authored-by: Joshua Batty <joshpbatty@gmail.com>
Co-authored-by: Sophie Dankel <47993817+sdankel@users.noreply.github.com>
## Description
Fixes an issue where storage access wasn't working for proxied
contracts. The fix is passing the combined storage slots to the proxy
contract.
## 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).
- [ ] If my change requires substantial documentation changes, I have
[requested support from the DevRel
team](https://github.com/FuelLabs/devrel-requests/issues/new/choose)
- [ ] 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](https://github.com/FuelLabs/rfcs/blob/master/text/code-standards/external-contributors.md).
- [ ] I have requested a review from the relevant team or maintainers.
## Description
closes#6560.
closes#6559.
This PR adds AWS kms signer support. Which is enabled if
`--aws-kms-signer <ARN>` is present. If that is the case, an aws client
is created which is used to create a AwsSigner.
With this PR, we are able to supply a signing arn and with that we can
sign a transaction. This enables being able to revoke signing authority
for aws kms managed keys. So we can control deployments and owner/target
changes for a proxy contract. Effectively enabling multi-sig like proxy
contracts via aws kms.
Edit: Added a usage video for deploying a contract with proxy and
updating it while using a aws kms signer below:
https://github.com/user-attachments/assets/de26edb0-bbbb-4894-afa0-3fe50fba74cb
---------
Co-authored-by: Sophie Dankel <47993817+sdankel@users.noreply.github.com>
Co-authored-by: Joshua Batty <joshpbatty@gmail.com>
## Description
As part of #6179, this PR updates the remaining quick-fix crates to
their latest X.Y versions. Code fixes were needed to get compilation
working and tests passing.
Issue #6536 lists the crates that will need a bit more work to get
working and passing.
## Checklist
- [x] I have linked to any relevant issues.
- [x] I have commented my code, particularly in hard-to-understand
areas.
- [x] I have updated the documentation where relevant (API docs, the
reference, and the Sway book).
- [x] If my change requires substantial documentation changes, I have
[requested support from the DevRel
team](https://github.com/FuelLabs/devrel-requests/issues/new/choose)
- [x] I have added tests that prove my fix is effective or that my
feature works.
- [x] I have added (or requested a maintainer to add) the necessary
`Breaking*` or `New Feature` labels where relevant.
- [x] I have done my best to ensure that my PR adheres to [the Fuel Labs
Code Review
Standards](https://github.com/FuelLabs/rfcs/blob/master/text/code-standards/external-contributors.md).
- [x] I have requested a review from the relevant team or maintainers.
## Description
For #6179, PR #6501 kept bumping into errors as it was doing too many
things, so I've split that PR into multiple PRs. This is the first, and
the only thing it does is move all of the various `Cargo.toml`
dependencies into the single workspace `Cargo.toml`.
Future PRs will:
- Update dependency versions
- Update code that breaks from the version bumps
## Checklist
- [x] I have linked to any relevant issues.
- [x] I have commented my code, particularly in hard-to-understand
areas.
- [x] I have updated the documentation where relevant (API docs, the
reference, and the Sway book).
- [x] If my change requires substantial documentation changes, I have
[requested support from the DevRel
team](https://github.com/FuelLabs/devrel-requests/issues/new/choose)
- [x] I have added tests that prove my fix is effective or that my
feature works.
- [x] I have added (or requested a maintainer to add) the necessary
`Breaking*` or `New Feature` labels where relevant.
- [x] I have done my best to ensure that my PR adheres to [the Fuel Labs
Code Review
Standards](https://github.com/FuelLabs/rfcs/blob/master/text/code-standards/external-contributors.md).
- [x] I have requested a review from the relevant team or maintainers.
## Description
It looks like there was a change in how fuel core client returns the
block height. It used to be a hex number and we had to convert it to
decimal, but now it’s returning the number as a decimal so we don't need
to convert it.
## 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).
- [ ] If my change requires substantial documentation changes, I have
[requested support from the DevRel
team](https://github.com/FuelLabs/devrel-requests/issues/new/choose)
- [ ] 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](https://github.com/FuelLabs/rfcs/blob/master/text/code-standards/external-contributors.md).
- [ ] I have requested a review from the relevant team or maintainers.
## Description
closes#6558.
This PR fixes an issue with the forc-client build script that causes the
deployment tests to be updated manually for each proxy abi change. This
is a follow up on #6535 and was overlooked in that one. Not critical as
it does not break anything on the user side but rather an code-quality
issue.
## Description
This PR implements the `__contract_ret` as a diverging (returning `!`)
and accordingly the FuelVM `retd` instruction as being a terminator.
This strict semantics is needed in the #6351 which introduces strict(er)
verification of IR invariants.
## Checklist
- [x] I have linked to any relevant issues.
- [x] 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).
- [ ] If my change requires substantial documentation changes, I have
[requested support from the DevRel
team](https://github.com/FuelLabs/devrel-requests/issues/new/choose)
- [x] 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.
- [x] I have done my best to ensure that my PR adheres to [the Fuel Labs
Code Review
Standards](https://github.com/FuelLabs/rfcs/blob/master/text/code-standards/external-contributors.md).
- [x] I have requested a review from the relevant team or maintainers.
## Description
By using im::Vector inside TypeMap we avoid cloning everything when
cloning namespaces.
Improves TraitMap not to traverse all entries.
These changes incur a performance **increase** in the compilation time.
The benchmark compile takes 40% less time to run.
Fixes#6470.
## Checklist
- [x] I have linked to any relevant issues.
- [x] 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).
- [ ] If my change requires substantial documentation changes, I have
[requested support from the DevRel
team](https://github.com/FuelLabs/devrel-requests/issues/new/choose)
- [ ] I have added tests that prove my fix is effective or that my
feature works.
- [x] I have added (or requested a maintainer to add) the necessary
`Breaking*` or `New Feature` labels where relevant.
- [x] I have done my best to ensure that my PR adheres to [the Fuel Labs
Code Review
Standards](https://github.com/FuelLabs/rfcs/blob/master/text/code-standards/external-contributors.md).
- [x] I have requested a review from the relevant team or maintainers.
---------
Co-authored-by: Joshua Batty <joshpbatty@gmail.com>
Co-authored-by: IGI-111 <igi-111@protonmail.com>
## Description
Adds more tests to chunking, and also indirectly to SDK decoding.
Co-authored-by: Sophie Dankel <47993817+sdankel@users.noreply.github.com>
## Description
To be merged after https://github.com/FuelLabs/sway/pull/6250
## 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).
- [ ] If my change requires substantial documentation changes, I have
[requested support from the DevRel
team](https://github.com/FuelLabs/devrel-requests/issues/new/choose)
- [ ] 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](https://github.com/FuelLabs/rfcs/blob/master/text/code-standards/external-contributors.md).
- [ ] I have requested a review from the relevant team or maintainers.
---------
Co-authored-by: Brandon Kite <brandonkite92@gmail.com>
Co-authored-by: IGI-111 <igi-111@protonmail.com>
## Description
This PR adds chunk deployment based on LDC. Contracts larger than 100 kb
size, is split into chunks and chunks are deployed as `blobs`. Out of
these blobs we create a loader contract, which loads all the blobs using
`LDC` opcode.
One important thing is that this feature works nicely with the proxy
feature introduced in #6069, so a large contract, with proxy can be
deployed directly. Large contract will be split into chunks, chunks will
get deployed, loader will get get generated and deployed, after all
these a proxy contract is deployed and pointed to the loader contract
deployed.
Simple chunked deploy, chunked deployment re routing the call, chunked
deployment behind a proxy re routes the call is tested.
---------
Co-authored-by: Sophie Dankel <47993817+sdankel@users.noreply.github.com>
## Description
Updates all the dependencies for the current release.
Implements the fuel ABI generation changes proposed in
https://github.com/FuelLabs/fuel-specs/pull/599.
Removes the flag `--json-abi-with-callpaths` and the behavior is as if
it were true. We removed the flag because it is unsafe to produce JSON
ABIs without callpaths, so we shouldn't allow it.
Includes the LDC, BSIZ, BLDD and ED19 changes
from:https://github.com/FuelLabs/sway/pull/6409.
Fixes https://github.com/FuelLabs/sway/issues/5954
Fixes https://github.com/FuelLabs/sway/issues/5151
## Checklist
- [x] I have linked to any relevant issues.
- [x] 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).
- [ ] If my change requires substantial documentation changes, I have
[requested support from the DevRel
team](https://github.com/FuelLabs/devrel-requests/issues/new/choose)
- [x] I have added tests that prove my fix is effective or that my
feature works.
- [x] I have added (or requested a maintainer to add) the necessary
`Breaking*` or `New Feature` labels where relevant.
- [x] I have done my best to ensure that my PR adheres to [the Fuel Labs
Code Review
Standards](https://github.com/FuelLabs/rfcs/blob/master/text/code-standards/external-contributors.md).
- [x] I have requested a review from the relevant team or maintainers.
---------
Co-authored-by: Vaivaswatha Nagaraj <vaivaswatha.nagaraj@fuel.sh>
Co-authored-by: Kaya Gokalp <kayagokalp123@gmail.com>
Co-authored-by: Kaya Gökalp <kaya.gokalp@fuel.sh>
Co-authored-by: Igor Rončević <ironcev@hotmail.com>
Co-authored-by: IGI-111 <igi-111@protonmail.com>
Co-authored-by: Sophie Dankel <47993817+sdankel@users.noreply.github.com>
## Description
The current `forc deploy` command is designed to submit and await for
transaction finalization as much this is a common use case, for delayed
transactions, were transaction are submitted but can take time a lot of
time to be included and finalized. For this use cases I have implement a
suggestion `--submit-only` this will follow the current flow, but only
submit the transaction.
### Example use case for delayed transactions
In Bako Safe, as it is a multisig, it is necessary to have signatures
from multiple accounts before sending the transaction to the network. To
work together with forc deploy, a GraphQL Proxy has been developed that
works with the Fuel provider to allow sending the transaction to our
protocol.
```zsh
forc deploy --node-url 'https://api.bako.global/v1/graphql' --default-signer --submit-only
```
## Changes
- [x] Add a new deploy params `--submit-only`
- [x] Create a branch on the code to verify if the param is provided
- [x] Abstract create artifacts to a single function to avoid code
repetition
- [x] Modified transaction submission to allow for immediate submission
when the `submit_only` command is provided
- [x] Implemented tests for the new command
## Checklist
- [ ] I have linked to any relevant issues.
- [ ] I have commented my code, particularly in hard-to-understand
areas.
- [x] I have updated the documentation where relevant (API docs, the
reference, and the Sway book).
- [ ] If my change requires substantial documentation changes, I have
[requested support from the DevRel
team](https://github.com/FuelLabs/devrel-requests/issues/new/choose)
- [x] 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](https://github.com/FuelLabs/rfcs/blob/master/text/code-standards/external-contributors.md).
- [ ] I have requested a review from the relevant team or maintainers.
---------
Co-authored-by: Sophie Dankel <47993817+sdankel@users.noreply.github.com>
Co-authored-by: K1-R1 <77465250+K1-R1@users.noreply.github.com>
## Description
Part of #6068.
This PR adds couple of things:
1. A default proxy contract implementation taken from [sway
standards](https://github.com/FuelLabs/sway-standards/blob/master/standards/src/src14.sw).
2. Infra for creating, building and deploying the reference
implementation for proxy contracts.
3. Deployment procedure such that proxy contract is deployed while
working on a contract which enables the `[proxy]` in its forc.toml. In a
way that it is owned by the deployer and the target initially points to
implementation contract.
4. Infra for making a contract call into the already deployed proxy
contracts to update their targets.
5. Adds a `Building` text to the all forc build invocations to better
inform the user about what forc is doing behind the scenes.
6. Removes duplicate forc-wallet password prompts which was very
frustrating for the users. Now forc-wallet deployment path only asks for
password once.
7. Refactors around how secret_key is selected based on user input
8. Updated docs around forc-client
9. Docs around how to use the proxy feature
## How this works
If the user does not have a proxy table in their forc.toml, nothing
changes, same old deployment procedure is followed. Only difference is
that this PR improves the ux by removing the need of providing the
password multiple times.
If the user has a contract with a proxy table but without an address
like:
```TOML
[project]
authors = ["kaya"]
entry = "main.sw"
license = "Apache-2.0"
name = "impl-contract"
[dependencies]
[proxy]
enabled = true
```
Forc automatically creates a proxy contract based on the reference
implementation at
[SRC14](61fd4ad8f6). Sets its
target to the implementation contract, whichever contract enabled the
proxy and the owner to the deployer (signing account of the
transaction).
If the user has a contract with a proxy table and an address specified
like:
```TOML
[project]
authors = ["kaya"]
entry = "main.sw"
license = "Apache-2.0"
name = "impl-contract"
[dependencies]
[proxy]
enabled = true
address = "........."
```
Forc automatically makes a set target conract call to update the proxy
contract's target. Pointing it to the newly deployed impl contract which
defines the proxy table.
Generated proxy contract abi and bins are stored at
`~/.forc/.generated_proxy_contracts/project_name` for housekeeping.
## Description
This PR is part of https://github.com/FuelLabs/sway/issues/5110 and
introduces two new intrinsic: `__slice` and `__elem_at`.
`__slice` allows the creation of slices by slicing arrays or other
slices. Whilst `__elem_at` returns a reference to an item inside the
slice or the array.
## Out of bounds checks
These intrinsic will not generate any runtime checks, these must be done
manually, when and where appropriate; but they do a complete static
analysis of all indices, to avoid runtime buffer overflows, when
possible.
That means that at runtime, it is possible to do a buffer overflow when
reading/writing, which is an "undefined behaviour" as to what will
happen.
## Empty Array
This PR also solves a problem with empty arrays. Before empty arrays
such as `let a = []` were being type-checked as `[Never; 0]`, which
means that any code after them was being marked as dead.
Now we correctly type check them as `[Unknown; 0]` and return a more
friendly error.
```
4 |
5 | // Empty array
6 | let a = [];
| ^^ Type must be known at this point
7 | }
|
____
```
## Check of constants inside fns
This PR also solves a problem with not checking `const` expressions
inside `fns`. We, for example, do not allow slices in constants, but we
were only checking globals. Now we check constants also inside
functions, methods etc...
## Small improvements for our e2e
We can now `dbg` inside our e2e harness and get results like the ones
below. One needs to include the lib `test/src/e2e_vm_tests/utils` and
cal `something.dbg()` or `something.dbgln()`. There is no magic, and
structs/enums will need to manually implement the `Dbg` trait.
This is only to facilitate the debugging of our e2e tests.

## 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).
- [ ] If my change requires substantial documentation changes, I have
[requested support from the DevRel
team](https://github.com/FuelLabs/devrel-requests/issues/new/choose)
- [ ] 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](https://github.com/FuelLabs/rfcs/blob/master/text/code-standards/external-contributors.md).
- [ ] I have requested a review from the relevant team or maintainers.
## Description
Improves the UX for forc-deploy in the following ways:
- uses `dialoguer` for a nicer interface for entering password,
selecting the wallet account from the list, and agreeing to sign.
- displays the account information in a single line, with the ETH value
shown rather than the raw gwei, similar to the browser wallet
- only shows the base asset amount for accounts, rather than all assets,
since only base asset can be used for gas fees.
- for multiple-contract deployments, users now only have to choose the
account and confirm once
- added error handling for the case where multi-contract deployments
have different networks specified in their manifests
- Displays the network URL *before* deployment rather than after
- After deployment, links to the contract and block in the block
explorer rather than just showing the ID
### Single contract deployed

### Multiple contracts deployed (workspace)

## 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).
- [ ] If my change requires substantial documentation changes, I have
[requested support from the DevRel
team](https://github.com/FuelLabs/devrel-requests/issues/new/choose)
- [ ] 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](https://github.com/FuelLabs/rfcs/blob/master/text/code-standards/external-contributors.md).
- [ ] I have requested a review from the relevant team or maintainers.
## Description
This PR unifies the AST representation for the parsed and typed `impl
self` and `impl trait` declarations.
Previously we had a parsed node for `impl self`, which was converted
into a `impl trait` typed node.
Now we are doing the same for the parsed nodes and using a unified
`ImplSelfOrTrait` node.
This will make it possible for
https://github.com/FuelLabs/sway/pull/6245 to store the parsed decl id
relationship for this node.
## Checklist
- [x] 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).
- [ ] If my change requires substantial documentation changes, I have
[requested support from the DevRel
team](https://github.com/FuelLabs/devrel-requests/issues/new/choose)
- [ ] 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.
- [x] I have done my best to ensure that my PR adheres to [the Fuel Labs
Code Review
Standards](https://github.com/FuelLabs/rfcs/blob/master/text/code-standards/external-contributors.md).
- [x] I have requested a review from the relevant team or maintainers.
## Description
This PR fixes a problem with `std::Bytes`, `std::Vec` and `std::String`
buffer ownership. It also fixes a problem with buffer overflow when
encoding huge types.
## Buffer Ownership
Currently, types like `Bytes`, `Vec` and `String` do not guarantee
ownership of their buffer. That means that we can very easily alias the
underlying buffer and change its mutability by simply creating a new
instance.
For example:
```sway
let some_slice = ...;
let buffer = Bytes::from(some_slice);
let mut buffer2 = buffer.clone();
// Now I can change `some_slice`
```
## Type Inference bug
I also had to fix a small problem with the type inference of method
applications. The problem is that sometimes the type check does not
return an error on the first pass, but the type is still not concrete.
For example `x.get(0) == Some(2)`, becomes `eq(x.get(0), Some(2))`.
After the first pass, `x.get(0)` is correctly inferred to be
`Option<u8>`; but `Some(2)` is only typed as `Option<Numeric>`. This
happens because the first pass starts with `TypeInfo::Unknown`. We can
use the argument types here because they may still be non-concrete types
like "Self".
What the fix is doing is that it checks if the inferred type
`is_concrete`, assuming that `Numeric` is not. This will make "Some(2)"
be type-checked again at the second pass, after monomorphization and be
correctly typed as "Option<u8>".
## IR Verification errors
This PR also improves the error message for IR verification. Now the
error is shown inside the printed IR.

## Script to update contract-ids (optional)
At `test/update-contract-ids.sh` there is a small script that
automatically updates contract ids. Unfortunately, given the indirect
nature of contract calls, it is impossible for the script to know which
contract it needs to compile. So we need to specify the path to the
contract.
We also need to pass the compiler flags, because in some cases we use
`debug` profile, and in others we use `release`.
```sway
const FUEL_COIN_CONTRACT_ID = 0x1a88d0982d216958d18378b6784614b75868a542dc05f8cc85cf3da44268c76c; // AUTO-CONTRACT-ID ../../test_contracts/test_fuel_coin_contract --release
```
In the example above, the path and flags are appended in the bash
script. I failed trying to inject commands, so I think the append is
safe.
I can remove this from the PR, if we find that this is not the solution
we want at the moment.
## 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).
- [ ] If my change requires substantial documentation changes, I have
[requested support from the DevRel
team](https://github.com/FuelLabs/devrel-requests/issues/new/choose)
- [ ] 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](https://github.com/FuelLabs/rfcs/blob/master/text/code-standards/external-contributors.md).
- [ ] I have requested a review from the relevant team or maintainers.
## Description
Removes local snapshot we were using to fund our accounts as it is now
done by default as of https://github.com/FuelLabs/fuel-core/pull/1894.
By default `--default-signer` is signing it with the account funded by
fuel-core out of the box.
## Description
This PR implements `match` for string slices including radix trie
optimization and is a task of
https://github.com/FuelLabs/sway/issues/5110.
For example a simple `match` like
```
fn return_match_on_str_slice(param: str) -> u64 {
match param {
"get_a" => { 1u64 },
"get_a_b" => { 2u64 },
"get_b" => { 3u64 },
_ => { 1000u64 },
}
}
```
will generate code following this logic:
```
let packed_string = "get_a_b"
if str.len() == 5
if str[0..4] == "get_" at packed_string[0]
if str[4..5] == "b" at packed_string[6]
return branch 2
if str[4..5] == "a" at packed_string[4]
return branch 0
return wildcard branch
return wildcard branch
if str.len() == 7
if str[0..7] == "get_a_b" at packed_string[0]
return branch 1
return wildcard branch
return wildcard branch
```
In logical terms, this boils down to checking the length and an `O(N)`
check on the string. Albeit the bytecode will be more complex because of
all the branches.
Another interesting optimization is the "packed string literal" that
coalesces all "match arms string slices" into just one string. In the
case above, given that one of the arms contains all the necessary
strings for all other comparisons, we will create just one string
literal. Saving a lot of bytes in the data section.
The section below describes how `rustc` deals with this desugaring. I
think these choices make more sense to us for two reasons:
1 - Avoid testing common prefixes multiple times will spend less gas in
general (needs more testing);
2 - packing all strings will decrease the data section size.
This is the bytecode generated in this case:
```
fn return_match_on_str_slice(param: str) -> u64 {
match param {
"get_a" => { 1u64 },
"get_a_b" => { 2u64 },
"get_b" => { 3u64 },
_ => { 1000u64 },
}
} @ /home/xunilrj/github/sway/test/src/e2e_vm_tests/test_programs/should_pass/language/match_expressions_all/src/main.sw:22:1
0x0000017c PSHL 0xf ;; [149, 0, 0, 15]
0x00000180 PSHH 0x80000 ;; [150, 8, 0, 0]
0x00000184 MOVE R59 $sp ;; [26, 236, 80, 0]
0x00000188 CFEI 0x90 ;; [145, 0, 0, 144]
0x0000018c MOVE $writable R58 ;; [26, 67, 160, 0]
0x00000190 MOVE R19 R62 ;; [26, 79, 224, 0]
match param {
"get_a" => { 1u64 },
"get_a_b" => { 2u64 },
"get_b" => { 3u64 },
_ => { 1000u64 },
} @ /home/xunilrj/github/sway/test/src/e2e_vm_tests/test_programs/should_pass/language/match_expressions_all/src/main.sw:23:5
0x00000194 ADDI R17 R59 0x80 ;;
0x00000198 MOVI R18 0x10 ;;
0x0000019c MCP R17 $writable R18 ;;
0x000001a0 MOVI R17 0x7 ;; 0x7 = "get_a_b".len()
@ <autogenerated>:1:1
0x000001a4 LW $writable R59 0x11 ;; R59 + 0x11 = a.len()
0x000001a8 EQ $writable $writable R17 ;; a.len() == 0x7
0x000001ac JNZF $writable $zero 0x3c ;; if false jump to 2a0?
0x000001b0 MOVI R17 0x5 ;; we have two arms with length equals 0x5
0x000001b4 LW $writable R59 0x11 ;; R59 + 0x11 = a.len()
0x000001b8 EQ $writable $writable R17 ;; a.len() == 0x5
0x000001bc MOVI R17 0x3e8 ;; 0x3e8 = 1000 (wildcard return value)
0x000001c0 JNZF $writable $zero 0x1 ;; if true jump to 1c8
0x000001c4 JMPF $zero 0x35 ;; if false jump to 29c (will return R17)
0x000001c8 LW $writable R63 0x3 ;; R63 = start of data section, will load 13c
0x000001cc ADD $writable $writable $pc ;; $writable = 0x308 = packed strings
0x000001d0 ADDI R17 R59 0x20 ;;
0x000001d4 SW R59 $writable 0x4 ;; R59 + 0x4 = packed strings
0x000001d8 MOVI $writable 0x7 ;;
0x000001dc SW R59 $writable 0x5 ;; R59 + 0x5 = 0x7
0x000001e0 ADDI $writable R59 0x30 ;;
0x000001e4 MOVI R18 0x10 ;;
0x000001e8 MCP $writable R17 R18 ;; R59 + 0x30 = R59 + 0x20
0x000001ec MOVI R18 0x4 ;; 0x4 = "get_".len()
0x000001f0 LW $writable R59 0x10 ;;
0x000001f4 ADDI $writable $writable 0x0 ;;
0x000001f8 LW R17 R59 0x6 ;; R17 = a.ptr()
0x000001fc ADDI R17 R17 0x0 ;;
0x00000200 MEQ $writable $writable R17 R18 ;; a[0..4] = packed[0..4]
0x00000204 MOVI R17 0x3e8 ;; 0x3e8 = 1000 (wildcard return value)
0x00000208 JNZF $writable $zero 0x1 ;; if true jump to 210
0x0000020c JMPF $zero 0x23 ;; if false jump to 29c (will return R17)
....
.data_section:
0x00000300 .bytes as hex ([]), len i0, as ascii ""
0x00000300 .word i18446744073709486084, as hex be bytes ([FF, FF, FF, FF, FF, FF, 00, 04])
0x00000308 .bytes as hex ([67, 65, 74, 5F, 61, 5F, 62]), len i7, as ascii "get_a_b"
0x00000310 .word i500, as hex be bytes ([00, 00, 00, 00, 00, 00, 01, F4])
0x00000318 .word i316, as hex be bytes ([00, 00, 00, 00, 00, 00, 01, 3C])
0x00000320 .word i244, as hex be bytes ([00, 00, 00, 00, 00, 00, 00, F4])
0x00000328 .word i176, as hex be bytes ([00, 00, 00, 00, 00, 00, 00, B0])
0x00000330 .word i100, as hex be bytes ([00, 00, 00, 00, 00, 00, 00, 64])
```
## How `rustc` desugar `match`
For comparison, this is the generated ASM with comments on how Rust
tackles this.
First, this is the function used:
```
#[inline(never)]
fn f(a: &str) -> u64 {
match a {
"get_method" => 0,
"get_tokens" => 1,
"get_something_else" => 2,
"get_tokens_2" => 3,
"clear" => 4,
"get_m" => 5,
_ => 6,
}
}
```
This is the LLVM IR generated. There is a match on the length of each
string slice arms. The valid range is (5, 18), everything outside of
this is the wildcard match arm. This range will be important later.
```
efine internal fastcc noundef i64 @example::f::hdb860bcd6d383112(ptr noalias nocapture noundef nonnull readonly align 1 %a.0, i64 noundef %a.1) unnamed_addr {
start:
switch i64 %a.1, label %bb13 [
i64 10, label %"_ZN73_$LT$$u5b$A$u5d$$u20$as$u20$core..slice..cmp..SlicePartialEq$LT$B$GT$$GT$5equal17h510120b4d3581de7E.exit"
i64 18, label %"_ZN73_$LT$$u5b$A$u5d$$u20$as$u20$core..slice..cmp..SlicePartialEq$LT$B$GT$$GT$5equal17h510120b4d3581de7E.exit30"
i64 12, label %"_ZN73_$LT$$u5b$A$u5d$$u20$as$u20$core..slice..cmp..SlicePartialEq$LT$B$GT$$GT$5equal17h510120b4d3581de7E.exit35"
i64 5, label %"_ZN73_$LT$$u5b$A$u5d$$u20$as$u20$core..slice..cmp..SlicePartialEq$LT$B$GT$$GT$5equal17h510120b4d3581de7E.exit40"
]
```
this is how "f" is called
```
mov rbx, qword ptr [rsp + 32]
mov r14, qword ptr [rsp + 40]
mov rsi, qword ptr [rsp + 48] <- length of the string slice
mov rdi, r14 <- ptr to string slice
call _ZN4main1f17h126a5dfd4e318ebcE
```
this is `f` body.
`ja .LBB8_12` jumps into a simple return, returning EAX as 6. It is the
wildcard return value. The cleverness of this is that when `RSI` is
smaller than 5, it will become negative (because of `add rsi, -5`,
wrapping into huge unsigned ints, and will also trigger `JA` (which
stands for `Jump Above`), effectively jumping when the slice length is
outside of the expected range which is (5, 18).
After that, it uses a jump table based on the string length minus 5.
Everywhere the string length is invalid, the jump address is `LBB8_12`.,
still returning `EAX` as 6.
```
_ZN4main1f17h126a5dfd4e318ebcE:
.cfi_startproc
mov eax, 6
add rsi, -5
cmp rsi, 13
ja .LBB8_12
lea rcx, [rip + .LJTI8_0]
movsxd rdx, dword ptr [rcx + 4*rsi]
add rdx, rcx
jmp rdx
```
```
.LBB8_12:
ret
```
This is the jump table used:
```
.LJTI8_0:
.long .LBB8_9-.LJTI8_0
.long .LBB8_12-.LJTI8_0
.long .LBB8_12-.LJTI8_0
.long .LBB8_12-.LJTI8_0
.long .LBB8_12-.LJTI8_0
.long .LBB8_2-.LJTI8_0 <- 5th entry is length = 10 (remember we add -5 to the length)
.long .LBB8_12-.LJTI8_0
.long .LBB8_8-.LJTI8_0
.long .LBB8_12-.LJTI8_0
.long .LBB8_12-.LJTI8_0
.long .LBB8_12-.LJTI8_0
.long .LBB8_12-.LJTI8_0
.long .LBB8_12-.LJTI8_0
.long .LBB8_6-.LJTI8_0
```
The interesting entry is entry 5, which has two strings: "get_method"
and "get_tokens". Here we can see that `rust` actually compares the
complete string slice twice. Even though they have an intersection.
```
.LBB8_2:
movabs rcx, 7526752397670245735=6874656D5F746567="htem_teg" (inverted "get_meth")
xor rcx, qword ptr [rdi]
movzx edx, word ptr [rdi + 8]
xor rdx, 25711=646F="do" (inverted "od")
or rdx, rcx
je .LBB8_3
movabs rcx, 7308057365947114855=656B6F745F746567="ekot_teg" (inverted "get_toke")
xor rcx, qword ptr [rdi]
movzx edx, word ptr [rdi + 8]
xor rdx, 29550=736E="sn" (inverted "ns")
or rdx, rcx
je .LBB8_5
```
```
.LBB8_3:
xor eax, eax <- returns 0
ret
```
```
.LBB8_5:
mov eax, 1 <- returns 1
ret
```
This is comparable to what `clang` is doing:
https://github.com/rust-lang/rust/issues/61961
## Code and Bytecode
This PR also implements code printing when printing bytecode. For now
this is only enable for tests. It gnerates something like:
```
match param {
"get_a" => { 1u64 },
"get_a_b" => { 2u64 },
"get_b" => { 3u64 },
_ => { 1000u64 },
} @ /home/xunilrj/github/sway/test/src/e2e_vm_tests/test_programs/should_pass/language/match_expressions_all/src/main.sw:23:5
0x00000194 ADDI R17 R59 0x80 ;;
0x00000198 MOVI R18 0x10 ;;
0x0000019c MCP R17 $writable R18 ;;
0x000001a0 MOVI R17 0x7 ;; 0x7 = "get_a_b".len()
@ <autogenerated>:1:1
0x000001a4 LW $writable R59 0x11 ;; R59 + 0x11 = a.len()
0x000001a8 EQ $writable $writable R17 ;; a.len() == 0x7
```
As we can see, not great, but helpful nonetheless. We can (should?)
improve this by better "carrying" spans in all transformations and
lowerings.
## Checklist
- [x] I have linked to any relevant issues.
- [x] 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).
- [ ] If my change requires substantial documentation changes, I have
[requested support from the DevRel
team](https://github.com/FuelLabs/devrel-requests/issues/new/choose)
- [ ] 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](https://github.com/FuelLabs/rfcs/blob/master/text/code-standards/external-contributors.md).
- [ ] I have requested a review from the relevant team or maintainers.
---------
Co-authored-by: Joshua Batty <joshpbatty@gmail.com>
Co-authored-by: IGI-111 <igi-111@protonmail.com>
## Description
Includes critical fix https://github.com/FuelLabs/sway/pull/6212
## 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).
- [ ] If my change requires substantial documentation changes, I have
[requested support from the DevRel
team](https://github.com/FuelLabs/devrel-requests/issues/new/choose)
- [ ] 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](https://github.com/FuelLabs/rfcs/blob/master/text/code-standards/external-contributors.md).
- [ ] I have requested a review from the relevant team or maintainers.
## Description
Makes the indendation and formatting consistent for forc's action
messages.
### forc build
before

after

### forc test
before

after

## 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).
- [ ] If my change requires substantial documentation changes, I have
[requested support from the DevRel
team](https://github.com/FuelLabs/devrel-requests/issues/new/choose)
- [ ] 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](https://github.com/FuelLabs/rfcs/blob/master/text/code-standards/external-contributors.md).
- [ ] I have requested a review from the relevant team or maintainers.