Skip to content

Commit

Permalink
Homogenize creation add operation (#1314)
Browse files Browse the repository at this point in the history
  • Loading branch information
letypequividelespoubelles authored Sep 25, 2024
1 parent ae20d75 commit 5544303
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ public void tracePreOpcode(MessageFrame frame) {
operations.add(
new AddOperation(
OpCode.of(frame.getCurrentOperation().getOpcode()),
frame.getStackItem(0),
frame.getStackItem(1)));
Bytes32.leftPad(frame.getStackItem(0)),
Bytes32.leftPad(frame.getStackItem(1))));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,10 @@ private boolean overflowBit(
return false;
}

public AddOperation(OpCode opCode, Bytes arg1, Bytes arg2) {
public AddOperation(OpCode opCode, Bytes32 arg1, Bytes32 arg2) {
this.opCode = opCode;
this.arg1 = Bytes32.leftPad(arg1);
this.arg2 = Bytes32.leftPad(arg2);
this.arg1 = arg1;
this.arg2 = arg2;
}

private int computeCtMax() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,11 @@ public class ReturnSection extends TraceSection
boolean successfulMessageCallExpected; // for sanity check
boolean successfulDeploymentExpected; // for sanity check

// TODO: trigger SHAKIRA

public ReturnSection(Hub hub) {
super(hub, maxNumberOfRows(hub));

final CallFrame callFrame = hub.currentFrame();
final MessageFrame messageFrame = hub.messageFrame();
final MessageFrame messageFrame = callFrame.frame();

returnFromMessageCall = callFrame.isMessageCall();
returnFromDeployment = callFrame.isDeployment();
Expand Down Expand Up @@ -257,7 +255,7 @@ public void resolveAtContextReEntry(Hub hub, CallFrame frame) {

// TODO: optional sanity check that may be removed
if (returnFromDeployment) {
Bytes topOfTheStack = hub.messageFrame().getStackItem(0);
final Bytes topOfTheStack = hub.messageFrame().getStackItem(0);
boolean deploymentWasSuccess = !topOfTheStack.isZero();
checkArgument(deploymentWasSuccess == successfulDeploymentExpected);
}
Expand All @@ -272,9 +270,6 @@ public void resolveAtContextReEntry(Hub hub, CallFrame frame) {
DomSubStampsSubFragment.standardDomSubStamps(this.hubStamp(), 0));

if (nonemptyByteCode) {
// TODO: we require the
// - triggerHashInfo stuff on the first stack row (automatic AFAICT)
// - triggerROMLEX on the deploymentAccountFragment row (see below)
deploymentAccountFragment.requiresRomlex(true);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@
import net.consensys.linea.zktracer.types.EWord;
import net.consensys.linea.zktracer.types.UnsignedByte;
import org.apache.tuweni.bytes.Bytes;
import org.apache.tuweni.bytes.Bytes32;
import org.hyperledger.besu.datatypes.Address;
import org.hyperledger.besu.evm.account.Account;
import org.hyperledger.besu.evm.frame.MessageFrame;
Expand Down Expand Up @@ -480,8 +481,8 @@ private void callToADD(
checkArgument(arg1Lo.bitLength() / 8 <= 16);
checkArgument(arg2Hi.bitLength() / 8 <= 16);
checkArgument(arg2Lo.bitLength() / 8 <= 16);
final EWord arg1 = EWord.of(arg1Hi, arg1Lo);
final EWord arg2 = EWord.of(arg2Hi, arg2Lo);
final Bytes32 arg1 = EWord.of(arg1Hi, arg1Lo);
final Bytes32 arg2 = EWord.of(arg2Hi, arg2Lo);
addFlag[k] = true;
modFlag[k] = false;
wcpFlag[k] = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,21 +25,22 @@
import net.consensys.linea.zktracer.module.add.AddOperation;
import net.consensys.linea.zktracer.opcode.OpCode;
import org.apache.tuweni.bytes.Bytes;
import org.apache.tuweni.bytes.Bytes32;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

public class StackedListTests {
private static final AddOperation ONE_PLUS_ONE =
new AddOperation(
OpCode.ADD,
Bytes.wrap(BigInteger.ONE.toByteArray()),
Bytes.wrap(BigInteger.ONE.toByteArray()));
Bytes32.leftPad(Bytes.wrap(BigInteger.ONE.toByteArray())),
Bytes32.leftPad(Bytes.wrap(BigInteger.ONE.toByteArray())));

private static final AddOperation ONE_PLUS_TWO =
new AddOperation(
OpCode.ADD,
Bytes.wrap(BigInteger.ONE.toByteArray()),
Bytes.wrap(BigInteger.TWO.toByteArray()));
Bytes32.leftPad(Bytes.wrap(BigInteger.ONE.toByteArray())),
Bytes32.leftPad(Bytes.wrap(BigInteger.TWO.toByteArray())));

@RequiredArgsConstructor
private static class IntegerModuleOperation extends ModuleOperation {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import net.consensys.linea.zktracer.module.add.AddOperation;
import net.consensys.linea.zktracer.opcode.OpCode;
import org.apache.tuweni.bytes.Bytes;
import org.apache.tuweni.bytes.Bytes32;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

Expand All @@ -29,14 +30,14 @@ public class StackedSetTests {
private static final AddOperation ONE_PLUS_ONE =
new AddOperation(
OpCode.ADD,
Bytes.wrap(BigInteger.ONE.toByteArray()),
Bytes.wrap(BigInteger.ONE.toByteArray()));
Bytes32.leftPad(Bytes.wrap(BigInteger.ONE.toByteArray())),
Bytes32.leftPad(Bytes.wrap(BigInteger.ONE.toByteArray())));

private static final AddOperation ONE_PLUS_TWO =
new AddOperation(
OpCode.ADD,
Bytes.wrap(BigInteger.ONE.toByteArray()),
Bytes.wrap(BigInteger.TWO.toByteArray()));
Bytes32.leftPad(Bytes.wrap(BigInteger.ONE.toByteArray())),
Bytes32.leftPad(Bytes.wrap(BigInteger.TWO.toByteArray())));

@Test
public void push() {
Expand Down

0 comments on commit 5544303

Please sign in to comment.