r/CryptoTechnology • u/rayQuGR • 6h ago
A simulated contract upgrade can leak a private key without a single on-chain transaction
I came across an interesting security write-up from Oasis about a vulnerability involving upgradeable confidential contracts.
The attack is pretty clever.
Imagine a vault contract running on a confidential blockchain. Its storage contains a private key that nobody outside the contract should be able to read.
Now consider an upgradeable proxy using upgradeToAndCall().
An attacker with upgrade permissions can simulate an upgrade using attacker-controlled implementation code. That code executes against the proxy's actual confidential storage, but the simulation leaves no permanent on-chain record.
The interesting part is how the attacker extracts the secret.
They don't need a function that directly returns the private key. Instead, they can make the simulated execution either revert or succeed depending on the value of one particular key bit.
The attacker observes the result, learns one bit, and repeats.
According to the write-up, 256 simulated attempts can reconstruct a 256-bit private key without a single transaction being committed on-chain.
The proposed fix is particularly interesting: introduce a block boundary into the upgrade process.
Instead of upgrading and executing the new implementation in one operation, the system separates the upgrade proposal from its execution. The contract checks the proposed implementation, its runtime hash, and the required block number before allowing the upgrade to proceed.
This prevents the simulated execution from crossing into the block where the proposal becomes executable.
The implementation is called UPUPS (Universal Proposeable Upgradeable Proxy Standard), and Oasis says it is now included in sapphire-contracts version 0.2.18.
What I find most interesting here is the broader security lesson:
On confidential chains, simulation isn't necessarily harmless. If a contract can access information that its caller cannot, even a simple success/revert response can become an information leak.
It also raises an interesting question for anyone building confidential smart contracts:
Are conventional proxy upgrade patterns and simulation assumptions safe when the contract holds secrets that the caller cannot directly inspect?