CPP-Ethereum libevm pow2N Code Execution Vulnerability
The pow2N function in libevm uses an unchecked index into a small array, allowing an out-of-bounds read that can return an unexpectedly large value. This value is used as a loop count in SIMD opcode handlers, causing an out-of-bounds write that can lead to remote code execution or denial of service.
Originally disclosed on Cisco Talos
An exploitable out-of-bounds read vulnerability exists in libevm (Ethereum Virtual Machine) of CPP-Ethereum. A specially crafted smart contract code can cause an out-of-bounds read which can subsequently trigger an out-of-bounds write resulting in remote code execution.
The full write-up lives on its author's site
It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
How it worked
Root cause
The pow2N function indexes a six-element array with an unchecked value, and the resulting out-of-bounds read can return a large value that is later used as a loop count without validation.
Impact
An attacker could cause remote code execution or a denial of service on all nodes using this implementation.
What the attacker needed
Ability to create/send a smart contract
How it was found
- Craft smart contract bytecode that pushes a value and then uses the XMLOAD opcode with a type byte of 8.
- The type byte 8 causes laneCount to read out-of-bounds from the exp array and return 0xF5.
- The large count is used in a loop that copies two bytes per iteration into a 32-byte stack element.
- The loop writes beyond the stack element, causing memory corruption and a crash.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
A smart contract is a small program that runs on the Ethereum network. The Ethereum Virtual Machine (EVM) is the part that executes these programs. In this case, a function that looks up a value in a small table did not check if the requested position was inside the table, so it could read memory beyond the table. That unexpected value was then used to control a loop that wrote data past the end of a buffer, corrupting memory and potentially letting an attacker run their own code.
What is Memory corruption?
Native code reads or writes memory it should not: overflows, use-after-free, type confusion. The core of browser, kernel and parser bugs.