The question is in the title :). Trying to understand why there is both an opcode and pre-compiled contract for SHA256. To execute the computation, would people canonically "CALL" into the pre-compiled contract or just use the SHA256 opcode directly?
1 Answer
As far as I'm aware there is no SHA256 opcode. I tried finding one but couldn't find - not listed at least in, for example, this list: https://github.com/crytic/evm-opcodes
Maybe you're mixing it up with sha3 (keccak256
)? It's a different algorithm.
So if you want to use SHA256 you need to call the precompiled contract. But if you're worried about gas costs there are cheaper alternatives around as well, quick googling found at least this: Gas cost of a sha256 hash
-
Follow-up question: what is the reason for implementing an operation as an opcode vs as a precompiled contract? The predicted frequency of uses only? Or is there a fundamental reason why sha256 couldn't be implemented as an opcode?– samlafDec 1, 2022 at 7:48
-