Skip to content

Commit

Permalink
CREATE tests (#1572)
Browse files Browse the repository at this point in the history
  • Loading branch information
OlivierBBB authored Dec 7, 2024
1 parent e84747c commit 92580b4
Show file tree
Hide file tree
Showing 33 changed files with 1,925 additions and 492 deletions.
35 changes: 35 additions & 0 deletions ac
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# SELFDESTRUCT testing

- STATICX
- i.e. done in an execution context spawned through STATICCALL
- OOGX
- zero / nonzero balance
- warmth / cold recipient
- self recipient
- new account cost for recipient
- REVERT'ed later or not
- inside of a CREATE / deployment transaction
- leads to early deployment of empty code
- said account will be wiped off the world later
- can still have storage in the mean time

- carried out several times in the same account, same transaction
- reverted yes or no at the end
- done indirectly (i.e. through DELEGATECALL / CALLCODE)
- interaction with storage

More involved:
- deploying from an account MARKED_FOR_SELFDESTRUCT
- deploying with CREATE from an account MARKED_FOR_SELFDESTRUCT

This would be to reproduce CREATE address collisions


# PRC calls

- all 9 precompiles
- testing all possible success / failure paths (some extensive work was already done for EC stuff)
- in particular for gas
- testing variations on CALLDATA
- testing the output RETURNDATA
- interaction with DELEGATECALL / CALLCODE ?
Original file line number Diff line number Diff line change
Expand Up @@ -625,7 +625,7 @@ public void traceContextEnter(MessageFrame frame) {
frameType,
newChildContextNumber(),
this.deploymentStatusOf(frame.getContractAddress()),
frame.getValue(),
frame.getApparentValue(),
frame.getRemainingGas(),
frame.getRecipientAddress(),
this.deploymentNumberOf(frame.getRecipientAddress()),
Expand Down

Large diffs are not rendered by default.

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 @@ -32,7 +32,16 @@ public enum CreateScenario {
CREATE_NON_EMPTY_INIT_CODE_FAILURE_WILL_REVERT,
CREATE_NON_EMPTY_INIT_CODE_FAILURE_WONT_REVERT,
CREATE_NON_EMPTY_INIT_CODE_SUCCESS_WILL_REVERT,
CREATE_NON_EMPTY_INIT_CODE_SUCCESS_WONT_REVERT
CREATE_NON_EMPTY_INIT_CODE_SUCCESS_WONT_REVERT;

public boolean isAnyOf(CreateScenario... createScenarios) {
for (CreateScenario createScenario : createScenarios) {
if (createScenario.equals(this)) {
return true;
}
}
return false;
}
}

@Setter @Getter private CreateScenario scenario;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import net.consensys.linea.zktracer.module.hub.Trace;
import net.consensys.linea.zktracer.module.hub.fragment.TraceFragment;
import net.consensys.linea.zktracer.module.hub.section.call.precompileSubsection.PrecompileSubsection;
import org.apache.tuweni.bytes.Bytes;
import org.hyperledger.besu.datatypes.Address;

@Getter
Expand Down Expand Up @@ -169,9 +170,9 @@ public Trace trace(Trace trace) {
.pScenarioPrcSuccessCallerWontRevert(scenario == PRC_SUCCESS_WONT_REVERT)
.pScenarioPrcFailureKnownToHub(scenario == PRC_FAILURE_KNOWN_TO_HUB)
.pScenarioPrcFailureKnownToRam(scenario == PRC_FAILURE_KNOWN_TO_RAM)
.pScenarioPrcCallerGas(precompileSubSection.callerGas())
.pScenarioPrcCalleeGas(precompileSubSection.calleeGas())
.pScenarioPrcReturnGas(precompileSubSection.returnGas())
.pScenarioPrcCallerGas(Bytes.ofUnsignedLong(precompileSubSection.callerGas()))
.pScenarioPrcCalleeGas(Bytes.ofUnsignedLong(precompileSubSection.calleeGas()))
.pScenarioPrcReturnGas(Bytes.ofUnsignedLong(precompileSubSection.returnGas()))
.pScenarioPrcCdo(precompileSubSection.callDataOffset())
.pScenarioPrcCds(precompileSubSection.callDataSize())
.pScenarioPrcRao(precompileSubSection.returnAtOffset())
Expand Down
Loading

0 comments on commit 92580b4

Please sign in to comment.