diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/ZkTracer.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/ZkTracer.java index cecd10ae..1d949f8b 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/ZkTracer.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/ZkTracer.java @@ -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; @@ -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); } } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/opcode/OpCodes.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/opcode/OpCodes.java index c5c5bef9..3ed4a836 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/opcode/OpCodes.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/opcode/OpCodes.java @@ -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; @@ -33,29 +32,31 @@ public class OpCodes { private static final JsonConverter YAML_CONVERTER = JsonConverter.builder().enableYaml().build(); - private static Map valueToOpCodeDataMap = new ConcurrentHashMap<>(); - private static Map opCodeToOpCodeDataMap = new ConcurrentHashMap<>(); + private static Map valueToOpCodeDataMap; + private static Map 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 opCodes = - YAML_CONVERTER.getObjectMapper().treeToValue(rootNode, typeReference); + List 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)); } /** diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/types/Utils.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/types/Utils.java index 9e68f25d..222c91c7 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/types/Utils.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/types/Utils.java @@ -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; @@ -90,7 +90,7 @@ public static BitDecOutput bitDecomposition(int input, int nbStep) { } public static Map computeSpillings() throws IOException { - final Map spillings = new ConcurrentHashMap<>(); + final Map spillings = new HashMap<>(); final TomlTable table = Toml.parse(Utils.class.getClassLoader().getResourceAsStream("spillings.toml"))