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

Improve error handling of ids variables #851

Merged
merged 22 commits into from
Feb 17, 2023
Merged

Improve error handling of ids variables #851

merged 22 commits into from
Feb 17, 2023

Conversation

fmoletta
Copy link
Member

@fmoletta fmoletta commented Feb 16, 2023

Currently, when retrieving ids values from memory, all internal memory errors get replaced by the FailedToGetIds error, which doesnt give us much information about what went wrong.
This PR aims to remove this error, and replace it with variants that state which is the identifier that couldnt be computed.
Also, methods reflecting internal computation of ids values and addresses will have their return values changed to Option<>, as their errors arent and wont be used
This pr also refactors secp hints to use concrete types for structs (EcPoint & BigInt3) failing to create these types will return an UnknownIdentifier or IdentifierHasNoMember error instead of relying on internal memory errors

After this PR the following error cases will be outputed by the hint in case of undetermined ids:

  • UnknownIdentifier: The identifier is unknown (aka ids.val doesnt exist)
  • IdentifierNotInteger/IdentifierNotRelocatable: The identifier is of invalid type (aka ids.val exists but its not integer/reloctable)
  • IdentifierHasNoMember: The identifier doesnt have a member (aka ids.val.x doesnt exist or has incorrect type)

@fmoletta fmoletta changed the title Get rid of uninformative FailedToComputeOperands error Get rid of uninformative FailedToGetIds error Feb 16, 2023
@fmoletta fmoletta changed the title Get rid of uninformative FailedToGetIds error Improve error handling of ids variables Feb 16, 2023
@fmoletta fmoletta marked this pull request as ready for review February 17, 2023 13:34
@codecov
Copy link

codecov bot commented Feb 17, 2023

Codecov Report

Merging #851 (1a7ee5d) into main (c2d80f8) will increase coverage by 0.03%.
The diff coverage is 96.92%.

@@            Coverage Diff             @@
##             main     #851      +/-   ##
==========================================
+ Coverage   96.79%   96.82%   +0.03%     
==========================================
  Files          69       69              
  Lines       28788    28835      +47     
==========================================
+ Hits        27864    27920      +56     
+ Misses        924      915       -9     
Impacted Files Coverage Δ
src/vm/vm_memory/memory_segments.rs 99.02% <80.00%> (ø)
src/hint_processor/hint_processor_utils.rs 88.51% <81.39%> (+1.89%) ⬆️
...int_processor/builtin_hint_processor/hint_utils.rs 94.59% <90.62%> (-3.73%) ⬇️
src/vm/vm_core.rs 97.39% <92.59%> (ø)
...t_processor/builtin_hint_processor/dict_manager.rs 95.72% <95.45%> (ø)
...cessor/builtin_hint_processor/secp/bigint_utils.rs 98.21% <98.71%> (+0.34%) ⬆️
..._processor/builtin_hint_processor/secp/ec_utils.rs 98.78% <98.73%> (-0.20%) ⬇️
..._processor/builtin_hint_processor/blake2s_utils.rs 99.48% <100.00%> (+0.25%) ⬆️
...int_processor/builtin_hint_processor_definition.rs 98.67% <100.00%> (ø)
...uiltin_hint_processor/cairo_keccak/keccak_hints.rs 93.53% <100.00%> (ø)
... and 35 more

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

Copy link
Member

@Oppen Oppen left a comment

Choose a reason for hiding this comment

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

LGTM but see comments.

Comment on lines +23 to +27
pub(crate) struct BigInt3<'a> {
pub d0: Cow<'a, Felt>,
pub d1: Cow<'a, Felt>,
pub d2: Cow<'a, Felt>,
}
Copy link
Member

Choose a reason for hiding this comment

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

Why Cow<_>?

Copy link
Member Author

Choose a reason for hiding this comment

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

I wanted to use references when possible instead of cloning values, and using references wasn't possible

Comment on lines 15 to 18
#[error("Expected ids.{0} to be an Integer value")]
IdentifierNotInteger(String),
#[error("Expected ids.{0} to be a Relocatable value")]
IdentifierNotRelocatable(String),
Copy link
Member

Choose a reason for hiding this comment

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

It may be a good idea (or not, I'm not really sure) to include the resolved address.

Copy link
Member Author

Choose a reason for hiding this comment

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

On it!

Copy link
Member Author

Choose a reason for hiding this comment

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

Done

@fmoletta fmoletta added this pull request to the merge queue Feb 17, 2023
Merged via the queue into main with commit abaf215 Feb 17, 2023
@fmoletta fmoletta deleted the error-handling-ids branch February 17, 2023 22:11
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.

None yet

3 participants