implement EIP 2315 opcodes

This commit is contained in:
jangko 2020-11-25 17:09:10 +07:00
parent 5a78b8a5a7
commit a38882a9a0
No known key found for this signature in database
GPG Key ID: 31702AE10541E6B9
1 changed files with 23 additions and 4 deletions

View File

@ -544,15 +544,34 @@ op jumpDest, inline = true:
op beginSub, inline = true:
## 0x5c, Marks the entry point to a subroutine
discard
raise newException(OutOfGas, "Abort: Attempt to execute BeginSub opcode")
op returnSub, inline = true:
## 0x5d, Returns control to the caller of a subroutine.
discard
if c.returnStack.len == 0:
raise newException(OutOfGas, "Abort: invalid returnStack during ReturnSub")
# Other than the check that the return stack is not empty, there is no
# need to validate the pc from 'returns', since we only ever push valid
# values onto it via jumpsub.
c.code.pc = c.returnStack.popInt().safeInt
op jumpSub, inline = true:
op jumpSub, inline = true, jumpTarget:
## 0x5e, Transfers control to a subroutine.
discard
if jumpTarget >= c.code.len.u256:
raise newException(InvalidJumpDestination, "JumpSub destination exceeds code len")
let jt = jumpTarget.truncate(int)
c.code.pc = jt
let nextOpcode = c.code.peek
if nextOpcode != BeginSub:
raise newException(InvalidJumpDestination, "Invalid JumpSub destination")
if c.returnStack.len == 1023:
raise newException(FullStack, "Out of returnStack")
push: jt + 1
inc c.code.pc
# ##########################################
# 60s & 70s: Push Operations.