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

Don't ignore errors reported after analysis #15624

Merged
merged 2 commits into from
Dec 11, 2024

Conversation

cameel
Copy link
Member

@cameel cameel commented Dec 7, 2024

Follow-up to #15168.

Originally this was a part of #15610, but I decided to extract it because it's really an issue of its own, even though before #15610 we weren't throwing any errors that could trigger it.

The issue is that CLI and Standard JSON interface don't check for errors after analysis and just happily proceed with assembling. CompilerStack also makes the same mistake when using YulStack internally. As a result, if an UnimplementedFeatureError were to be reported it would be ignored and we'd report empty bytecode, or run into an assertion/segfault in the process.

In addition to that UnimplementedFeatureErrors caught during parsing were not reported as a parsing failure.

@cameel cameel requested review from r0qs and matheusaaguiar December 7, 2024 02:03
@cameel cameel self-assigned this Dec 7, 2024
@cameel cameel force-pushed the dont-ignore-post-analysis-errors branch from df69431 to c475915 Compare December 7, 2024 03:51
Copy link
Member

@r0qs r0qs left a comment

Choose a reason for hiding this comment

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

Nice, thanks for extracting this PR.

libsolidity/interface/CompilerStack.cpp Show resolved Hide resolved
Comment on lines +1255 to +1256
stack.parserResult() &&
!stack.parserResult()->hasContiguousSourceIndices()
Copy link
Member

@r0qs r0qs Dec 10, 2024

Choose a reason for hiding this comment

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

Previously, stack.optimize() was called prior to invoking stack.parserResult(). However, now it is called afterward (on line 1264). If I’m not mistaken, the Object returned by parserResult() can also be modified by optimize(), meaning that hasContiguousSourceIndices will not be checked against the optimized object anymore, no? Is this intentional, or am I misunderstanding something?

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 don't think that was intentional. The check was inserted after optimize() probably simply because it was more convenient to do it there. IMO it makes more sense to do such checks on the unoptimized code that the user is submitting rather than on some modified version so the change is good.

In any case, it should not affect solc behavior in practice - optimize() theoretically could change the code in an arbitrary way, but in practice it will never touch the @use-src annotation so this property should remain unchanged.

We also have a second validation against this in the asm export code, which would catch this if it did happen:

solAssert(maxSourceIndex + 1 >= _sourceIndices.size());
solRequire(
_sourceIndices.size() == 0 || _sourceIndices.size() == maxSourceIndex + 1,
AssemblyImportException,
"The 'sourceList' array contains invalid 'null' item."
);

We have the check in the CLI only because we don't catch AssemblyImportError there. Perhaps we should later change it into a CodeGenerationError so that it gets caught by YulStack and reported as a normal error.

Copy link
Member

Choose a reason for hiding this comment

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

We have the check in the CLI only because we don't catch AssemblyImportError there. Perhaps we should later change it into a CodeGenerationError so that it gets caught by YulStack and reported as a normal error.

Yeah, I don't see why not do that.

Copy link
Member Author

Choose a reason for hiding this comment

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

ok, I'll keep it in mind for when we're done with this series of PRs and can actually handle those errors properly.

@cameel cameel force-pushed the dont-ignore-post-analysis-errors branch from c475915 to 2f6d9ab Compare December 11, 2024 00:05
@cameel cameel requested a review from r0qs December 11, 2024 00:34
@cameel cameel force-pushed the dont-ignore-post-analysis-errors branch from 2f6d9ab to 20da2f1 Compare December 11, 2024 00:37
Copy link
Member

@r0qs r0qs left a comment

Choose a reason for hiding this comment

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

It looks fine to me now ;)

@cameel cameel force-pushed the dont-ignore-post-analysis-errors branch from 20da2f1 to 95c6e84 Compare December 11, 2024 13:45
@cameel cameel enabled auto-merge December 11, 2024 13:45
@cameel cameel merged commit 61f0d84 into develop Dec 11, 2024
73 checks passed
@cameel cameel deleted the dont-ignore-post-analysis-errors branch December 11, 2024 14:20
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