So is there some reason this is seemingly currently being done via a stateful (!) precompile rather than just a new opcode? A new opcode seems like it would fit better… it’s stateful, after all, and this seems to be just reading that state, not just doing computation? Everything about this has the characteristics of an opcode, not a precompile; it seems like the wrong mechanism is being used here. Is it to save on opcode space? There’s quite a lot of that still, so that hardly seems like a good reason to use this awkward, seemingly-incorrect mechanism.
we can always use the “last” opcode as a pointer to an extension table so in fact there is unlimited opcode address space
a big motivator for the stateful precompile approach is facilitating the migration to a stateless world w/ Verkle tries and stateless clients
having everything required for protocol execution live w/in the execution state means the state transition function can be a function of the pre state and next block, to get the post state; which is cleaner for stateful clients and makes proofs for stateless clients easier to manage
a close analog to the functionality provided in this EIP is the
BLOCKHASH opcode which just summons some history alongside the execution state – so now to validate an ethereum block you don’t need just the state but also this small buffer on the side of the last 256 hashes; this makes the stateless paradigm a bit more awkward so its better to design in the direction of 4788
there are even EIPs floating around to change
BLOCKHASH so that it follows the pattern of 4788
I have some questions regarding this EIP.
set 32 bytes of the execution block header after the last header field as of
FORK_TIMESTAMPto the 32 byte hash tree root of the parent beacon block
I am not sure how to interpret this. Does this imply that we add a new field to the block header after the last header field (such that we RLP encode this)? Or, do we first RLP-encode the block header and then add these 32 bytes…?
The new precompile (which it definitely is, since it does do some EVM behavior like SLOAD, but will not add these to warm slots to account for them) is located at
0xfffffffffffffffffffffffffffffffffffffffd. Why here? Why not in the precompile range
0x00..00ffff (see EIP-1352: Specify restricted address range for precompiles/system contracts, it is stagnant, but I was under the impression that those “low” addresses were indeed reserved for precompiles). I am mainly worried about RIPEMD160 scenarios (Clarification about when touchedness is reverted during state clearance · Issue #716 · ethereum/EIPs · GitHub). We can fix this on mainnet by sending 1 wei to this precompile (currently it has no eth). However since usually genesis files on testnets fill the precompiles in order to avoid this RIPEMD160 behavior, this
0xfffffffffffffffffffffffffffffffffffffffd address is not there. Is there a motivation to put this there, and not at a “low” address?
I’m not sure I follow how using a stateful precompile makes that any better (the state still has to be stored somewhere!), but good to at least know there’s some non-arbitrary reason for it.
there are even EIPs floating around to change BLOCKHASH so that it follows the pattern of 4788
Got a link?
I assumed the odd high address was to mark it as a stateful precompile rather than an ordinary one. But meanwhile I’m wondering, why -3 of all things, when (assuming people are setting aside high addresses in this way) -1 and -2 have yet to be taken?
Got a link?
the idea is that everything is under one object, namely the execution state, rather than the execution state and some additional context (like it is today for block hash)
the intention is to add a header field – I wrote it this way so it is independent of any other header fields as even in the last few weeks the header fields for EIP-4844 have been changing
it would be unexpected (and so we should assume this was not the intent) to do a completely new thing where we encode the header and then tack this extra data on
we decided on ACDE 163 to move this precompile to the low address range and I’ll be updating the EIP today
I see, thank you! That also seemingly explains why -2 wasn’t used… -2 was taken by this other proposed stateful precompile. (And I can imagine that -1 wasn’t used for other reasons.) Although going by below sounds like these are being moved to low addresses regardless.
I do have to say I don’t really understand the distinction being drawn, though. One way or another, you need this list to be stored somewhere. I don’t understand why it makes a difference whether it is stored somewhere available to an opcode, or stored somewhere avialable to a precompile.
Like, you say “right now you need the execution state and some additional context”, but that statement depends on defining “execution state” in a particular way, right? I would have just said that, because this list is accessible, that makes it part of the execution state. Evidently “execution state” has some technical meaning here that excludes this sort of thing, but even granting that, why does it make a difference? Why is the line that is being drawn a useful line to draw, such that doing it the precompile way is easier than doing it the opcode way? To me it just seems like they both require storing this information – which I would have called state information, though I suppose it doesn’t fall under what is technically being called state – somewhere, and it’s not clear why opcode vs precompile makes a difference…
I’d say the opcode vs precompile question is a bit different than the state design question.
Evidently “execution state” has some technical meaning here that excludes this sort of thing
when we say “execution state”, we mean the thing committed to by the state root in each block header
but assuming the beacon roots live somewhere, there is an access question – do we have an opcode or just frame it as a precompile so we can just leverage the
CALL infra? every opcode we add does introduce new semantics to the EVM virtual machine, whereas just
CALLing a precompile is something done all the time so its less of a ask to just go via
Should this precompile go OOG if the input length is not 32 bytes?
not sure – what do other precompiles do here?
Blake2F throws, ecrecover pads input with zeros to get the expected 129 bytes length. It should be noted though what should happen if < 32 bytes are given as input: do we left- or right-pad the storage key with zeros in order to retrieve it? (And if there are more than 32 bytes, just take the first 32 bytes)
I want to raise a point regarding gas, but I do not want to make the EIP implementation more complex:
What if someone sends a transaction with one of these storage slots warm? We could lower the gas (but yes, this would make the implementation more complex)
i’m not too worried about this, and someone could prototype a verification of say a validator balance to ensure it doesn’t feel too expensive
one option if it was a problem is either (1) update precompile in future fork, (2) have a “caching” contract that proxies to the precompile so you get the warm/cold gas distinction
more than 32, just take the first 32
less should throw
lmk if see anything we should change
I mean, new precompiles add more semantics too! Both need to be specified. I’m just saying it’s a little confusing because doesn’t match the roles of opcodes and precompiles as they’ve existed so far. Getting information about the environment has been the province of opcodes, precompiles are for complicated computations. Well, except for 0x4… but that oversight is being rectified with the addition of MCOPY!
Why don’t you deploy the real bytecode at the given address instead of trying to describe what it suppose to do in pseudocode? And come up with some arbitrary gas cost of this?
This strongly resonates with me. I also wonder.
Some historical context, this approach was once suggested for blockhash, with EIP-210: Blockhash refactoring
@axic already posted that link, however, I think that was early in the discussion, when the beacon root EIP also included an opcode? Later on, the opcode was dropped, and the EIP is now in a situation where it could be replaced by:
- A contract
- A system-call to
X, invoking it with the latest beaconroot+number at the start of block processing.
X would store new values if the
sender is system-address, otherwise respond with the value requested (as per the pseudo-code in the current version of the EIP).
The address of
X could either be pre-determined, like a precompile, or we could just create it with CREATE2 in advance – before the hardfork, and then just ‘bless it’ at cancun by beginning the population of values (optional: the ‘blessing’ could also include auto-inclusion into the prepopulated access-list).
In that case, the core of the EIP would basically be:
At the start of processing any execution block where
block.timestamp >= FORK_TIMESTAMP(i.e. before processing any transactions), make a transaction to the
HISTORY_STORAGE_ADDRESS, with calldata
The internals of what the contract does would not be consensus-critical (any more than other contract internals)