-
Notifications
You must be signed in to change notification settings - Fork 0
Integer Opcodes
Integer Opcodes
Author: Joonmo Yang<[email protected]>
Created: 2019-10-30
This CIP describes a new set of opcodes for CodeChain VM related to integer manipulation. It includes addition(ADD
), and comparison(GT
, LT
) opcodes.
One of the most common instructions in existing script systems are integer handling operations. CodeChain VM didn’t need them because commonly used scripts(eg. P2PK) don’t require such features. However, recent high-level language proposals like Vault need such features to be implemented. Adding the opcodes specified in this proposal will help adopting high-level languages for CodeChain and give more flexibility to the scripting system.
- Pop one value from the stack as an integer(refer this value as a)
- Pop one value from the stack as an integer(refer this value as b)
- Push true if a > b. Push false otherwise.
- Pop one value from the stack as an integer(refer this value as a)
- Pop one value from the stack as an integer(refer this value as b)
- Push true if a < b. Push false otherwise.
- Pop two values from the stack as integers and add them(refer to this value as a)
- If a is larger than or equal to 264, script fails immediately.
- Push a to the stack
-
PUSH 1 PUSH 2 GT
→ stack:[0x01]
-
PUSH 2 PUSH 1 GT
→ stack:[0x00]
-
PUSH 2 PUSH 1 LT
→ stack:[0x01]
-
PUSH 2 PUSH 1 ADD
→ stack:[0x03]
seulgi.kim I think you should specify that integers are unsigned or handle the case of the underflow.
jmyang CodeChain Virtual Machine spec specifies that stack items are decoded as unsigned 64bit integer. We don't have underflow since there are no subtraction opcode here.