Finding the call-depth limit on PolkaVM
A small recursive Solidity contract I used to test the call-depth limit on Westend Asset Hub. At the time, calls worked up to depth 5 and failed from depth 6.
PolkaVM runs Solidity contracts on Polkadot Hub alongside the EVM. On Ethereum, contracts can call each other around 1,024 levels deep. I wanted to see how far PolkaVM would go.
The setup
So I wrote a small contract that calls itself recursively, dropping the depth by one each time and emitting an event at every level:
contract DepthTester {
event ReachedDepth(uint256 depth);
function dive(uint256 depth) public {
emit ReachedDepth(depth);
if (depth > 0) {
DepthTester(address(this)).dive(depth - 1);
}
}
}
To run it, I used Hardhat with Parity’s plugin for Polkadot. It compiles the contract for PolkaVM and runs it against a local PolkaVM node. The test deploys the contract and calls dive(1), dive(2), dive(3) and so on, bumping the depth by one each time until a call fails. It logs every attempt and the last depth that worked.
What happened
Running the test gave me this:
Trying depth: 1
Trying depth: 2
Trying depth: 3
Trying depth: 4
Trying depth: 5
Caught error at depth: 6
Error message: execution reverted: Max call depth before failure: 5
After that, I deployed the contract to Westend Asset Hub, a Polkadot test network, and called it directly with cast. At depth 5 the transaction went through, and the event in the logs had the 5. At depth 6 it came back with execution reverted.
At the time, calls worked up to depth 5 and failed starting at depth 6. Honestly, that’s pretty far from the roughly 1,024 frames the EVM allows.