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

CREATE tests #1572

Open
wants to merge 29 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
29 commits
Select commit Hold shift + click to select a range
e0f6dd9
first commit
OlivierBBB Nov 26, 2024
0c986fe
ras
OlivierBBB Nov 27, 2024
2044895
feat: wip tests
OlivierBBB Nov 27, 2024
a271c07
feat: root level CREATE tests
OlivierBBB Nov 27, 2024
8826713
ras
OlivierBBB Nov 27, 2024
98f63a4
fix: added missing salt parameter to genericCreate()
OlivierBBB Nov 27, 2024
50f85d7
feat: some abort tests for CREATE(2)
OlivierBBB Nov 27, 2024
14afa73
feat: abort / success and success / abort tests for CREATE(2)'s
OlivierBBB Nov 27, 2024
b18f6dd
feat: more tests
OlivierBBB Nov 27, 2024
e8cd37f
fix: documentation + no SUX for CREATE2 anymore
OlivierBBB Nov 27, 2024
66019d9
Merge branch 'arith-dev' into CREATE-tests
OlivierBBB Nov 27, 2024
7744321
spotless
OlivierBBB Nov 27, 2024
356dc8e
fix: make the test work
OlivierBBB Nov 27, 2024
efdc33b
Merge branch 'arith-dev' into CREATE-tests
OlivierBBB Nov 27, 2024
b3fd26f
spotless
OlivierBBB Nov 27, 2024
aa81fba
feat: added documentation for nontrivial CREATE tests
OlivierBBB Nov 28, 2024
c8c5aaa
feat: more CREATE test todo's
OlivierBBB Nov 29, 2024
03a90c8
Merge branch 'arith-dev' into CREATE-tests
OlivierBBB Nov 29, 2024
3eb1d33
ras
OlivierBBB Dec 2, 2024
818e692
fix: CREATE's gasPaidOutOfPocket()
OlivierBBB Dec 2, 2024
2bc38d7
fix: remove double use of CREATE's gasPaidOutOfPocket
OlivierBBB Dec 2, 2024
0611e0e
fix: using creator snapshots for creatorAccountFragment of CreateSection
OlivierBBB Dec 2, 2024
581a7ab
fix: CREATE2 gas pricing (similar error to CREATE pricing error)
OlivierBBB Dec 2, 2024
1cf202e
fix: CREATE2 address computations now trace the nonce
OlivierBBB Dec 2, 2024
64fe94b
ras
OlivierBBB Dec 2, 2024
ba8e12c
spotless
OlivierBBB Dec 2, 2024
3bdae0c
Merge branch 'arith-dev' into CREATE-tests
OlivierBBB Dec 2, 2024
4a45440
feat: upgraded the todo.md's to GitHub issues
OlivierBBB Dec 2, 2024
117b776
fix: RLPADDR needs to hash the nonce to disambiguate CREATE2's
OlivierBBB Dec 2, 2024
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 @@ -257,9 +257,6 @@ public long computeGasNext(short exceptions) {

final long gasAfterDeductingCost = computeGasRemaining() - computeGasCost();

OpCode opCode = hub.opCode();
GasProjection gasUtility = Hub.GAS_PROJECTOR.of(hub.messageFrame(), opCode);

return switch (hub.opCodeData().instructionFamily()) {
case KEC, COPY, STACK_RAM, STORAGE, LOG, HALT -> gasAfterDeductingCost;
case CREATE -> gasAfterDeductingCost;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,16 +59,17 @@ public class StpCall implements TraceSubFragment {
@EqualsAndHashCode.Include long gasPaidOutOfPocket;
@EqualsAndHashCode.Include long stipend;

public StpCall(Hub hub, long memoryExpansionGas) {
this.memoryExpansionGas = memoryExpansionGas;
public StpCall(Hub hub, MessageFrame frame, long memoryExpansionGas) {
this.opCode = hub.opCode();
this.gasActual = hub.messageFrame().getRemainingGas();
checkArgument(this.opCode.isCall() || this.opCode.isCreate());

this.memoryExpansionGas = memoryExpansionGas;
this.gasActual = frame.getRemainingGas();

if (this.opCode.isCall()) {
this.stpCallForCalls(hub);
} else {
this.stpCallForCreates(hub);
this.stpCallForCreates(frame);
}
}

Expand Down Expand Up @@ -114,8 +115,7 @@ private long gasPaidOutOfPocketForCalls() {
}
}

private void stpCallForCreates(Hub hub) {
MessageFrame frame = hub.messageFrame();
private void stpCallForCreates(MessageFrame frame) {

this.gas = ZERO; // irrelevant
this.value = EWord.of(frame.getStackItem(0));
Expand All @@ -132,7 +132,7 @@ private long computeGasPaidOutOfPocketForCreates() {
return 0;
} else {
long gasMinusUpfrontCost = gasActual - upfrontGasCost;
return gasMinusUpfrontCost - (gasMinusUpfrontCost >> 6);
return gasMinusUpfrontCost - gasMinusUpfrontCost / 64;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ public CreateSection(Hub hub, MessageFrame frame) {
return;
}

final StpCall stpCall = new StpCall(hub, mxpCall.getGasMxp());
final StpCall stpCall = new StpCall(hub, frame, mxpCall.getGasMxp());
imcFragment.callStp(stpCall);

checkArgument(stpCall.outOfGasException() == Exceptions.outOfGasException(exceptions));
Expand Down Expand Up @@ -206,6 +206,7 @@ public CreateSection(Hub hub, MessageFrame frame) {
if (failedCreate) {
finalContextFragment = ContextFragment.nonExecutionProvidesEmptyReturnData(hub);
scenarioFragment.setScenario(CREATE_FAILURE_CONDITION_WONT_REVERT);
commonValues.payGasPaidOutOfPocket(hub);
Copy link
Collaborator Author

@OlivierBBB OlivierBBB Dec 2, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

omission

hub.failureConditionForCreates = true;
return;
}
Expand All @@ -220,13 +221,15 @@ public CreateSection(Hub hub, MessageFrame frame) {
// Finally, non-exceptional, non-aborting, non-failing, non-emptyInitCode create
////////////////////////////////////////////////////////////////////////////////

// we charge for the gas paid out of pocket
commonValues.payGasPaidOutOfPocket(hub);

// we capture revert information about the child context: CCSR and CCRS
hub.defers().scheduleForContextReEntry(imcFragment, hub.currentFrame());

// The current execution context pays (63/64)ths of it current gas to the child context
commonValues.payGasPaidOutOfPocket(hub);
hub.defers()
.scheduleForContextReEntry(this, callFrame); // To get the success bit of the CREATE(2)
// To get the success bit of the CREATE(2) operation
hub.defers().scheduleForContextReEntry(this, callFrame);

requiresRomLex = true;
hub.romLex().callRomLex(frame);
Expand Down Expand Up @@ -361,8 +364,8 @@ private void finishAbort(final Hub hub) {
hub.factories().accountFragment();
final AccountFragment creatorAccountFragment =
accountFragmentFactory.make(
preOpcodeCreateeSnapshot,
preOpcodeCreateeSnapshot,
preOpcodeCreatorSnapshot,
preOpcodeCreatorSnapshot,
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo

DomSubStampsSubFragment.standardDomSubStamps(this.hubStamp(), 0));

final ContextFragment updatedCurrentContextFragment =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ public CallSection(Hub hub, MessageFrame frame) {
return;
}

stpCall = new StpCall(hub, mxpCall.gasMxp);
stpCall = new StpCall(hub, frame, mxpCall.gasMxp);
firstImcFragment.callStp(stpCall);
checkArgument(
stpCall.outOfGasException() == Exceptions.outOfGasException(exceptions),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,13 @@ public void callRlpAddrCreate2(MessageFrame frame, Bytes32 salt, Bytes32 hash) {
final Address currentAddress = frame.getRecipientAddress();
final Bytes32 rawCreate2Address = getCreate2RawAddress(currentAddress, salt, hash);
final RlpAddrOperation operation =
new RlpAddrOperation(rawCreate2Address, OpCode.CREATE2, currentAddress, salt, hash);
new RlpAddrOperation(
rawCreate2Address,
OpCode.CREATE2,
currentAddress,
salt,
hash,
longToUnsignedBigInteger(frame.getWorldUpdater().get(currentAddress).getNonce()));
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Even though it's unnecessary, the nonce is part of the HUB -> RLPADDR lookup for CREATE2.

operations.add(operation);
hub.trm().callTrimming(rawCreate2Address);
}
Expand All @@ -118,6 +124,8 @@ private void traceCreate2(int stamp, RlpAddrOperation chunk, Trace trace) {
final Bytes rawAddressHi = chunk.rawHash().slice(0, LLARGE);
final long depAddressHi = rawAddressHi.slice(12, 4).toLong();
final Bytes depAddressLo = chunk.rawHash().slice(LLARGE, LLARGE);
final BigInteger nonce = chunk.nonce();
final Bytes nonceBytes = bigIntegerToBytes(nonce);

for (int ct = 0; ct <= MAX_CT_CREATE2; ct++) {
trace
Expand All @@ -130,10 +138,11 @@ private void traceCreate2(int stamp, RlpAddrOperation chunk, Trace trace) {
.depAddrLo(depAddressLo)
.addrHi(chunk.address().slice(0, 4).toLong())
.addrLo(chunk.address().slice(4, LLARGE))
.saltHi(chunk.salt().orElseThrow().slice(0, LLARGE))
.saltLo(chunk.salt().orElseThrow().slice(LLARGE, LLARGE))
.kecHi(chunk.keccak().orElseThrow().slice(0, LLARGE))
.kecLo(chunk.keccak().orElseThrow().slice(LLARGE, LLARGE))
.saltHi(chunk.salt().slice(0, LLARGE))
.saltLo(chunk.salt().slice(LLARGE, LLARGE))
.kecHi(chunk.keccak().slice(0, LLARGE))
.kecLo(chunk.keccak().slice(LLARGE, LLARGE))
.nonce(nonceBytes)
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We trace the nonce in all cases.

.lc(true)
.index(UnsignedByte.of(ct))
.counter(UnsignedByte.of(ct));
Expand All @@ -149,19 +158,19 @@ private void traceCreate2(int stamp, RlpAddrOperation chunk, Trace trace) {
.nBytes(BYTES_LLARGE)
.selectorKeccakRes(false);
case 2 -> trace
.limb(chunk.salt().orElseThrow().slice(0, LLARGE))
.limb(chunk.salt().slice(0, LLARGE))
.nBytes(BYTES_LLARGE)
.selectorKeccakRes(false);
case 3 -> trace
.limb(chunk.salt().orElseThrow().slice(LLARGE, LLARGE))
.limb(chunk.salt().slice(LLARGE, LLARGE))
.nBytes(BYTES_LLARGE)
.selectorKeccakRes(false);
case 4 -> trace
.limb(chunk.keccak().orElseThrow().slice(0, LLARGE))
.limb(chunk.keccak().slice(0, LLARGE))
.nBytes(BYTES_LLARGE)
.selectorKeccakRes(false);
case 5 -> trace
.limb(chunk.keccak().orElseThrow().slice(LLARGE, LLARGE))
.limb(chunk.keccak().slice(LLARGE, LLARGE))
.nBytes(BYTES_LLARGE)
.selectorKeccakRes(false);
}
Expand All @@ -172,7 +181,7 @@ private void traceCreate2(int stamp, RlpAddrOperation chunk, Trace trace) {
}

private void traceCreate(int stamp, RlpAddrOperation chunk, Trace trace) {
final BigInteger nonce = chunk.nonce().orElseThrow();
final BigInteger nonce = chunk.nonce();

Bytes nonceShifted = leftPadTo(bigIntegerToBytes(nonce), recipe1NbRows);
Boolean tinyNonZeroNonce = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,20 +37,25 @@
public final class RlpAddrOperation extends ModuleOperation {
@EqualsAndHashCode.Include private final Bytes32 rawHash;
private final OpCode opCode;
private final Optional<BigInteger> nonce;
@EqualsAndHashCode.Include private final BigInteger nonce;
private final Address address;
private final Optional<Bytes32> salt;
private final Optional<Bytes32> keccak;
private final Bytes32 salt;
private final Bytes32 keccak;

// CREATE operation
public RlpAddrOperation(Bytes32 rawDepAddress, OpCode opCode, BigInteger nonce, Address address) {
this(rawDepAddress, opCode, Optional.of(nonce), address, Optional.empty(), Optional.empty());
this(rawDepAddress, opCode, nonce, address, Bytes32.ZERO, Bytes32.ZERO);
}

// CREATE2 operation
public RlpAddrOperation(
Bytes32 rawHash, OpCode opCode, Address address, Bytes32 salt, Bytes32 kec) {
this(rawHash, opCode, Optional.empty(), address, Optional.of(salt), Optional.of(kec));
Bytes32 rawHash,
OpCode opCode,
Address address,
Bytes32 salt,
Bytes32 kec,
BigInteger nonce) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding the nonce to the interface

this(rawHash, opCode, nonce, address, salt, kec);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,13 @@ public long largestOffset() {
@Override
public long gasPaidOutOfPocket() {
long currentGas = frame.getRemainingGas();
long gasCost = this.staticGas() + this.memoryExpansion();
long upfrontGasCost = this.upfrontGasCost();

if (gasCost > currentGas) {
if (upfrontGasCost > currentGas) {
return 0;
} else {
return currentGas - currentGas / 64;
}

long gasMinusUpfront = currentGas - upfrontGasCost;
return gasMinusUpfront - gasMinusUpfront / 64;
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was a genuine mistake. the 63/64-ths business happens after paying the upfront gas cost.

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,15 @@ public long linearPerWord() {
@Override
public long gasPaidOutOfPocket() {
long currentGas = frame.getRemainingGas();
long gasCost = this.staticGas() + this.memoryExpansion() + this.linearPerWord();
long upfrontGasCost = this.upfrontGasCost();

if (gasCost > currentGas) {
if (upfrontGasCost > currentGas) {
return 0;
} else {
return currentGas - currentGas / 64;
}

final long gasMinusUpfrontGasCost = currentGas - upfrontGasCost;

return gasMinusUpfrontGasCost - gasMinusUpfrontGasCost / 64;
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same mistake for CREATE2

}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*
* 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.createTests;

public enum CreateType {
CREATE,
CREATE2
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
* 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.createTests;

public enum OffsetParameter {
ZERO,
THREE,
SIXTEEN,
SIXTEEN_BYTE_INT,
THIRTY_TWO_BYTE_INT,
MAX,
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* 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.createTests;

public enum SizeParameter {
ZERO,
TWELVE, // - 3 - 1
THIRTEEN, // - 3 + 0
FOURTEEN, // - 3 + 1
THIRTY_TWO,
MSIZE,
MAX;

public boolean isAnyOf(SizeParameter... sizeParameters) {
for (SizeParameter sizeParameter : sizeParameters) {
if (this == sizeParameter) {
return true;
}
}
return false;
}

public boolean willRaiseException() {
return this.isAnyOf(MAX);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*
* 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.createTests;

public enum ValueParameter {
ZERO,
ONE,
SELFBALANCE,
SELFBALANCE_PLUS_ONE,
}
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.createTests;

public enum WhenToTestParameter {
BEFORE,
AFTER,
BEFORE_AND_AFTER
}
Loading
Loading