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

feat: checks on upper bounds of contract storage sizes #169

Open
wants to merge 21 commits into
base: main
Choose a base branch
from

Conversation

@TilakMaddy TilakMaddy marked this pull request as ready for review December 14, 2024 14:34
@TilakMaddy TilakMaddy marked this pull request as draft December 14, 2024 15:21
@TilakMaddy TilakMaddy marked this pull request as ready for review December 14, 2024 15:23
@TilakMaddy TilakMaddy changed the title feat: pre-checks for upper bound of contracts' sizes feat: checks on the upper bound of contract size Dec 14, 2024
@TilakMaddy TilakMaddy changed the title feat: checks on the upper bound of contract size feat: checks on upper bounds of contract storage sizes Dec 14, 2024
crates/sema/src/typeck/mod.rs Outdated Show resolved Hide resolved
crates/sema/src/typeck/mod.rs Outdated Show resolved Hide resolved
crates/sema/src/typeck/mod.rs Outdated Show resolved Hide resolved
crates/sema/src/typeck/mod.rs Outdated Show resolved Hide resolved
crates/cli/src/lib.rs Outdated Show resolved Hide resolved
@TilakMaddy TilakMaddy requested a review from DaniPopes December 15, 2024 09:35
crates/sema/src/typeck/mod.rs Outdated Show resolved Hide resolved
crates/cli/src/lib.rs Outdated Show resolved Hide resolved
crates/cli/src/cli.rs Outdated Show resolved Hide resolved
…; branch 'main' of github.com:paradigmxyz/solar into feat/ast-validation-p10
@TilakMaddy TilakMaddy requested a review from DaniPopes February 5, 2025 17:07
@TilakMaddy
Copy link
Contributor Author

@DaniPopes I have also added a test case to demonstrate what happens when more than 2^256 - 1 storage slots are requested.

crates/config/src/opts.rs Outdated Show resolved Hide resolved
let mut total_size = U256::from(1);
for field_id in strukt.fields {
let variable = gcx.hir.variable(*field_id);
let t = gcx.type_of_hir_ty(&variable.ty);
Copy link
Member

Choose a reason for hiding this comment

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

please don't use type_of_hir_ty since it recomputes the type which is already computed for the variable; instead use type_of_item and struct_field_types, and also you have to check for recursive struct so as to not recurse infinitely with struct_recursiveness

applies above in check_storage_size_upper_bound too

Copy link
Contributor Author

@TilakMaddy TilakMaddy Feb 7, 2025

Choose a reason for hiding this comment

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

@DaniPopes I have applied the suggestion and got the tests passing but I have 2 doubts

  • Why check again for struct recursiveness when it's already done here ? Also I'm not sure where to add the logic

  • Why does doing gcx.type_of_item wrap all the contract's elementary-type-storage-variables in Ref(.., DataLocation::Storage) ? Is it by design or bug? Because technically there could be "references" to "storage variables" used within functions that which does NOT make them the storage variables themseleves?

[Given gcx.type_of_hir_ty(..) doesn't do this "wrapping"] So they are not quite interchangeable 🤔 . . .

crates/sema/src/typeck/mod.rs Outdated Show resolved Hide resolved
crates/sema/src/typeck/mod.rs Outdated Show resolved Hide resolved
@TilakMaddy TilakMaddy requested a review from DaniPopes February 7, 2025 17:48
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.

2 participants