design icon indicating copy to clipboard operation
design copied to clipboard

Use invalid opcode as part of the eWASM magic

Open axic opened this issue 9 years ago • 9 comments

Following the discussion: https://github.com/ethereum/evm2.0-design/pull/20#discussion_r73419436

axic avatar Aug 14 '16 12:08 axic

@chriseth since you mentioned the requirement for this, can you please explain why we should have it?

axic avatar Oct 08 '16 11:10 axic

The idea is that multiple versions of evm bytecode can be introduced with limited backwards-compatibility breaks. We can at least be rather sure that no useful existing contract can have the same bytecode (prefix) as an ewasm contract.

chriseth avatar Nov 07 '16 13:11 chriseth

We can at least be rather sure that no useful existing contract can have the same bytecode (prefix) as an ewasm contract.

Currently all wasm binaries a prefixed with 0x00, which is stop. Wouldn't that eliminate all useful contracts?

wanderer avatar Nov 07 '16 15:11 wanderer

This aims for a general standard to select the proper VM for a given bytecode, without having to add metadata to an account. Since we do not have a VM identifier for EVM1, anything is valid EVM1. In order to avoid cases where an existing contract written for EVM1 is mistaken for eWASM bytecode which would change its semantics, I would propose to take a first byte that cannot be the start of a contract that is in use, and I think 0xef is more likely to fulfil that purpose than 0x00.

chriseth avatar Nov 07 '16 16:11 chriseth

right, so if we go that route we probably should drop the wasm magic number 0x00, 0x61, 0x73, 0x6d and replace it with just a single 0xfe

wanderer avatar Nov 07 '16 16:11 wanderer

No, I still think that a kind of version number of VM identifier should follow the 0xfe because that allows for upgrading the VM much more easily.

chriseth avatar Nov 08 '16 12:11 chriseth

0x00, 0x61, 0x73, 0x6d ("0asm") is wasm identifier, it is followed the version number (0x01). So if we replaced the identifier then we would still have the version number to go off of for future upgrades

wanderer avatar Nov 08 '16 14:11 wanderer

I would argue this is not needed, because wasm cannot be introduced without the client knowing about it, and if it does, it can easily detect the "wasm magic" as a pattern.

axic avatar Jun 29 '18 12:06 axic

In theory it would be nice for a client to be able to implement some, but not all, VMs and to be able to detect which VM a particular piece of contract bytecode targets, so that it can choose to execute that contract or not -- this wouldn't make sense for main chain but it could make sense for a private network, or maybe for a hypothetical world where different shards run different VMs. It would be nice to maintain optionality.

lrettig avatar Jun 29 '18 15:06 lrettig