OCaml is a general-purpose, high-level, statically-typed functional programming language with a heavy emphasis on safety, efficiency, and expressiveness.
It has a strong type system, which helps to catch errors at compile-time rather than at runtime, this makes it easier to reason about the correctness of code.
The language is quite often used in industries such as finance, where one mistake in the code could prove catastrophic.
Jane Street, Docker, Facebook, Microsoft, Bloomberg, Ahrefs, SimCorp, and of course Tezos are all known to use OCaml.
Despite the numerous advantages, OCaml did not previously have multicore support, and to this point it has limited Tezos to single-core performance.
Multicore OCaml has been in the making for 8 years as it required a full rewrite of the OCaml runtime environment.
It has also been highly anticipated in the developer community and there was even a community Twitter bot created to keep track of its progress towards this important milestone.
On December 16th and after 8 years of cutting-edge research and development from multiple teams, OCaml 5 multicore was released.
Using OCaml 5 With Tezos For Faster Processing
With the new multithreaded capabilities that come with OCaml 5 Multicore, Tezos would be able to take advantage of faster processing.
With this in mind Nomadic Labs and Tarides started by using an early version as the OCaml 5 project aimed to be backwards compatible.
The Tarides team had already been deeply involved in OCaml’s evolution, working alongside academics, industrial developers, and the entire OCaml community to make improvements.
This prior experience meant that this team was perfectly positioned to help alongside Nomadic Labs on potential OCaml 5 multicore improvements.
Both teams wasted no time on development and even started before OCaml 5 multicore was even released, with backward compatibility in mind.
Marco Stronati, who co-leads the cryptography team at Nomadic Labs said:
“We knew OCaml 5 was not ready yet, but that backward compatibility was an explicit goal of the project, so we thought we would put that to the test.”
One of the areas the team looked at was how to use multicore processing to increase the performance of Epoxy, a new ZK-rollup solution coming to Tezos.
Epoxy on Tezos represents validity rollups (also known as ZK-rollups) and is a new layer 2 scaling solution that is proposed to be introduced on the Mondaynet testnet with the Mumbai protocol upgrade.
ZK-rollups have been seen as the ‘holy-grail’ of rollups by many top engineers, due to instant finality, the ability to introduce different data availability layers, and all whilst maintaining privacy.
“Epoxy allows for applications to be built on Tezos which do not necessarily need to rely on Tezos’ Layer 1 to publish and distribute data, but rather can implement their own data availability layers.
This will enable building privacy-preserving solutions which require keeping sensitive information (reified as part of their state or transactions) private from the public Layer 1.”
Although ZK-rollups are very highly anticipated and benefit both security and privacy, they also come with their own set of challenges and limitations.
Nomadic Labs needed help in the form of OCaml 5 multicore and Tarides to overcome one of these.
The challenge Nomadic Labs faced was related to their proving system. In general, proving systems have to be very asymmetrical, with a prover doing most of the work off-chain and a lean verifier working on-chain.
Whilst these rollup systems are great for blockchains, because of how quickly they can verify something, the proving stage is very CPU- and memory-intensive.
This prevents the scalability of Epoxy, their zk-rollup solution, since its throughput and latency are directly limited by the speed of the prover.
This is where OCaml 5 Multicore entered the equation.
“The team’s solution to the prover’s inefficiencies was to use the aPlonK proving system to power Epoxy.
It enables the efficient aggregation of multiple proofs that can be executed in parallel.
This is where OCaml 5 comes in! With its Multicore capabilities and strong safety features, it is the perfect candidate for speeding up the proving process.
With OCaml 5, the team could parallelise the proving process by utilising multiple cores on one machine”
The end result is increased performance of the ZK-rollup translating to high TPS (transactions per second) and throughput.