3

Instead of just having special native code for each precompiled contract, a client could have special gas metering for those (as it is their main purpose) but keep the logic as EVM instructions.

Would this be possible?

1 Answer 1

3

There's no reason they can't be implemented in the EVM, but that completely defeats the purpose. The reason precompiles are precompiles instead of just Solidity libraries that people deploy is because, since they're programmed in the client's language and compiled, they're orders of magnitude more efficient than writing them in EVM bytecode.

4
  • Thanks, I guess it is faster, but just wondering if it really makes a difference in practice.
    – elmattic
    Feb 3, 2019 at 22:39
  • but why are they not builtins then? like the keccak functions Jul 21 at 9:27
  • 1
    @David天宇Wong I assume what you're asking is why is keccak an opcode while some things are precompiles. The answer isn't precise. Generally though precompiles are used in cases where the input data is more complex. Most opcodes take 1, maybe 2 items off the stack, whereas many precompiles take 3+ different parameters. There's also the issue of opcode bloat - opcodes are 2 hex characters (1 byte), which is somewhat limited space, so things that don't necessarily make sense to be opcodes are more likely to be made into precompiles as to not use up the precious opcode space
    – natewelch_
    Jul 21 at 19:00
  • I guess I was also thrown out by the "precompiled" word, which seems to be implemented as native builtins in Golang (at least for geth) Jul 25 at 14:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.