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

Fix uncaught exception when using empty string for yul optimization flags #14967

Merged
merged 1 commit into from Apr 19, 2024

Conversation

matheusaaguiar
Copy link
Collaborator

fix #14946.

Copy link
Collaborator

@nikola-matic nikola-matic left a comment

Choose a reason for hiding this comment

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

Bugfixes need changlog entries :)

libyul/optimiser/Suite.cpp Outdated Show resolved Hide resolved
@matheusaaguiar
Copy link
Collaborator Author

I am wondering whether we should have a better error message for this case. Although the docs explain what should be an empty optimizer sequence, it can be a bit confusing. Or in other words, it is understandable mistake to think that an empty or blank string is the same as the empty sequence.

Copy link
Collaborator

@nikola-matic nikola-matic left a comment

Choose a reason for hiding this comment

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

Can you add CLI tests as well?

@matheusaaguiar matheusaaguiar force-pushed the fixEmptyStringYulOptimizationFlags branch from 75c147c to fce74bf Compare March 28, 2024 14:36
@ethereum ethereum deleted a comment from stackenbotten Mar 28, 2024
@ethereum ethereum deleted a comment from stackenbotten Mar 28, 2024
@matheusaaguiar matheusaaguiar force-pushed the fixEmptyStringYulOptimizationFlags branch 2 times, most recently from ae61ea6 to f966433 Compare April 2, 2024 20:04
@ethereum ethereum deleted a comment from stackenbotten Apr 2, 2024
@ethereum ethereum deleted a comment from stackenbotten Apr 2, 2024
@ethereum ethereum deleted a comment from stackenbotten Apr 2, 2024
@matheusaaguiar matheusaaguiar force-pushed the fixEmptyStringYulOptimizationFlags branch from f966433 to 831d5b9 Compare April 2, 2024 21:58
Copy link
Collaborator

@nikola-matic nikola-matic left a comment

Choose a reason for hiding this comment

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

Also, please add a short line to describe what an empty optimizer sequence is (:) here.

