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

Bug fix for large binary with unlink libraries codegen #2016

Merged
merged 5 commits into from
Mar 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,7 @@ private FieldSpec createLibrariesLinkedBinaryField() {
.build();
}

private FieldSpec createBinaryDefinition(String binary) {
FieldSpec createBinaryDefinition(String binary) {
if (binary.length() < 65534) {
return FieldSpec.builder(String.class, BINARY)
.addModifiers(Modifier.PUBLIC, Modifier.FINAL, Modifier.STATIC)
Expand All @@ -407,7 +407,8 @@ private FieldSpec createBinaryDefinition(String binary) {
StringBuilder stringBuilderString = new StringBuilder().append("new StringBuilder()");
for (String s : argsArray) {
stringBuilderString.append(".append(\"");
stringBuilderString.append(s);
stringBuilderString.append(
s.replaceAll("\\$", "\\$\\$")); // escape $ which bytecode may contain
stringBuilderString.append("\")");
}
stringBuilderString.append(".toString()");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -983,4 +983,13 @@ public void testBuildFunctionLinkBinaryWithReferences() throws Exception {

assertEquals(methodSpec.toString(), (expected));
}

@Test
public void testBinaryWithUnlinkedLibraryLengthOver65534() throws Exception {
solidityFunctionWrapper.createBinaryDefinition(
"0x"
+ "a".repeat(40000)
+ "__$927c5a12e2f339676f56d42ec1c0537964$__"
+ "a".repeat(40000));
}
}
Loading