-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'arith-dev' into 1209-get-the-chainid-for-blockdata
- Loading branch information
Showing
6 changed files
with
269 additions
and
161 deletions.
There are no files selected for viewing
64 changes: 64 additions & 0 deletions
64
...n/src/main/java/net/consensys/linea/zktracer/container/stacked/NoLineCountStackedSet.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
/* | ||
* Copyright ConsenSys 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.container.stacked; | ||
|
||
import java.util.HashSet; | ||
import java.util.Set; | ||
|
||
import lombok.Getter; | ||
import lombok.experimental.Accessors; | ||
|
||
@Accessors(fluent = true) | ||
@Getter | ||
public class NoLineCountStackedSet<E> { | ||
private final Set<E> operationsCommitedToTheConflation; | ||
private final Set<E> operationsInTransaction; | ||
|
||
public NoLineCountStackedSet() { | ||
operationsCommitedToTheConflation = new HashSet<>(); | ||
operationsInTransaction = new HashSet<>(); | ||
} | ||
|
||
/** Prefer this constructor as we preallocate more needed memory */ | ||
public NoLineCountStackedSet( | ||
final int expectedConflationNumberOperations, final int expectedTransactionNumberOperations) { | ||
operationsCommitedToTheConflation = new HashSet<>(expectedConflationNumberOperations); | ||
operationsInTransaction = new HashSet<>(expectedTransactionNumberOperations); | ||
} | ||
|
||
/** | ||
* Upon entering a new transaction, the set of operations generated by the previous transaction | ||
* {@link StackedSet#operationsInTransaction()} (which is empty if no such transaction exists) is | ||
* added to the set of committed operations {@link | ||
* StackedSet#operationsCommitedToTheConflation()}. {@link StackedSet#operationsInTransaction()} | ||
* is further reset to be empty. | ||
*/ | ||
public void enter() { | ||
operationsCommitedToTheConflation().addAll(operationsInTransaction()); | ||
operationsInTransaction().clear(); | ||
} | ||
|
||
public void pop() { | ||
operationsInTransaction().clear(); | ||
} | ||
|
||
public boolean add(E e) { | ||
if (!operationsCommitedToTheConflation().contains(e)) { | ||
return operationsInTransaction().add(e); | ||
} | ||
return false; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
...on/src/main/java/net/consensys/linea/zktracer/module/hub/transients/StackHeightCheck.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
/* | ||
* 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.module.hub.transients; | ||
|
||
import static com.google.common.base.Preconditions.*; | ||
import static net.consensys.linea.zktracer.runtime.stack.Stack.MAX_STACK_SIZE; | ||
|
||
import lombok.EqualsAndHashCode; | ||
|
||
@EqualsAndHashCode(onlyExplicitlyIncluded = true, callSuper = false) | ||
public class StackHeightCheck { | ||
private static final Integer SHIFT_FACTOR = | ||
8; // 5 would suffice but 8 makes it a byte shift, not sure if it matters | ||
|
||
@EqualsAndHashCode.Include final int comparison; | ||
|
||
/** | ||
* This constructor creates a {@link StackHeightCheck} for stack underflow detection. | ||
* | ||
* @param height stack height pre opcode execution | ||
* @param delta greatest depth at which touched stack items | ||
*/ | ||
public StackHeightCheck(int height, int delta) { | ||
checkArgument(0 <= height && height <= MAX_STACK_SIZE && 0 <= delta && delta <= 17); | ||
comparison = height << SHIFT_FACTOR | delta; | ||
} | ||
|
||
/** | ||
* This constructor creates a {@link StackHeightCheck} for stack overflow detection. | ||
* | ||
* @param heightNew stack height post opcode execution | ||
*/ | ||
public StackHeightCheck(int heightNew) { | ||
checkArgument(0 <= heightNew && heightNew <= MAX_STACK_SIZE + 1); | ||
comparison = heightNew; | ||
} | ||
} |
Oops, something went wrong.