Implement OP_ADD, OP_HASH160
In Bitcoin script, OP_ADD adds the top two items on the stack, while OP_HASH160 computes the RIPEMD160(SHA256(x)) hash of the top stack item.
Task
Complete the OP_ADD
and OP_HASH160
functions in challenges/OpcodeFunctions.js
:
- Implement
OP_ADD
to add the top two stack items, handling Bitcoin's number encoding. - Implement
OP_HASH160
to compute the RIPEMD160(SHA256(x)) hash of the top stack item.
Implementation
Ready to Code?
Choose your preferred language to begin
Hints
- Use the provided encodeNum and decodeNum functions for OP_ADD
- For OP_HASH160, use CryptoJS.SHA256 and CryptoJS.RIPEMD160
- Remember to handle edge cases like insufficient stack items
- The stack contains Buffer objects, not plain numbers
Solution
Solution Code
Test your implementation using the Bitcoin Opcode Simulator above. Try various inputs to ensure your opcodes handle different scenarios correctly.