BOOST_CHECK_EXCEPTION(
parseCommandLineAndReadInputFiles({
"solc",
"--strict-assembly",
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
"--strict-assembly",

Copy link
Member

Choose a reason for hiding this comment

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

It would actually not hurt to test both as long as it can be done concisely, e.g. by looping over

{
    ["--strict-assembly", "--yul-optimizations="],
    ["--strict-assembly", "--yul-optimizations=    "],
    ["--yul-optimizations="],
    ["--yul-optimizations=    "],
}

which would be used to construct the command. Both assembling and compilation go through the same path in command-line parser now, but it's not guaranteed that it will always be like this and the issue affects both.

I'd say it's optional, but @nikola-matic has a point that currently you're assembling with input file called input.sol.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Actually, this should had been input.yul. I was testing using the example from the issue.
I will add the variations.

test/solc/CommandLineInterface.cpp Outdated Show resolved Hide resolved
libsolidity/interface/StandardCompiler.cpp Outdated Show resolved Hide resolved
libyul/optimiser/Suite.cpp Outdated Show resolved Hide resolved
libsolidity/interface/StandardCompiler.cpp Outdated Show resolved Hide resolved
libsolidity/interface/StandardCompiler.cpp Outdated Show resolved Hide resolved
BOOST_CHECK_EXCEPTION(
parseCommandLineAndReadInputFiles({
"solc",
"--strict-assembly",
Copy link
Member

Choose a reason for hiding this comment

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

It would actually not hurt to test both as long as it can be done concisely, e.g. by looping over

{
    ["--strict-assembly", "--yul-optimizations="],
    ["--strict-assembly", "--yul-optimizations=    "],
    ["--yul-optimizations="],
    ["--yul-optimizations=    "],
}

which would be used to construct the command. Both assembling and compilation go through the same path in command-line parser now, but it's not guaranteed that it will always be like this and the issue affects both.

I'd say it's optional, but @nikola-matic has a point that currently you're assembling with input file called input.sol.

@matheusaaguiar matheusaaguiar force-pushed the fixEmptyStringYulOptimizationFlags branch 3 times, most recently from 3a47bfa to c60dd99 Compare April 11, 2024 19:10
{
"C":
{
"metadata": "{\"compiler\":{\"version\":\"<VERSION REMOVED>\"},\"language\":\"Solidity\",\"output\":{\"abi\":[],\"devdoc\":{\"kind\":\"dev\",\"methods\":{},\"version\":1},\"userdoc\":{\"kind\":\"user\",\"methods\":{},\"version\":1}},\"settings\":{\"compilationTarget\":{\"A\":\"C\"},\"evmVersion\":\"cancun\",\"libraries\":{},\"metadata\":{\"bytecodeHash\":\"ipfs\"},\"optimizer\":{\"details\":{\"constantOptimizer\":false,\"cse\":false,\"deduplicate\":false,\"inliner\":false,\"jumpdestRemover\":true,\"orderLiterals\":false,\"peephole\":true,\"simpleCounterForLoopUncheckedIncrement\":true,\"yul\":false,\"yulDetails\":{\"optimizerSteps\":\":\"}},\"runs\":200},\"remappings\":[]},\"sources\":{\"A\":{\"keccak256\":\"0xb63d3c030f127aecaa7a1e223e41ef58ce5b4404939d397ccfd9ca0eb11d757b\",\"license\":\"GPL-3.0\",\"urls\":[\"bzz-raw://567242af52de5d6870167f16a7f46d7bf27fb2b101cf99fd9ab48c645dfe7ecd\",\"dweb:/ipfs/QmamT3HqCmEbVvWwQiYSfUZRn5XwHRRkEe29BpbEJadxDT\"]}},\"version\":1}"
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I noticed here that the metadata was not preserved. The optimizerSteps value is just the colon instead of a whitespace before it and two whitespaces after it.
The cause is

details["yulDetails"]["optimizerSteps"] = ":";

being defined if the sequence is the empty optimizer sequence, although we accept whitespaces and linebreaks.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I fixed that in a455829.

Copy link
Member

Choose a reason for hiding this comment

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

True. But changing it so that this is preserved also technically changes the metadata so I'd keep it out of this PR.

Like I said in #14967 (comment), this is fine to do, but I'd rather do any such changes explicitly, in a separate PR.

Also, I think that the right way to make it consistent is to be always stripping whitespace from the sequence, means we'd leave this bit as is and instead change the rest to match :)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Ok, I will separate this commit apart.

@matheusaaguiar matheusaaguiar force-pushed the fixEmptyStringYulOptimizationFlags branch from 458c093 to d29d7eb Compare April 15, 2024 13:39
Copy link
Member

@cameel cameel left a comment

Choose a reason for hiding this comment

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

The only thing that still needs to be addressed is #14967 (comment). Other than that there are no big problems and I pushed some fixups to clean up some of the smaller ones without going through extra review rounds.

@matheusaaguiar matheusaaguiar force-pushed the fixEmptyStringYulOptimizationFlags branch from ac9bf2e to b1797fc Compare April 15, 2024 20:13
@matheusaaguiar
Copy link
Collaborator Author

Rebased and squashed commits.

cameel
cameel previously approved these changes Apr 15, 2024
@nikola-matic
Copy link
Collaborator

Also, please add a short line to describe what an empty optimizer sequence is (:) here.

Push docs and I'll re-approve so we can merge.

@matheusaaguiar
Copy link
Collaborator Author

Also, please add a short line to describe what an empty optimizer sequence is (:) here.

Push docs and I'll re-approve so we can merge.

Sorry, I missed that when checking pending comments. Fixed.

@matheusaaguiar matheusaaguiar force-pushed the fixEmptyStringYulOptimizationFlags branch 2 times, most recently from 929204f to dd6e098 Compare April 17, 2024 02:58
cameel
cameel previously approved these changes Apr 17, 2024
@nikola-matic nikola-matic merged commit 2e8cd3f into develop Apr 19, 2024
73 checks passed
@nikola-matic nikola-matic deleted the fixEmptyStringYulOptimizationFlags branch April 19, 2024 15:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Development

Successfully merging this pull request may close these issues.

Providing an empty string to --yul-optimizations without enabling yul optimization triggers uncaught exception
4 participants