The More-Minimal Proxy

0age
Coinmonks
4 min readDec 13, 2019

--

If you’ve ever looked into how to cheaply deploy contracts at scale, you’ve probably encountered EIP-1167. These minimal proxy contracts perform a DELEGATECALL to a fixed address, and they do it with only 45 bytes (or even less if you’re proxying to a compact address that starts with zero bytes), which makes it much more efficient to deploy, with the tradeoff of some increased overhead to use it thereafter.

The standard is proliferating, and with good reason — it’s a great idea for a set of contracts with duplicate logic to only have that logic to live in one place (as long as nobody takes that logic and accidentally kills it, that is). For example, it’s now part of the OpenZeppelin SDK (they just published a great primer on how EIP-1167 works). Hell, I myself wrote a library a while back for the Erasure protocol called Spawner that spits out EIP-1167 proxies. Point being, this EIP is now in single-digit company of ERCs that are actually being adopted in the wild.

And that’s why I want to address something that’s been bothering me about EIP-1167 before it reaches critical mass. Namely, this: it’s not as minimal as it could be.

Here’s the bytecode in question, spelled out in the parlance of the EIP itself:

So what jumps out at you when you scan through this? I’ll tell you what jumps out at me — the swap opcodes. We can do better:

See? One less swap, and a returndatasize instead of a dup to boot. This translates to 200 less gas to deploy (one fewer byte of runtime code) and 4 less gas to call (the swap we got rid of costs three gas, and returndatasize costs one less gas than dup).

It’s objective improvement, but is it worth the extra effort to update all the tooling, or maybe even modify the EIP or draft a new one? I have no idea. Let me know if you have strong opinions one way or the other.

Get Best Software Deals Directly In Your Inbox

--

--

0age
Coinmonks

Head of Protocol Development @ OpenSea (views are my own)