Skip to content

Commit

Permalink
Refactoring
Browse files Browse the repository at this point in the history
Signed-off-by: Ameziane H <[email protected]>
  • Loading branch information
ahamlat committed May 16, 2024
1 parent 4bc852c commit 8e4a668
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
import net.consensys.linea.config.LineaL1L2BridgeConfiguration;
import net.consensys.linea.zktracer.module.Module;
import net.consensys.linea.zktracer.module.hub.Hub;
import net.consensys.linea.zktracer.opcode.OpCodes;
import net.consensys.linea.zktracer.types.Utils;
import org.apache.tuweni.bytes.Bytes;
import org.hyperledger.besu.datatypes.Hash;
Expand All @@ -57,11 +56,12 @@ public class ZkTracer implements ConflationAwareOperationTracer {

static {
try {
// Load opcodes configured in src/main/resources/opcodes.yml.
OpCodes.load();
// Load spillings configured in src/main/resources/spillings.toml.
spillings = Utils.computeSpillings();
} catch (final Exception e) {
final String errorMsg =
"A problem happened during spillings initialization, cause " + e.getCause();
log.error(errorMsg);
throw new RuntimeException(e);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.concurrent.ConcurrentHashMap;
import java.util.stream.Collectors;

import com.fasterxml.jackson.databind.JsonNode;
Expand All @@ -33,29 +32,31 @@
public class OpCodes {
private static final JsonConverter YAML_CONVERTER = JsonConverter.builder().enableYaml().build();

private static Map<Integer, OpCodeData> valueToOpCodeDataMap = new ConcurrentHashMap<>();
private static Map<OpCode, OpCodeData> opCodeToOpCodeDataMap = new ConcurrentHashMap<>();
private static Map<Integer, OpCodeData> valueToOpCodeDataMap;
private static Map<OpCode, OpCodeData> opCodeToOpCodeDataMap;

static {
/** Loads all opcode metadata from src/main/resources/opcodes.yml. */
init();
}

/** Loads all opcode metadata from src/main/resources/opcodes.yml. */
@SneakyThrows(IOException.class)
public static void load() {
if (valueToOpCodeDataMap.isEmpty() || opCodeToOpCodeDataMap.isEmpty()) {
JsonNode rootNode =
YAML_CONVERTER
.getObjectMapper()
.readTree(OpCodes.class.getClassLoader().getResourceAsStream("opcodes.yml"))
.get("opcodes");
private static void init() {
JsonNode rootNode =
YAML_CONVERTER
.getObjectMapper()
.readTree(OpCodes.class.getClassLoader().getResourceAsStream("opcodes.yml"))
.get("opcodes");

CollectionType typeReference =
TypeFactory.defaultInstance().constructCollectionType(List.class, OpCodeData.class);
CollectionType typeReference =
TypeFactory.defaultInstance().constructCollectionType(List.class, OpCodeData.class);

List<OpCodeData> opCodes =
YAML_CONVERTER.getObjectMapper().treeToValue(rootNode, typeReference);
List<OpCodeData> opCodes =
YAML_CONVERTER.getObjectMapper().treeToValue(rootNode, typeReference);

valueToOpCodeDataMap = opCodes.stream().collect(Collectors.toMap(OpCodeData::value, e -> e));
opCodeToOpCodeDataMap =
opCodes.stream().collect(Collectors.toMap(OpCodeData::mnemonic, e -> e));
}
valueToOpCodeDataMap = opCodes.stream().collect(Collectors.toMap(OpCodeData::value, e -> e));
opCodeToOpCodeDataMap =
opCodes.stream().collect(Collectors.toMap(OpCodeData::mnemonic, e -> e));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@

import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

import com.google.common.base.Preconditions;
import org.apache.tuweni.bytes.Bytes;
Expand Down Expand Up @@ -90,7 +90,7 @@ public static BitDecOutput bitDecomposition(int input, int nbStep) {
}

public static Map<String, Integer> computeSpillings() throws IOException {
final Map<String, Integer> spillings = new ConcurrentHashMap<>();
final Map<String, Integer> spillings = new HashMap<>();

final TomlTable table =
Toml.parse(Utils.class.getClassLoader().getResourceAsStream("spillings.toml"))
Expand Down

0 comments on commit 8e4a668

Please sign in to comment.