-
Notifications
You must be signed in to change notification settings - Fork 42
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
test(CALL): zero size, huge return at offset, huge call data offset, huge return data offset #1448
Closed
lorenzogentile404
wants to merge
20
commits into
arith-dev
from
1444-failing-tests-for-testmxprandomadvanced
Closed
Changes from 9 commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
d5a44f3
test(mxp): add testMxpRandomAdvancedWithFixedSeed
lorenzogentile404 6f4a136
fix(mxp): filter out RETURN and REVERT when testing against large off…
lorenzogentile404 0fd68d2
fix(mxp): revert wrong fix
lorenzogentile404 1f3d4ca
test(mxp): add print
lorenzogentile404 cab035d
test(mxp): add failing tests for debugging purposes
lorenzogentile404 8833f5a
fix: OperationAncillaries outputDataSpan
lorenzogentile404 bc80f91
test: add docs
lorenzogentile404 f3a9d26
fix: returnDataRequestedSegment
lorenzogentile404 65b48a8
fix(operationAncillaries): return at offset and return at capacity
lorenzogentile404 cb1ace9
Merge branch 'arith-dev' into 1444-failing-tests-for-testmxprandomadv…
OlivierBBB 1bc1a35
typo
lorenzogentile404 f84f1fe
Merge branch 'arith-dev' into 1444-failing-tests-for-testmxprandomadv…
OlivierBBB ce175a0
Merge branch 'arith-dev' into 1444-failing-tests-for-testmxprandomadv…
lorenzogentile404 0e02378
Merge branch 'arith-dev' into 1444-failing-tests-for-testmxprandomadv…
letypequividelespoubelles 1770b48
Merge branch 'arith-dev' into 1444-failing-tests-for-testmxprandomadv…
lorenzogentile404 c7f3bec
Merge branch 'arith-dev' into 1444-failing-tests-for-testmxprandomadv…
lorenzogentile404 3a67df5
docs: remove useless comment
lorenzogentile404 3089801
Merge branch 'arith-dev' into 1444-failing-tests-for-testmxprandomadv…
lorenzogentile404 d9f9e3b
Merge branch 'arith-dev' into 1444-failing-tests-for-testmxprandomadv…
lorenzogentile404 596b990
Merge branch 'arith-dev' into 1444-failing-tests-for-testmxprandomadv…
lorenzogentile404 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,6 +19,7 @@ | |
import static net.consensys.linea.zktracer.module.UtilCalculator.allButOneSixtyFourth; | ||
import static net.consensys.linea.zktracer.types.AddressUtils.isPrecompile; | ||
|
||
import com.google.common.base.Preconditions; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import net.consensys.linea.zktracer.module.constants.GlobalConstants; | ||
|
@@ -164,14 +165,36 @@ public static Bytes initCode(final MessageFrame frame) { | |
public static MemorySpan returnDataRequestedSegment(final MessageFrame frame) { | ||
switch (OpCode.of(frame.getCurrentOperation().getOpcode())) { | ||
case CALL, CALLCODE -> { | ||
long offset = Words.clampedToLong(frame.getStackItem(5)); | ||
long length = Words.clampedToLong(frame.getStackItem(6)); | ||
return MemorySpan.fromStartLength(offset, length); | ||
long callDataOffset = Words.clampedToLong(frame.getStackItem(3)); | ||
long callDataSize = Words.clampedToLong(frame.getStackItem(4)); | ||
long returnAtOffset = Words.clampedToLong(frame.getStackItem(5)); | ||
long returnAtCapacity = Words.clampedToLong(frame.getStackItem(6)); | ||
|
||
Preconditions.checkArgument(!(callDataOffset >= Math.pow(2, 32) && callDataSize == 0)); | ||
Preconditions.checkArgument(!(returnAtOffset >= Math.pow(2, 32) && returnAtCapacity == 0)); | ||
|
||
System.out.println("callDataOffset: " + callDataOffset); | ||
System.out.println("callDataSize: " + callDataSize); | ||
System.out.println("returnAtOffset: " + returnAtOffset); | ||
System.out.println("returnAtCapacity: " + returnAtCapacity); | ||
|
||
return MemorySpan.fromStartLength(returnAtOffset, returnAtCapacity); | ||
} | ||
case DELEGATECALL, STATICCALL -> { | ||
long offset = Words.clampedToLong(frame.getStackItem(4)); | ||
long length = Words.clampedToLong(frame.getStackItem(5)); | ||
return MemorySpan.fromStartLength(offset, length); | ||
long callDataOffset = Words.clampedToLong(frame.getStackItem(2)); | ||
long callDataSize = Words.clampedToLong(frame.getStackItem(3)); | ||
long returnAtOffset = Words.clampedToLong(frame.getStackItem(4)); | ||
long returnAtCapacity = Words.clampedToLong(frame.getStackItem(5)); | ||
|
||
System.out.println("callDataOffset: " + callDataOffset); | ||
System.out.println("callDataSize: " + callDataSize); | ||
System.out.println("returnAtOffset: " + returnAtOffset); | ||
System.out.println("returnDataSize: " + returnAtCapacity); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same |
||
|
||
Preconditions.checkArgument(!(callDataOffset >= Math.pow(2, 32) && callDataSize == 0)); | ||
Preconditions.checkArgument(!(returnAtOffset >= Math.pow(2, 32) && returnAtCapacity == 0)); | ||
|
||
return MemorySpan.fromStartLength(returnAtOffset, returnAtCapacity); | ||
} | ||
default -> throw new IllegalArgumentException( | ||
"returnDataRequestedSegment called outside of a *CALL"); | ||
|
@@ -221,7 +244,7 @@ public static MemorySpan outputDataSpan(final MessageFrame frame) { | |
// We cannot use this method for that purpose. | ||
case CALL, CALLCODE, DELEGATECALL, STATICCALL -> { | ||
Address target = Words.toAddress(frame.getStackItem(1)); | ||
if (isPrecompile(target)) { | ||
if (!isPrecompile(target)) { | ||
return MemorySpan.fromStartLength(0, 0); | ||
} | ||
checkArgument(isPrecompile(target)); // useless (?) sanity check | ||
|
108 changes: 108 additions & 0 deletions
108
...c/test/java/net/consensys/linea/zktracer/module/hub/ZeroSizeCallDataOrReturnDataTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
/* | ||
* Copyright ConsenSys Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on | ||
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations under the License. | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package net.consensys.linea.zktracer.module.hub; | ||
|
||
import java.util.List; | ||
|
||
import net.consensys.linea.testing.BytecodeCompiler; | ||
import net.consensys.linea.testing.BytecodeRunner; | ||
import net.consensys.linea.testing.ToyAccount; | ||
import net.consensys.linea.zktracer.opcode.OpCode; | ||
import org.hyperledger.besu.datatypes.Address; | ||
import org.hyperledger.besu.datatypes.Wei; | ||
import org.junit.jupiter.api.Test; | ||
|
||
public class ZeroSizeCallDataOrReturnDataTest { | ||
|
||
@Test | ||
void zeroSizeHugeReturnAtOffsetTest() { | ||
BytecodeCompiler program = BytecodeCompiler.newProgram(); | ||
program | ||
.push(0) // return at capacity | ||
.push("ff".repeat(32)) // return at offset | ||
.push(0) // call data size | ||
.push(0) // call data offset | ||
.push("ca11ee") // address | ||
.push(1000) // gas | ||
.op(OpCode.STATICCALL); | ||
|
||
BytecodeCompiler calleeProgram = BytecodeCompiler.newProgram(); | ||
calleeProgram.op(OpCode.CALLDATASIZE); | ||
|
||
final ToyAccount calleeAccount = | ||
ToyAccount.builder() | ||
.balance(Wei.fromEth(1)) | ||
.nonce(10) | ||
.address(Address.fromHexString("ca11ee")) | ||
.code(calleeProgram.compile()) | ||
.build(); | ||
|
||
BytecodeRunner.of(program.compile()).run(Wei.fromEth(1), 30000L, List.of(calleeAccount)); | ||
// TODO: this test is supposed to fail as the ones below, but it does not. Understand why | ||
} | ||
|
||
@Test | ||
void zeroSizeHugeCallDataOffsetTest() { | ||
BytecodeCompiler program = BytecodeCompiler.newProgram(); | ||
program | ||
.push(0) // return at capacity | ||
.push(0) // return at offset | ||
.push(0) // call data size | ||
.push("ff".repeat(32)) // call data offset | ||
.push("ca11ee") // address | ||
.push(1000) // gas | ||
.op(OpCode.STATICCALL); | ||
|
||
BytecodeCompiler calleeProgram = BytecodeCompiler.newProgram(); | ||
calleeProgram.op(OpCode.CALLDATASIZE); | ||
|
||
final ToyAccount calleeAccount = | ||
ToyAccount.builder() | ||
.balance(Wei.fromEth(1)) | ||
.nonce(10) | ||
.address(Address.fromHexString("ca11ee")) | ||
.code(calleeProgram.compile()) | ||
.build(); | ||
|
||
BytecodeRunner.of(program.compile()).run(Wei.fromEth(1), 30000L, List.of(calleeAccount)); | ||
} | ||
|
||
@Test | ||
void zeroSizeHugeReturnDataOffsetTest() { | ||
BytecodeCompiler program = BytecodeCompiler.newProgram(); | ||
program | ||
.push(0) // return at capacity | ||
.push(0) // return at offset | ||
.push(0) // call data size | ||
.push(0) // call data offset | ||
.push("ca11ee") // address | ||
.push(1000) // gas | ||
.op(OpCode.STATICCALL); | ||
|
||
BytecodeCompiler calleeProgram = BytecodeCompiler.newProgram(); | ||
calleeProgram.push(0).push("ff".repeat(32)).op(OpCode.RETURN); | ||
|
||
final ToyAccount calleeAccount = | ||
ToyAccount.builder() | ||
.balance(Wei.fromEth(1)) | ||
.nonce(10) | ||
.address(Address.fromHexString("ca11ee")) | ||
.code(calleeProgram.compile()) | ||
.build(); | ||
|
||
BytecodeRunner.of(program.compile()).run(Wei.fromEth(1), 30000L, List.of(calleeAccount)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This doesn't explain the HUB tracing not blowing up 🤔.