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

[Aleo ins parser] Fix array type anomaly. #2017

Merged
merged 2 commits into from
Oct 8, 2023
Merged

Conversation

acoglio
Copy link
Contributor

@acoglio acoglio commented Sep 26, 2023

Fixes #2016.

@acoglio acoglio requested review from howardwu and d0cd September 26, 2023 06:29
Copy link
Collaborator

@d0cd d0cd left a comment

Choose a reason for hiding this comment

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

LGTM!

@@ -42,8 +42,6 @@ impl<N: Network> Parser for ArrayType<N> {
Ok((string, length))
}

// Parse the whitespace and comments from the string.
let (string, _) = Sanitizer::parse(string)?;
Copy link
Member

Choose a reason for hiding this comment

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

I think this parse is justified. At the least we should have parse_whitespaces.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This array type parser is called by the plaintext type parser, which expects whitespace to have been skipped over already: the other two alternative parsers for plaintext type, namely literal type and identifier, do not skip over whitespace.

This is an instance of a general pattern in the Aleo instructions parser:

  1. Some (larger) constructs are parsed by first skipping over white space (and sometimes also comments).
  2. Other (smaller) constructs are parsed without any such initial skipping, i.e. they are expected to start right there. Their callers skip white space already.

Plaintext types, including array types, belong to the second group of constructs above.

Copy link
Member

@howardwu howardwu Oct 8, 2023

Choose a reason for hiding this comment

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

I see your perspective, we should make sure its parent callers have some notion of parse_whitespace since we don't invoke string.trim() before calling the parser.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, definitely. I believe that to be the case. I don't have a formal proof yet, but here's an argument. As you may know, I've derived the ABNF grammar of Aleo instructions directly from the parser. So under the (good) assumption that the grammar is consistent with the parser, we can see the following in the grammar:

  • Every occurrence of plaintext-type not at the start of the right side of a rule is preceded by ws, which corresponds to Sanitizer::parse_whitespaces.
  • plainttext-type occurs at the start of the right sides of value-type, mapping-type, finalize-type, and entry-type.
  • We repeat the same argument for value-type, ..., entry-type, recursively, and find that there is always a preceding ws.

(That was actually a sketch of a formal proof.)

@howardwu howardwu merged commit 0424b18 into testnet3 Oct 8, 2023
@howardwu howardwu deleted the fix/array-type-parse branch October 8, 2023 15:55
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.

[Bug] Anomaly in array type parsing
3 participants