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

LDC support in predicates #848

Merged
merged 17 commits into from
Oct 5, 2024
Merged

LDC support in predicates #848

merged 17 commits into from
Oct 5, 2024

Conversation

Voxelot
Copy link
Member

@Voxelot Voxelot commented Oct 4, 2024

Enables predicates to load immutable blobs of code from storage. This helps reduce bloating blockspace with large predicates.

Core changes:

  • $PC can now jump outside of predicate memory range
  • ldc, bldd, and bsiz instructions are allowed inside of predicates (but only for blobs, no contracts)
  • verifying or estimating predicates now requires access to blob storage

Comment on lines +704 to +705
| JNZB | JNEF | JNEB | CFEI | CFSI | CFE | CFS | GTF | LDC | BSIZ | BLDD => {
true
Copy link
Contributor

Choose a reason for hiding this comment

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

test needs updating (

pub fn is_predicate_allowed(&self) -> bool {
)

}
}

impl StorageRead<ContractsState> for PredicateStorage {
impl<D> StorageRead<ContractsState> for PredicateStorage<D>
Copy link
Contributor

Choose a reason for hiding this comment

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

question for my own understanding: in what cases can these operations be called?

Copy link
Collaborator

Choose a reason for hiding this comment

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

We allow only blobs in the predicate. Any other access to the storage should return an error

Copy link
Contributor

@acerone85 acerone85 left a comment

Choose a reason for hiding this comment

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

My understanding is that after this PR the contract code will be loaded from a blob, hence we keep predicate stateless. Just to check that I am getting this correctly?

Added one simple test to check that we can call blobs and they are executed correctly.
@xgreenx xgreenx marked this pull request as ready for review October 5, 2024 11:29
@xgreenx xgreenx requested a review from a team October 5, 2024 11:29
AurelienFT
AurelienFT previously approved these changes Oct 5, 2024
@@ -108,6 +108,7 @@ where
}) if owner == &pk => Some(*witness_index as usize),
_ => None,
})
.sorted()
Copy link
Contributor

Choose a reason for hiding this comment

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

personal question: what is the reason behind this ?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Just notice going over the code that we call dedup, but it not we expect=) So I added dedup to have behavior that we want

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, dedup() works on "consecutive identical elements". This bit me many times in the past :)
Good catch.

@xgreenx
Copy link
Collaborator

xgreenx commented Oct 5, 2024

My understanding is that after this PR the contract code will be loaded from a blob, hence we keep predicate stateless. Just to check that I am getting this correctly?

No. In this change we break the idea that predicates are stateless. This PR enables access to the blobs in the predicate context. Since blobs are monotonic it shouldn't invalidate the predicate. If blob doesn't exist, we return a panic. If blob exists, it will not change later.

#[derive(Debug, Clone)]
pub enum PredicateStorageError {
/// Storage operation is unavailable in predicate context.
UnsupportedStorageOperation,
Copy link
Contributor

Choose a reason for hiding this comment

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

nit, and definitely not for this PR. But this could be also a StorageError.

@acerone85
Copy link
Contributor

I think this has been tested already extensively, it would be nice to have a test that checks that loading blobs in a predicate works as expected. That said, it would be nice to have tests for it. Not blocking.

@Voxelot
Copy link
Member Author

Voxelot commented Oct 5, 2024

I think this has been tested already extensively, it would be nice to have a test that checks that loading blobs in a predicate works as expected. That said, it would be nice to have tests for it. Not blocking.

The rust-sdk has tests with their new custom blob loader to verify this all works.

@Voxelot Voxelot added this pull request to the merge queue Oct 5, 2024
Merged via the queue into master with commit 90edebd Oct 5, 2024
40 checks passed
@Voxelot Voxelot deleted the feature/predicate-ldc branch October 5, 2024 19:15
@xgreenx xgreenx restored the feature/predicate-ldc branch October 5, 2024 19:40
This was referenced Oct 5, 2024
Voxelot added a commit to FuelLabs/fuel-core that referenced this pull request Oct 5, 2024
## Linked Issues/PRs
FuelLabs/fuel-vm#848
FuelLabs/fuel-vm#849

## Description
<!-- List of detailed changes -->

## Checklist
- [x] Breaking changes are clearly marked as such in the PR description
and changelog
- [x] New behavior is reflected in tests
- [ ] [The specification](https://github.com/FuelLabs/fuel-specs/)
matches the implemented behavior (link update PR if changes are needed)

### Before requesting review
- [x] I have reviewed the code myself

---------

Co-authored-by: AurelienFT <aurelien.foucault@epitech.eu>
Co-authored-by: green <xgreenx9999@gmail.com>
Co-authored-by: Ahmed Sagdati <37515857+segfault-magnet@users.noreply.github.com>
Dentosal added a commit to FuelLabs/fuel-specs that referenced this pull request Oct 23, 2024
Closes #456

Requires #611
VM PR FuelLabs/fuel-vm#848

### Before requesting review
- [x] I have reviewed the code myself

---------

Co-authored-by: Brandon Kite <brandonkite92@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants