How to add an opcode to Tezos
Purpose
For Maintenance
Procedures
For LEVEL opcode, it was easier because NOW is has close characteristic and so just grep-ed and added.
You can test it via tests_python dir.
For KECCAK256 opcode, it will resemble to BLAKE2B opcode.
This is the keccak256 in OCaml link Hard things:
Type casting
You need to cast Tezos type into Michelson type. It's somehow tricky. link Each type has of_int and to_int interface. We can use it.
Be careful that there's of_int32, of_int64, to_int32 and , to_int64. Tezos typing likes it but Michelson doesn't understand these types.
Non exhaustive enum matching link Each opcode has each type and OCaml has type matcher. The Tezos codebase is saying that "If you add an opcode into enum type, type checker will tell you where to change".
But in reality, some of pattern matcher is squashing via wildcard case matching. And this is OCaml's unsafe anti-pattern.
To solve this, you have to remove willcard case and list all possible types as the matchable cases.