mirror of
https://github.com/status-im/EIPs.git
synced 2025-02-23 20:28:21 +00:00
Automatically merged updates to draft EIP(s) 2315 (#3380)
Hi, I'm a bot! This change was automatically merged because: - It only modifies existing Draft, Review, or Last Call EIP(s) - The PR was approved or written by at least one author of each modified EIP - The build is passing
This commit is contained in:
parent
b7c7561f9f
commit
324ca88a48
@ -153,20 +153,20 @@ The following is a pseudo-go specification of an algorithm for enforcing program
|
|||||||
bytecode []byte
|
bytecode []byte
|
||||||
stack_depth []int
|
stack_depth []int
|
||||||
SP := 0
|
SP := 0
|
||||||
validate(PC :=0)
|
validate(PC :=0) {
|
||||||
{
|
|
||||||
// traverse code sequentially, recurse for subroutines and conditional jumps
|
// traverse code sequentially, recurse for subroutines and conditional jumps
|
||||||
while true
|
while true {
|
||||||
{
|
|
||||||
instruction = bytecode[PC]
|
instruction = bytecode[PC]
|
||||||
if is_invalid(instruction)
|
if is_invalid(instruction) {
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
// if stack depth set we have been here before
|
// if stack depth non-zero we have been here before
|
||||||
// check for constant depth and return to break cycle
|
// check for constant depth and return to break cycle
|
||||||
if stack_depth[PC] != 0 {
|
if stack_depth[PC] != 0 {
|
||||||
if SP != stack_depth[PC]
|
if SP != stack_depth[PC] {
|
||||||
return false
|
return false
|
||||||
|
}
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
stack_depth[PC] = SP
|
stack_depth[PC] = SP
|
||||||
@ -174,62 +174,70 @@ The following is a pseudo-go specification of an algorithm for enforcing program
|
|||||||
// effect of instruction on stack
|
// effect of instruction on stack
|
||||||
SP -= removed_items(instruction)
|
SP -= removed_items(instruction)
|
||||||
SP += added_items(instruction)
|
SP += added_items(instruction)
|
||||||
if SP < 0 || 1024 < SP
|
if SP < 0 || 1024 < SP {
|
||||||
return false
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
// successful validation of path
|
// successful validation of path
|
||||||
if instruction == STOP, RETURN, or SUICIDE
|
if instruction == STOP, RETURN, or SUICIDE {
|
||||||
return true
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
if instruction == JUMP {
|
||||||
|
|
||||||
if instruction == JUMP
|
|
||||||
{
|
|
||||||
// check for constant and correct destination
|
// check for constant and correct destination
|
||||||
if (bytecode[PC - 33] != PUSH32)
|
if (bytecode[PC - 33] != PUSH32) {
|
||||||
return false
|
return false
|
||||||
|
}
|
||||||
PC = stack[PC-32]
|
PC = stack[PC-32]
|
||||||
if byte_code[PC] != JUMPDEST
|
if byte_code[PC] != JUMPDEST {
|
||||||
return false
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
// reset PC to destination of jump
|
// reset PC to destination of jump
|
||||||
PC = stack[PC-32]
|
PC = stack[PC-32]
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if instruction == JUMPI
|
if instruction == JUMPI {
|
||||||
{
|
|
||||||
// check for constant and correct destination
|
|
||||||
if (bytecode[PC - 33] != PUSH32)
|
|
||||||
return false
|
|
||||||
PC = stack[PC-32]
|
|
||||||
if byte_code[PC] != JUMPDEST
|
|
||||||
return false
|
|
||||||
|
|
||||||
// recurse to jump to code to validate
|
// check for constant and correct destination
|
||||||
if !validate(stack[SP]))
|
if (bytecode[PC - 33] != PUSH32) {
|
||||||
return false
|
return false
|
||||||
|
}
|
||||||
|
PC = stack[PC-32]
|
||||||
|
if byte_code[PC] != JUMPDEST {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
// recurse to jump to code to validate
|
||||||
|
if !validate(stack[SP])) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if instruction == JUMPSUB
|
if instruction == JUMPSUB {
|
||||||
{
|
|
||||||
// check for constant and correct destination
|
// check for constant and correct destination
|
||||||
if (bytecode[PC - 33] != PUSH32)
|
if (bytecode[PC - 33] != PUSH32)
|
||||||
return false
|
return false
|
||||||
prevPC = PC
|
prevPC = PC
|
||||||
PC = stack[PC-32]
|
PC = stack[PC-32]
|
||||||
if byte_code[PC] != BEGINSUB
|
if byte_code[PC] != BEGINSUB {
|
||||||
return false
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
// recurse to jump to code to validate
|
// recurse to jump to code to validate
|
||||||
prevSP = SP
|
prevSP = SP
|
||||||
depth = SP - prevSP
|
depth = SP - prevSP
|
||||||
SP = depth
|
SP = depth
|
||||||
if !validate(stack[SP]+1))
|
if !validate(stack[SP]+1)) {
|
||||||
return false
|
return false
|
||||||
|
}
|
||||||
SP = prevSP - depth + SP
|
SP = prevSP - depth + SP
|
||||||
PC = prevPC
|
PC = prevPC
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if instruction == RETURNSUB
|
if instruction == RETURNSUB {
|
||||||
{
|
|
||||||
// successful return from recursion
|
// successful return from recursion
|
||||||
PC = prevPC
|
PC = prevPC
|
||||||
return true
|
return true
|
||||||
|
Loading…
x
Reference in New Issue
Block a user