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

Support bytes concat #14685

Merged
merged 1 commit into from Jan 24, 2024
Merged

Support bytes concat #14685

merged 1 commit into from Jan 24, 2024

Conversation

pgebal
Copy link
Collaborator

@pgebal pgebal commented Nov 17, 2023

Closes #11997

@pgebal pgebal force-pushed the pgebal/bytes_concat branch 3 times, most recently from 4a80492 to effab73 Compare November 17, 2023 14:13
@cameel cameel added the smt label Nov 19, 2023
@pgebal pgebal force-pushed the pgebal/bytes_concat branch 7 times, most recently from be52960 to 9e713cb Compare November 22, 2023 17:28
@pgebal pgebal force-pushed the pgebal/bytes_concat branch 3 times, most recently from f5270cd to 4528fcc Compare November 28, 2023 10:58
@@ -28,7 +28,7 @@ contract C
}
function g(uint x) public {
require(x < severalMaps.length);
f(severalMaps[x]);
f(severalMaps[x]); //should hold
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This shouldn't be reported. I don't know how to fix it.

@pgebal pgebal force-pushed the pgebal/bytes_concat branch 5 times, most recently from 6cd0cc1 to ba2959e Compare November 29, 2023 11:40
// ----
// Warning 6328: (242-256): CHC: Assertion violation happens here.\nCounterexample:\na = [[], [], [0, 0, 0, 0]]\ny = 0\n\nTransaction trace:\nC.constructor()\nState: a = [[], [], [0, 0, 0, 0]]\nC.f()
// Warning 6328: (242-256): CHC: Assertion violation happens here.
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 don't know why no counterexample here

@pgebal pgebal marked this pull request as ready for review November 29, 2023 12:29
@pgebal
Copy link
Collaborator Author

pgebal commented Nov 30, 2023

Explanation on 1 argument bytes.concat call:

  1. If the argument is of type bytes memory: bytes.concat call is defined as value of the argument.
  2. If the argument is of other type: fixed bytes, etc, bytes.concat is defined as a function (just as 2+ arguments calls)

Maybe it could be done differently, but I would have to cast values of types fixed bytes, string literals to values of type bytes memory

@r0qs
Copy link
Member

r0qs commented Nov 30, 2023

Explanation on 1 argument bytes.concat call:

1. If the argument is of type `bytes memory`: `bytes.concat` call is defined as value of the argument.

2. If the argument is of other type: fixed bytes, etc, `bytes.concat` is defined as a function (just as 2+ arguments calls)

Maybe it could be done differently, but I would have to cast values of types fixed bytes, string literals to values of type bytes memory

Hey @pgebal the two tests failing seems to be due to out of memory in the CI jobs: https://app.circleci.com/pipelines/github/ethereum/solidity/31908/workflows/a54b0a16-fb08-4f77-989d-13a1bebba3b2/jobs/1425767/resources. If there is no memory leak in the current implementation, and the memory increase is expected, you may need to increase the resource_class of the job, which, by the way, is already using a large image, i.e. base_ubuntu2204_large.

@pgebal
Copy link
Collaborator Author

pgebal commented Dec 1, 2023

@r0qs Thanks, I noticed that too. I am not sure about the memory increase caused by my changes. I asked @leonardoalt to have a look on this code. Maybe he can find something suspicious here. If Leo thinks it seems right I'll increase resource class to see if that helps.

libsolidity/formal/SMTEncoder.cpp Outdated Show resolved Hide resolved
libsolidity/formal/SMTEncoder.cpp Outdated Show resolved Hide resolved
@pgebal pgebal force-pushed the pgebal/bytes_concat branch 2 times, most recently from 691a920 to e21eab9 Compare December 4, 2023 11:33
@pgebal pgebal force-pushed the pgebal/bytes_concat branch 16 times, most recently from f535a42 to 0992050 Compare January 18, 2024 09:26
Copy link
Contributor

@blishko blishko left a comment

Choose a reason for hiding this comment

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

I think this looks good!

Left just a few small comments, but I think this should be soon good to go!

Also, it looks like this PR needs rebase.

libsolidity/formal/CHC.cpp Outdated Show resolved Hide resolved
libsolidity/formal/CHC.h Outdated Show resolved Hide resolved
libsolidity/formal/Predicate.cpp Outdated Show resolved Hide resolved
@@ -381,7 +384,7 @@ std::vector<std::optional<std::string>> Predicate::summaryPostInputValues(std::v

auto const& inParams = function->parameters();

auto first = _args.begin() + 6 + static_cast<int>(stateVars->size()) * 2 + static_cast<int>(inParams.size()) + 1;
auto first = _args.begin() + (long)firstArgIndex() + static_cast<int>(stateVars->size()) * 2 + static_cast<int>(inParams.size()) + 1;
Copy link
Contributor

Choose a reason for hiding this comment

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

Why do you need to cast to long?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

because return type of firstArgIndex() is size_t (which seemed to me it makes most sense)
and operator + for iterator takes long as an argument

Copy link
Contributor

Choose a reason for hiding this comment

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

Since the other offsets use static_cast<int> maybe we should at least be consistent with that?
In general, we should prefer static_cast from C++ to C-style casts.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Right! It's being used in the same line and I didn't notice it!

libsolidity/formal/Predicate.h Outdated Show resolved Hide resolved
@pgebal pgebal force-pushed the pgebal/bytes_concat branch 3 times, most recently from da5b178 to 4585079 Compare January 23, 2024 14:04
blishko
blishko previously approved these changes Jan 23, 2024
Copy link
Contributor

@blishko blishko left a comment

Choose a reason for hiding this comment

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

LGTM!

@blishko
Copy link
Contributor

blishko commented Jan 23, 2024

@pgebal You have to update test expectations for the test where you changed the indentation.
Also you can now update the main description of the PR again, since the test is no longer deleted.

@pgebal pgebal merged commit ce98680 into ethereum:develop Jan 24, 2024
65 checks passed
Ruko97 pushed a commit to Ruko97/solidity that referenced this pull request Apr 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[SMTChecker] Support bytes concat
5 participants