Skip to content

Commit 16adf96

Browse files
doc: add error messages (#2365)
Signed-off-by: F Bojarski <[email protected]> Co-authored-by: Olivier Bégassat <[email protected]> Co-authored-by: Olivier Bégassat <[email protected]>
1 parent a792088 commit 16adf96

File tree

75 files changed

+587
-231
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

75 files changed

+587
-231
lines changed

arithmetization/src/main/java/net/consensys/linea/zktracer/bytestheta/BytesArray.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ public MutableBytes get(int index) {
9292
* @param bytes the new Bytes value
9393
*/
9494
public void set(int index, Bytes bytes) {
95-
checkArgument(bytes.size() == 8);
95+
checkArgument(bytes.size() == 8, "bytes size must be 8");
9696
bytesArray[index] = MutableBytes.wrap(bytes.toArray());
9797
}
9898

arithmetization/src/main/java/net/consensys/linea/zktracer/container/module/CountingOnlyModule.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,8 @@ public int spillage(Trace trace) {
6565
}
6666

6767
public void updateTally(final int count) {
68-
Preconditions.checkArgument(count >= 0, "Must be non-negative");
68+
Preconditions.checkArgument(
69+
count >= 0, "CountingOnlyModule: count %s in updateTally must be nonnegative", count);
6970
counts.add(count);
7071
}
7172

arithmetization/src/main/java/net/consensys/linea/zktracer/container/module/IncrementingModule.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ public IncrementingModule(ModuleName moduleKey) {
2929
public void updateTally(final int numberEffectiveCall) {
3030
checkArgument(
3131
numberEffectiveCall == 0 || numberEffectiveCall == 1,
32-
"Can only update the tally by one at the time.");
32+
"IncrementingModule: updateTally can only update the tally by 0 or 1, here it's by %s",
33+
numberEffectiveCall);
3334
counts.add(numberEffectiveCall);
3435
}
3536

arithmetization/src/main/java/net/consensys/linea/zktracer/container/stacked/CountOnlyOperation.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ public void popTransactionBundle() {
3737
}
3838

3939
public void add(final int operationCount) {
40-
Preconditions.checkArgument(operationCount >= 0, "operationCount must be non negative");
40+
Preconditions.checkArgument(
41+
operationCount >= 0, "operationCount %s should be nonnegative", operationCount);
4142
countInTransactionBundle += operationCount;
4243
}
4344

arithmetization/src/main/java/net/consensys/linea/zktracer/module/Util.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ public static boolean isUInt256(BigInteger number) {
117117
* @return The UInt256 sum of the products of the elements in the two input ranges.
118118
*/
119119
public static UInt256 multiplyRange(Bytes[] range1, Bytes[] range2) {
120-
checkArgument(range1.length == range2.length);
120+
checkArgument(range1.length == range2.length, "Ranges must be of the same length");
121121
UInt256 sum = UInt256.ZERO;
122122
for (int i = 0; i < range1.length; i++) {
123123
UInt256 prod =

arithmetization/src/main/java/net/consensys/linea/zktracer/module/blockdata/moduleOperation/BlockdataOperation.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -262,8 +262,8 @@ public void trace(Trace.Blockdata trace) {
262262

263263
// Module call macros
264264
private boolean wcpCallTo(int w, EWord arg1, EWord arg2, int inst) {
265-
checkArgument(arg1.bitLength() / 8 <= 32);
266-
checkArgument(arg2.bitLength() / 8 <= 32);
265+
checkArgument(arg1.bitLength() / 8 <= 32, "WCP: arg1 bit width too large");
266+
checkArgument(arg2.bitLength() / 8 <= 32, "WCP: arg2 bit width too large");
267267

268268
this.arg1[w] = arg1;
269269
this.arg2[w] = arg2;

arithmetization/src/main/java/net/consensys/linea/zktracer/module/blsdata/BlsDataOperation.java

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,10 @@ private BlsDataOperation(
129129
Bytes callData,
130130
Bytes returnData,
131131
boolean successBit) {
132-
checkArgument(precompileFlag.isBlsPrecompile(), "invalid BLS type");
132+
checkArgument(
133+
precompileFlag.isBlsPrecompile(),
134+
"BlsDataOperation: precompile %s isn't of BLS type",
135+
precompileFlag);
133136

134137
this.precompileFlag = precompileFlag;
135138
this.callData = callData;
@@ -162,8 +165,12 @@ private BlsDataOperation(
162165
// Set successBit
163166
this.successBit = successBit;
164167
final int returnDataSize = returnData.toArray().length;
168+
final int expectedReturnDataSize = (successBit ? expectedReturnDataSize(precompileFlag) : 0);
165169
Preconditions.checkArgument(
166-
returnDataSize == (successBit ? expectedReturnDataSize(precompileFlag) : 0));
170+
returnDataSize == expectedReturnDataSize,
171+
"BLS precompile return data size %s does not agree with the expected value %s",
172+
returnDataSize,
173+
expectedReturnDataSize);
167174
}
168175

169176
public static int expectedReturnDataSize(
@@ -250,7 +257,8 @@ private void handleBlsG1Add() {
250257
final boolean isSmallPointOnCurve =
251258
isSmallPointOnCurve(indexOffset, callData.slice(sizeOffset, SIZE_SMALL_POINT));
252259
final boolean mextBit = wellFormedCoordinate && !isSmallPointOnCurve;
253-
Preconditions.checkArgument(mextBit == (wellFormedCoordinate && !successBit));
260+
Preconditions.checkArgument(
261+
mextBit == (wellFormedCoordinate && !successBit), "BLS_G1ADD: mext bit inconsistency");
254262

255263
if (mextBit && !mextBitIsSet) {
256264
for (int j = 0; j <= CT_MAX_SMALL_POINT; j++) {
@@ -277,7 +285,8 @@ private void handleBlsG1Msm() {
277285
final boolean isSmallPointInSubgroup =
278286
isSmallPointInSubGroup(indexOffset, callData.slice(sizeOffset, SIZE_SMALL_POINT));
279287
final boolean mextBit = wellFormedCoordinate && !isSmallPointInSubgroup;
280-
Preconditions.checkArgument(mextBit == (wellFormedCoordinate && !successBit));
288+
Preconditions.checkArgument(
289+
mextBit == (wellFormedCoordinate && !successBit), "BLS_G1MSM: mext bit inconsistency");
281290

282291
if (mextBit && !mextBitIsSet) {
283292
for (int j = 0; j <= CT_MAX_SMALL_POINT; j++) {
@@ -307,7 +316,8 @@ private void handleBlsG2Add() {
307316
final boolean isLargePointOnCurve =
308317
isLargePointOnCurve(indexOffset, callData.slice(sizeOffset, SIZE_LARGE_POINT));
309318
final boolean mextBit = wellFormedCoordinate && !isLargePointOnCurve;
310-
Preconditions.checkArgument(mextBit == (wellFormedCoordinate && !successBit));
319+
Preconditions.checkArgument(
320+
mextBit == (wellFormedCoordinate && !successBit), "BLS_G2ADD: mext bit inconsistency");
311321

312322
if (mextBit && !mextBitIsSet) {
313323
for (int j = 0; j <= CT_MAX_LARGE_POINT; j++) {
@@ -338,7 +348,8 @@ private void handleBlsG2Msm() {
338348
final boolean isLargePointInSubgroup =
339349
isLargePointInSubGroup(indexOffset, callData.slice(sizeOffset, SIZE_LARGE_POINT));
340350
final boolean mextBit = wellFormedCoordinate && !isLargePointInSubgroup;
341-
Preconditions.checkArgument(mextBit == (wellFormedCoordinate && !successBit));
351+
Preconditions.checkArgument(
352+
mextBit == (wellFormedCoordinate && !successBit), "BLS_G2MSM: mext bit inconsistency");
342353

343354
if (mextBit && !mextBitIsSet) {
344355
for (int j = 0; j <= CT_MAX_LARGE_POINT; j++) {
@@ -371,7 +382,9 @@ private void handleBlsPairingCheck() {
371382
final boolean isSmallPointInSubgroup =
372383
isSmallPointInSubGroup(indexOffset, callData.slice(sizeOffset, SIZE_SMALL_POINT));
373384
final boolean mextBitSmall = wellFormedFpCoordinate && !isSmallPointInSubgroup;
374-
Preconditions.checkArgument(mextBitSmall == (wellFormedFpCoordinate && !successBit));
385+
Preconditions.checkArgument(
386+
mextBitSmall == (wellFormedFpCoordinate && !successBit),
387+
"BLS_PAIRING_CHECK: mext bit inconsistency for small point");
375388

376389
if (mextBitSmall && !mextBitIsSet) {
377390
for (int j = 0; j <= CT_MAX_SMALL_POINT; j++) {
@@ -388,7 +401,9 @@ private void handleBlsPairingCheck() {
388401
isLargePointInSubGroup(
389402
8 + indexOffset, callData.slice(8 * LLARGE + sizeOffset, SIZE_LARGE_POINT));
390403
final boolean mextBitLarge = wellFormedFp2Coordinate && !isLargePointInSubgroup;
391-
Preconditions.checkArgument(mextBitLarge == (wellFormedFp2Coordinate && !successBit));
404+
Preconditions.checkArgument(
405+
mextBitLarge == (wellFormedFp2Coordinate && !successBit),
406+
"BLS_PAIRING_CHECK: mext bit inconsistency for large point");
392407

393408
if (mextBitLarge && !mextBitIsSet) {
394409
for (int j = 0; j <= CT_MAX_LARGE_POINT; j++) {

arithmetization/src/main/java/net/consensys/linea/zktracer/module/ecdata/EcDataOperation.java

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -135,20 +135,26 @@ private EcDataOperation(
135135
final PrecompileScenarioFragment.PrecompileFlag precompileFlag,
136136
Bytes callData,
137137
Bytes returnData) {
138-
checkArgument(precompileFlag.isEcdataPrecompile(), "invalid EC type");
138+
checkArgument(
139+
precompileFlag.isEcdataPrecompile(),
140+
"EcDataOperation: precompile %s isn't of EC_DATA type",
141+
precompileFlag);
139142

140143
this.precompileFlag = precompileFlag;
141144
final int callDataSize = callData.size();
142145
checkArgument(
143-
callDataSize > 0,
144-
"EcDataOperation should only be called with nonempty call rightPaddedCallData");
146+
callDataSize > 0, "EcDataOperation should only be called with nonempty call data");
145147
final int paddedCallDataLength =
146148
switch (precompileFlag) {
147149
case PRC_ECRECOVER -> TOTAL_SIZE_ECRECOVER_DATA;
148150
case PRC_ECADD -> TOTAL_SIZE_ECADD_DATA;
149151
case PRC_ECMUL -> TOTAL_SIZE_ECMUL_DATA;
150152
case PRC_ECPAIRING -> {
151-
checkArgument(callDataSize % TOTAL_SIZE_ECPAIRING_DATA_MIN == 0);
153+
checkArgument(
154+
callDataSize % TOTAL_SIZE_ECPAIRING_DATA_MIN == 0,
155+
"ECPAIRING: call data size expected to be multiple of %s, but remainder is %s ≠ 0",
156+
TOTAL_SIZE_ECPAIRING_DATA_MIN,
157+
callDataSize % TOTAL_SIZE_ECPAIRING_DATA_MIN);
152158
yield callDataSize;
153159
}
154160
default -> throw new IllegalArgumentException(
@@ -425,7 +431,10 @@ void handleAdd() {
425431

426432
// Extract output
427433
if (internalChecksPassed && returnData.toArray().length != 0) {
428-
checkArgument(returnData.toArray().length == 64);
434+
checkArgument(
435+
returnData.toArray().length == 64,
436+
"ECADD: return data size %s should be 64",
437+
returnData.toArray().length);
429438
resX = EWord.of(returnData.slice(0, 32));
430439
resY = EWord.of(returnData.slice(32, 32));
431440
}
@@ -473,7 +482,10 @@ void handleMul() {
473482

474483
// Extract output
475484
if (internalChecksPassed && returnData.toArray().length != 0) {
476-
checkArgument(returnData.toArray().length == 64);
485+
checkArgument(
486+
returnData.toArray().length == 64,
487+
"ECMUL: return data size %s should be 64",
488+
returnData.toArray().length);
477489
resX = EWord.of(returnData.slice(0, 32));
478490
resY = EWord.of(returnData.slice(32, 32));
479491
}
@@ -690,9 +702,16 @@ void trace(Trace.Ecdata trace, final int stamp, final long previousId) {
690702
}
691703

692704
if (precompileFlag != PRC_ECPAIRING || !isData) {
693-
checkArgument(ct == 0);
705+
checkArgument(
706+
ct == 0,
707+
"EcDataOperation's trace method: ct should be 0 except for ECPAIRING data rows, yet prc = %s, isData = %s, ct = %s",
708+
precompileFlag,
709+
isData,
710+
ct);
694711
}
695-
checkArgument(!(isSmallPoint && isLargePoint));
712+
checkArgument(
713+
!(isSmallPoint && isLargePoint),
714+
"EcDataOperation's trace: ECPAIRING data simultaneously categorized as small and large point");
696715

697716
trace
698717
.stamp(stamp)

arithmetization/src/main/java/net/consensys/linea/zktracer/module/exp/ExpOperation.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,9 @@ public ExpOperation(ExpCall expCall) {
5757
final ModexpMetadata modexpMetadata = modexplogExpCall.getModexpMetadata();
5858
final int bbsInt = modexpMetadata.bbsInt();
5959
final int ebsInt = modexpMetadata.ebsInt();
60-
checkArgument(modexpMetadata.callData().size() - BASE_MIN_OFFSET - bbsInt >= 0);
60+
checkArgument(
61+
modexpMetadata.callData().size() - BASE_MIN_OFFSET - bbsInt >= 0,
62+
"MODEXP call data unexpectedly short");
6163
final EWord rawLead = modexpMetadata.rawLeadingWord();
6264
final int cdsCutoff =
6365
Math.min(modexpMetadata.callData().size() - BASE_MIN_OFFSET - bbsInt, 32);

arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/AccountSnapshot.java

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ public AccountSnapshot deepCopy() {
158158

159159
public void wipe(DeploymentInfo deploymentInfo) {
160160
final boolean deploymentStatus = deploymentInfo.getDeploymentStatus(address);
161-
checkArgument(!deploymentStatus);
161+
checkArgument(!deploymentStatus, "Cannot wipe an account that is under deployment");
162162
this.nonce(0).balance(Wei.ZERO).code(Bytecode.EMPTY).setDeploymentInfo(deploymentInfo);
163163
}
164164

@@ -232,7 +232,10 @@ public AccountSnapshot raiseNonceByOne() {
232232
}
233233

234234
public AccountSnapshot decrementNonceByOne() {
235-
checkState(nonce > 0);
235+
checkState(
236+
nonce > 0,
237+
"AccountSnapshot: attempting to decrement nonce by one when nonce is %s ≤ 0",
238+
nonce);
236239
return this.nonce(nonce - 1);
237240
}
238241

@@ -245,7 +248,10 @@ public AccountSnapshot setDeploymentNumber(DeploymentInfo deploymentInfo) {
245248
}
246249

247250
public void decrementDeploymentNumberByOne() {
248-
checkState(deploymentNumber > 0);
251+
checkState(
252+
deploymentNumber > 0,
253+
"Attempting to decrement deployment number by one when deployment number is %s ≤ 0",
254+
deploymentNumber);
249255
this.deploymentNumber(deploymentNumber - 1);
250256
}
251257

0 commit comments

Comments
 (0)