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

fuel-core v0.13 upgrade #3181

Merged
merged 25 commits into from
Nov 2, 2022
Merged

fuel-core v0.13 upgrade #3181

merged 25 commits into from
Nov 2, 2022

Conversation

Voxelot
Copy link
Member

@Voxelot Voxelot commented Oct 28, 2022

  • $rB on state opcodes is now used as a flag for whether the storage slot was previously set
  • $rD on quad word state opcodes is reserved for use as accessing a range of slots (currently hardcoded to 1)

currently blocked on fuel-rs upgrade

Closes #3159
Closes #2115 (the dependency is on sway-core now)

Had to disable the u128 sqrt tests for now as they are too expensive / slow, as per @mohammadfawaz suggestion.

Copy link
Contributor

@mohammadfawaz mohammadfawaz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is amazing, thank you @Voxelot. Everything here seems very reasonable to me.

I suppose once we figure out how to use $rB, we have to expose it in IR as an output to state_read_* and state_write_* instructions.

sway-core/src/asm_generation/asm_builder.rs Outdated Show resolved Hide resolved
sway-core/src/asm_generation/asm_builder.rs Outdated Show resolved Hide resolved
sway-core/src/asm_generation/asm_builder.rs Outdated Show resolved Hide resolved
Co-authored-by: Mohammad Fawaz <mohammadfawaz89@gmail.com>
@mohammadfawaz
Copy link
Contributor

mohammadfawaz commented Oct 28, 2022

As we were just talking about the fuel-core in CI, I remembered that

image: ghcr.io/fuellabs/fuel-core:v0.11.2
and
image: ghcr.io/fuellabs/fuel-core:v0.11.2
should be updated.

Voxelot added a commit to FuelLabs/fuels-rs that referenced this pull request Nov 1, 2022
WIP to upgrade to fuel-core 0.13 with the new generic tx format

sway tests were compiled using forc from this PR:
FuelLabs/sway#3181

Because there were breaking changes to the fuel-vm opcodes, we have to
check in the compiled sway files for now until a new version of forc can
be released. However, releasing forc is blocked on the SDK supporting
fuel-core 0.13, so the upgrades were done concurrently.

Co-authored-by: green <xgreenx9999@gmail.com>
@Voxelot Voxelot marked this pull request as ready for review November 2, 2022 02:07
mohammadfawaz
mohammadfawaz previously approved these changes Nov 2, 2022
@Voxelot Voxelot enabled auto-merge (squash) November 2, 2022 02:24
mohammadfawaz
mohammadfawaz previously approved these changes Nov 2, 2022
@mohammadfawaz mohammadfawaz requested review from a team November 2, 2022 03:43
u_128 = U128::from(0, 1);
root_of_u_128 = u_128.sqrt();
assert(root_of_u_128 == U128::from(0, 1));
//let mut u_128: U128 = U128::from(0, 49);
Copy link
Member

@JoshuaBatty JoshuaBatty Nov 2, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this block of code meant to be commented out for this PR?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah. The operation is now too expensive with the new gas schedule and the test was running out of gas. The implementation should probably be revamped. It's a new feature anyways (like 2 days ago).

@JoshuaBatty JoshuaBatty requested review from a team November 2, 2022 04:17
@Voxelot Voxelot merged commit 11496e6 into master Nov 2, 2022
@Voxelot Voxelot deleted the Voxelot/fuel-core-0.13 branch November 2, 2022 04:19
MujkicA pushed a commit to FuelLabs/fuels-rs that referenced this pull request Nov 4, 2022
WIP to upgrade to fuel-core 0.13 with the new generic tx format

sway tests were compiled using forc from this PR:
FuelLabs/sway#3181

Because there were breaking changes to the fuel-vm opcodes, we have to
check in the compiled sway files for now until a new version of forc can
be released. However, releasing forc is blocked on the SDK supporting
fuel-core 0.13, so the upgrades were done concurrently.

Co-authored-by: green <xgreenx9999@gmail.com>
mohammadfawaz added a commit that referenced this pull request Nov 5, 2022
Once we have a fully fledged instruction combining optimization pass,
these types of optimizations won't be needed anymore (for the most
part). For now, this allows us to re-enable the `u128_root_test` that
was disabled in #3181.
* Switch division by 2 to a shift left by 1
* Switch to using the lower part of a `U128` in situations where the
upper part is obviously not impacted.

This cuts down the gas cost for `sqrt` by around 30-40% and the
`u128_root_test` now consumes ~77M gas. Previously, the test was running
out of gas (our default limit is 100M).

I also made the same optimization in `U256` but notice that the
`u256_div_test` was disabled (doesn't have a `test.toml`!) so I enabled.
The test was actually running out of gas before my change but now it
just barely passes with like 98M gas, which is dangerous.

Finally, I replaced the method of multiplication in both `U128` and
`U256` and enabled two previously disabled tests:
* `u256_mul_test` which used to run out of gas but now takes ~21M (so
that's a least 5 X improvement).
* `u256_ops_test` which runs fine.

In short, div and mul for both `U128` and `U256` are now much cheaper
and so is `sqrt` for `U128` (`U256` doesn't have a `sqrt` yet).

Closes #3256 
Closes #3245

Co-authored-by: João Matos <joao@tritao.eu>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants