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

Mega precompile testing PR: SHA2-256, RIPEMD-160, IDENTITY, MODEXP, ECADD, ECMUL, ECRECOVER, ECPAIRING #1778

Open
wants to merge 64 commits into
base: arith-dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
64 commits
Select commit Hold shift + click to select a range
fe12daa
release: bump version to beta-v1.2.0-rc2 and update changelog
OlivierBBB Jan 24, 2025
f019281
Merge branch 'arith-dev' into rel/beta-v1.2.0-rc2
OlivierBBB Jan 24, 2025
4dac4bc
feat: "Happy Path" tests for SHA2/RIPE/ID
OlivierBBB Feb 5, 2025
00ba52e
fix: constraints commit update
OlivierBBB Feb 5, 2025
4e2b485
ras: documentation
OlivierBBB Feb 5, 2025
9b3a5b4
ras: documentation
OlivierBBB Feb 5, 2025
5810b58
ras: renaming + documentation
OlivierBBB Feb 5, 2025
a685284
feat: the happy path tests now do more
OlivierBBB Feb 6, 2025
d256b86
ras: refactoring
OlivierBBB Feb 6, 2025
3917817
ras
OlivierBBB Feb 6, 2025
5668fc8
ras
OlivierBBB Feb 6, 2025
91aaaf8
ras
OlivierBBB Feb 6, 2025
f2a2f56
feat: some refactoring
OlivierBBB Feb 6, 2025
20d540a
Merge branch 'arith-dev' into PRC-testing---SHA2-RIPEMD-IDENTITY
OlivierBBB Feb 6, 2025
72a03dc
ras: moved parameter generation + CONTRACT_DEPLOYMENT version of tests
OlivierBBB Feb 9, 2025
0250263
Merge branch 'arith-dev' into PRC-testing---SHA2-RIPEMD-IDENTITY
OlivierBBB Feb 9, 2025
2969e20
feat: more tests
OlivierBBB Feb 10, 2025
605fb38
feat: extracted methods for running code by different means
OlivierBBB Feb 11, 2025
93ea5da
ras
OlivierBBB Feb 11, 2025
2ccdfbc
ras: some refactoring and method extraction
OlivierBBB Feb 11, 2025
2a71485
ras
OlivierBBB Feb 11, 2025
794ae98
feat: MODEXP parameter generation wip
OlivierBBB Feb 11, 2025
2bb41d7
feat: more MODEXP wip
OlivierBBB Feb 11, 2025
3e393b3
spotless
OlivierBBB Feb 11, 2025
24705ce
ras: get tests to run
OlivierBBB Feb 12, 2025
1b5d222
ras: documentation + single parameter test for MODEXP
OlivierBBB Feb 12, 2025
388c1f3
fix: type error in ModexpLeadOobCall
OlivierBBB Feb 12, 2025
6afdd65
fix: remove obsolete columns from RomLex
OlivierBBB Feb 12, 2025
9544035
feat: more wip on MODEXP testing
OlivierBBB Feb 12, 2025
7d75071
constraints commit update
OlivierBBB Feb 12, 2025
4473021
feat: @amkCha's gradle dependency fix
OlivierBBB Feb 12, 2025
a0db68a
ras: more wip
OlivierBBB Feb 12, 2025
5dfec53
ras
OlivierBBB Feb 13, 2025
d8cd30b
feat: exact cost of MODEXP
OlivierBBB Feb 13, 2025
ad253f4
ras: refactoring
OlivierBBB Feb 13, 2025
e458e86
ras
OlivierBBB Feb 13, 2025
707e4cc
feat: ECADD tests
OlivierBBB Feb 13, 2025
e021a44
feat: fixed typo in sstore method
OlivierBBB Feb 14, 2025
f8d6730
feat: the remaining ECADD tests
OlivierBBB Feb 14, 2025
b3a72be
spotless
OlivierBBB Feb 14, 2025
f2742bc
Merge branch 'arith-dev' into PRC-testing---SHA2-RIPEMD-IDENTITY
OlivierBBB Feb 14, 2025
291dcd3
wip: ECMUL tests
OlivierBBB Feb 14, 2025
7c877ad
wip: ECRECOVER
OlivierBBB Feb 17, 2025
0fcc291
feat: progress on ECRECOVER
OlivierBBB Feb 18, 2025
8fc22c1
feat: ECRECOVER tests
OlivierBBB Feb 19, 2025
22fda24
Merge branch 'arith-dev' into PRC-testing---SHA2-RIPEMD-IDENTITY
OlivierBBB Feb 19, 2025
672d7ab
Generic precompile testing methods (#1837)
OlivierBBB Feb 20, 2025
bcb4a71
merge arith-dev
OlivierBBB Feb 20, 2025
0f3ec3b
ras
OlivierBBB Feb 22, 2025
52d7d17
feat: ECPAIRING wip
OlivierBBB Feb 22, 2025
85bb5a5
Merge branch 'arith-dev' into PRC-testing---SHA2-RIPEMD-IDENTITY
OlivierBBB Feb 22, 2025
106f77f
spotless
OlivierBBB Feb 22, 2025
49672e4
feat: ECPAIRING wip
OlivierBBB Feb 22, 2025
d1cb762
wip ECPAIRING
OlivierBBB Feb 22, 2025
da4f47c
feat: the PLENTY GasParameter now only provides GAS/2
OlivierBBB Feb 22, 2025
3411658
wip ECPAIRING
OlivierBBB Feb 22, 2025
4a0f413
wip ECPAIRING (nearly there)
OlivierBBB Feb 22, 2025
ae62778
spotless
OlivierBBB Feb 22, 2025
ed74390
ECPAIRING ok + various
OlivierBBB Feb 22, 2025
a4f5162
feat: fewer test cases
OlivierBBB Feb 22, 2025
b84cb3d
ras
OlivierBBB Feb 22, 2025
41513c0
constraints commit update
OlivierBBB Feb 22, 2025
6a43edf
constraints commit update (again)
OlivierBBB Feb 22, 2025
48d5dbc
feat: disable ECPAIRING tests + reduce GOMEMLIMIT
OlivierBBB Feb 24, 2025
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
2 changes: 1 addition & 1 deletion .github/workflows/gradle-weekly-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ jobs:
go-corset: true

- name: Run Weekly tests
run: GOMEMLIMIT=96GiB ./gradlew weeklyTests
run: GOMEMLIMIT=20GiB ./gradlew weeklyTests
env:
JAVA_OPTS: -Dorg.gradle.daemon=false
WEEKLY_TESTS_PARALLELISM: 4
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public static void appendInsufficientBalanceCall(
.push(rao)
.push(cds)
.push(cdo)
.op(BALANCE)
.op(SELFBALANCE)
.push(1)
.op(ADD) // puts balance + 1 on the stack
.push(to)
Expand Down Expand Up @@ -128,6 +128,91 @@ public static void validEcrecoverData(BytecodeCompiler program) {
.op(MSTORE);
}

public static void fullReturnDataCopyAt(BytecodeCompiler program, int targetOffset) {
program.op(RETURNDATASIZE).push(0).push(targetOffset);
}

/**
* Copies <b>1 / 2</b> of the return data starting at offset <b>RDS / 3</b> (internal to return
* data) into memory at targetOffset.
*
* @param program
* @param targetOffset
*/
public static void copyHalfOfReturnDataOmittingTheFirstThirdOfIt(
BytecodeCompiler program, int targetOffset) {
pushRdsOverArgOntoTheStack(program, 2); // source size ≡ rds/2
pushRdsOverArgOntoTheStack(program, 3); // source offset ≡ rds/3
program.push(targetOffset);
}

/**
* Loads the (right 0 padded) first <b>RDS ∧ 32</b> bytes from return data onto the stack.
*
* <p><b>Note.</b> if <b>RDS < 32</b>.
*
* @param program
* @param offset
*/
public static void loadFirstReturnDataWordOntoStack(BytecodeCompiler program, int offset) {
squashMemoryWordAtOffset(program, offset);
pushMinOfRdsAnd32OntoStack(program); // leaves min(RDS, 32) on the stack
program.push(0).push(offset).op(RETURNDATACOPY).push(offset).op(MLOAD);
}

/**
* Pushes the integer <b>RDS ∧ 32 = min(RDS, 32)</b> onto the stack.
*
* @param program
*/
public static void pushMinOfRdsAnd32OntoStack(BytecodeCompiler program) {
program
.push(WORD_SIZE)
.op(RETURNDATASIZE)
.op(LT) // stack: | ... | c ], where c ≡ [RDS < 32]
.op(DUP1)
.push(1)
.op(SUB) // stack: | ... | c | d ], where d ≡ ¬c ≡ [RDS ≥ 32]
.push(WORD_SIZE)
.op(MUL) // stack: | ... | c | (d ? 32 : 0) ]
.op(SWAP1) // stack: | ... | (d ? 32 : 0) | c ]
.op(RETURNDATASIZE)
.op(MUL) // stack: | ... | (d ? 32 : 0) | (c ? RDS : 0) ]
.op(ADD) // stack: | ... | min(RDS, 32) ]
;
}

/**
* Squashes the word in memory at (byte)<b>offset</b>, i.e. replaces it with <b>0x 00 .. 00</b>.
*
* @param program
* @param offset
*/
public static void squashMemoryWordAtOffset(BytecodeCompiler program, int offset) {
program.push(0).push(offset).op(MSTORE);
}

/**
* Pushes <b>RDS / arg</b> onto the stack.
*
* @param program
* @param arg
*/
public static void pushRdsOverArgOntoTheStack(BytecodeCompiler program, int arg) {
program.push(arg).op(RETURNDATASIZE).op(DIV);
}

/**
* Populates memory with 6 words of data, namely
*
* <p><b>0x aa ... aa bb ... bb cc ... cc dd ... dd ee ... ee ff ... ff</b>
*
* <p>starting at offset 0. This provides 192 = 6*32 nonzero bytes in RAM.
*/
public static void populateMemory(BytecodeCompiler program) {
populateMemory(program, 6, 0);
}

/**
* {@link #populateMemory} populates memory with <b>nWords</b> chosen cyclically from the set of 6
* EVM words obtained by repeating the strings <b>aa</b>, <b>bb</b>, ..., <b>ff</b> 32 times.
Expand All @@ -144,4 +229,79 @@ public static void populateMemory(BytecodeCompiler program, int nWords, int offs
.op(MSTORE);
}
}

/**
* Appends byte code to the {@code program} that loads the first word of call data onto the stack
* and interprets it as an address like so:
*
* <p><b>[address | xx ... xx]</b>
*
* <p>It then calls into this address.
*
* @param program
* @param callOpCode
*/
public static void appendCallTo(BytecodeCompiler program, OpCode callOpCode, Address address) {
checkArgument(callOpCode.isCall());

pushSeveral(program, 0, 0, 0, 0);
if (callOpCode.callHasValueArgument()) {
program.push(256); // value
}
program.push(address).op(GAS).op(callOpCode);
}

/**
* Performs a full copy of the code at {@code foreignAddress} and runs it as initialization code.
*
* @param program
* @param foreignAddress
*/
public static void copyForeignCodeAndRunItAsInitCode(
BytecodeCompiler program, Address foreignAddress) {

program.push(foreignAddress).op(EXTCODESIZE); // ] EXTCS ]
pushSeveral(program, 0, 0);
program.push(foreignAddress); // ] EXTCS | 0 | 0 | foreignAddress ]
program.op(EXTCODECOPY);
program.op(MSIZE);
pushSeveral(program, 0, 0); // ] MSIZE | 0 | 0 ]
program.op(CREATE);
}

/**
* <b>EXTCODECOPY</b>'s all of {@code foreignAddress}'s byte code and returns it.
*
* @param program
* @param foreignAddress
*/
public static void copyForeignCodeAndReturnIt(BytecodeCompiler program, Address foreignAddress) {
copyForeignCodeToRam(program, foreignAddress);
program.op(MSIZE).push(0).op(RETURN); // return memory in full
}

public static void copyForeignCodeToRam(BytecodeCompiler program, Address foreignAddress) {
program.push(foreignAddress).op(EXTCODESIZE); // ] EXTCS ]
pushSeveral(program, 0, 0);
program.push(foreignAddress); // ] EXTCS | 0 | 0 | foreignAddress ]
program.op(EXTCODECOPY); // full copy of foreign code
}

public static void sstoreTopOfStackTo(BytecodeCompiler program, int storageKey) {
program.push(storageKey).op(SSTORE);
}

public static void sloadFrom(BytecodeCompiler program, int storageKey) {
program.push(storageKey).op(SLOAD);
}

public static void revertWith(BytecodeCompiler program, int offset, int size) {
program.push(size).push(offset).op(REVERT);
}

public static void pushSeveral(BytecodeCompiler program, int... values) {
for (int value : values) {
program.push(value);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*
* Copyright Consensys Software 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.instructionprocessing.callTests.prc;

public enum CallOffset {
ALIGNED,
MISALIGNED,
INFINITY
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*
* Copyright Consensys Software 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.instructionprocessing.callTests.prc;

public enum CallSize {
ZERO,
WORD,
OTHER
}
Loading
Loading