Skip to content

Commit 9bf3986

Browse files
test: some more skip tests (#1734)
1 parent bfb7883 commit 9bf3986

File tree

3 files changed

+138
-14
lines changed

3 files changed

+138
-14
lines changed

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

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -234,24 +234,26 @@ public AccountSnapshot setWarmthTo(boolean newWarmth) {
234234
return this;
235235
}
236236

237-
/**
238-
* Raises the nonce by 1. <b>WARNING:</b> this modifies the underlying {@link AccountSnapshot}. Be
239-
* sure to work with a {@link AccountSnapshot#deepCopy} if necessary.
240-
*
241-
* @return {@code this} with nonce++
242-
*/
243237
public AccountSnapshot raiseNonceByOne() {
244-
this.nonce(nonce + 1);
245-
return this;
238+
return this.nonce(nonce + 1);
239+
}
240+
241+
public AccountSnapshot decrementNonceByOne() {
242+
checkState(nonce > 0);
243+
return this.nonce(nonce - 1);
246244
}
247245

248246
public AccountSnapshot setDeploymentNumber(Hub hub) {
249247
return this.setDeploymentNumber(hub.transients.conflation().deploymentInfo());
250248
}
251249

252250
public AccountSnapshot setDeploymentNumber(DeploymentInfo deploymentInfo) {
253-
this.deploymentNumber(deploymentInfo.deploymentNumber(address));
254-
return this;
251+
return this.deploymentNumber(deploymentInfo.deploymentNumber(address));
252+
}
253+
254+
public AccountSnapshot decrementDeploymentNumberByOne() {
255+
checkState(deploymentNumber > 0);
256+
return this.deploymentNumber(deploymentNumber - 1);
255257
}
256258

257259
public AccountSnapshot setDeploymentInfo(Hub hub) {

tracer/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/TxSkipSection.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -112,14 +112,14 @@ public void resolveAtEndTransaction(
112112
// may have to be modified in case of address collision
113113
senderNew = canonical(hub, world, sender.address(), isPrecompile(sender.address()));
114114
recipientNew = canonical(hub, world, recipient.address(), isPrecompile(recipient.address()));
115-
coinbaseNew = canonical(hub, world, coinbase.address(), isPrecompile(recipient.address()));
115+
coinbaseNew = canonical(hub, world, coinbase.address(), isPrecompile(coinbase.address()));
116116

117117
final Wei value = (Wei) txMetadata.getBesuTransaction().getValue();
118118

119119
if (senderAddressCollision()) {
120-
BigInteger gasUsed = BigInteger.valueOf(txMetadata.getGasUsed());
121-
BigInteger gasPrice = BigInteger.valueOf(txMetadata.getEffectiveGasPrice());
122-
BigInteger gasCost = gasUsed.multiply(gasPrice);
120+
final BigInteger gasUsed = BigInteger.valueOf(txMetadata.getGasUsed());
121+
final BigInteger gasPrice = BigInteger.valueOf(txMetadata.getEffectiveGasPrice());
122+
final BigInteger gasCost = gasUsed.multiply(gasPrice);
123123
senderNew =
124124
sender
125125
.deepCopy()
@@ -135,6 +135,9 @@ public void resolveAtEndTransaction(
135135
if (recipientIsCoinbase()) {
136136
recipientNew = coinbaseNew.deepCopy().decrementBalanceBy(txMetadata.getCoinbaseReward());
137137
recipient = recipientNew.deepCopy().decrementBalanceBy(value);
138+
if (txMetadata.isDeployment()) {
139+
recipient.decrementNonceByOne().decrementDeploymentNumberByOne();
140+
}
138141
}
139142
}
140143

tracer/arithmetization/src/test/java/net/consensys/linea/zktracer/module/hub/TxSkipTests.java

Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
package net.consensys.linea.zktracer.module.hub;
1717

1818
import static net.consensys.linea.testing.ToyExecutionEnvironmentV2.DEFAULT_COINBASE_ADDRESS;
19+
import static net.consensys.linea.zktracer.types.AddressUtils.getCreateRawAddress;
1920

2021
import java.util.List;
2122

@@ -320,4 +321,122 @@ void senderIsCoinbaseIsReceiver() {
320321
.build()
321322
.run();
322323
}
324+
325+
@Test
326+
void skipMessageCallCoinbaseIsPrecompile() {
327+
final KeyPair senderKeyPair = new SECP256K1().generateKeyPair();
328+
final Address senderAddress =
329+
Address.extract(Hash.hash(senderKeyPair.getPublicKey().getEncodedBytes()));
330+
final ToyAccount senderAccount =
331+
ToyAccount.builder().balance(Wei.fromEth(0xffff)).nonce(128).address(senderAddress).build();
332+
333+
final Address receiverAddress =
334+
Address.fromHexString("0xffffffffffffffffffffffffffffffffffffff");
335+
336+
final ToyAccount receiverAccount =
337+
ToyAccount.builder()
338+
.balance(Wei.fromEth(0xffffee))
339+
.nonce(18)
340+
.address(receiverAddress)
341+
.build();
342+
343+
final Transaction tx =
344+
ToyTransaction.builder()
345+
.sender(senderAccount)
346+
.to(receiverAccount)
347+
.keyPair(senderKeyPair)
348+
.value(Wei.of(123))
349+
.build();
350+
351+
ToyExecutionEnvironmentV2.builder()
352+
.accounts(List.of(senderAccount, receiverAccount))
353+
.transaction(tx)
354+
.zkTracerValidator(zkTracer -> {})
355+
.coinbase(Address.BLAKE2B_F_COMPRESSION)
356+
.build()
357+
.run();
358+
}
359+
360+
@Test
361+
void skippedDepSenderIsCoinbase() {
362+
final KeyPair senderKeyPair = new SECP256K1().generateKeyPair();
363+
final Address senderAddress =
364+
Address.extract(Hash.hash(senderKeyPair.getPublicKey().getEncodedBytes()));
365+
final ToyAccount senderAccount =
366+
ToyAccount.builder().balance(Wei.fromEth(0xffff)).nonce(128).address(senderAddress).build();
367+
368+
final Transaction tx =
369+
ToyTransaction.builder()
370+
.sender(senderAccount)
371+
.keyPair(senderKeyPair)
372+
.value(Wei.of(123))
373+
.gasLimit(100000L)
374+
.build();
375+
376+
ToyExecutionEnvironmentV2.builder()
377+
.accounts(List.of(senderAccount))
378+
.transaction(tx)
379+
.zkTracerValidator(zkTracer -> {})
380+
.coinbase(senderAddress)
381+
.build()
382+
.run();
383+
}
384+
385+
@Test
386+
void skippedDepDeploymentAddressIsCoinbase() {
387+
final KeyPair senderKeyPair = new SECP256K1().generateKeyPair();
388+
final Address senderAddress =
389+
Address.extract(Hash.hash(senderKeyPair.getPublicKey().getEncodedBytes()));
390+
final int nonce = 632;
391+
final ToyAccount senderAccount =
392+
ToyAccount.builder()
393+
.balance(Wei.fromEth(0xffff))
394+
.nonce(nonce)
395+
.address(senderAddress)
396+
.build();
397+
398+
final Address depAddress = Address.extract(getCreateRawAddress(senderAddress, nonce));
399+
400+
final Transaction tx =
401+
ToyTransaction.builder()
402+
.sender(senderAccount)
403+
.keyPair(senderKeyPair)
404+
.value(Wei.of(123))
405+
.gasLimit(100000L)
406+
.nonce((long) nonce)
407+
.build();
408+
409+
ToyExecutionEnvironmentV2.builder()
410+
.accounts(List.of(senderAccount))
411+
.transaction(tx)
412+
.zkTracerValidator(zkTracer -> {})
413+
.coinbase(depAddress)
414+
.build()
415+
.run();
416+
}
417+
418+
@Test
419+
void skippedDepCoinbaseIsPrecompile() {
420+
final KeyPair senderKeyPair = new SECP256K1().generateKeyPair();
421+
final Address senderAddress =
422+
Address.extract(Hash.hash(senderKeyPair.getPublicKey().getEncodedBytes()));
423+
final ToyAccount senderAccount =
424+
ToyAccount.builder().balance(Wei.fromEth(0xffff)).nonce(128).address(senderAddress).build();
425+
426+
final Transaction tx =
427+
ToyTransaction.builder()
428+
.sender(senderAccount)
429+
.keyPair(senderKeyPair)
430+
.value(Wei.of(123))
431+
.gasLimit(100000L)
432+
.build();
433+
434+
ToyExecutionEnvironmentV2.builder()
435+
.accounts(List.of(senderAccount))
436+
.transaction(tx)
437+
.zkTracerValidator(zkTracer -> {})
438+
.coinbase(Address.RIPEMD160)
439+
.build()
440+
.run();
441+
}
323442
}

0 commit comments

Comments
 (0)