evmone icon indicating copy to clipboard operation
evmone copied to clipboard

EOF: Nested container validation without recursion

Open gumb0 opened this issue 1 year ago • 0 comments

Currently nested containers are validated by recursive calls to validation function (see eof-create4 branch). Subcontainers are validated before instruction validation of parent container, because CREATE3 validation requires to know whether target child container is truncated or not.

Recursion is potentially attackable by nesting containers many levels deep causing client's stack overflow. It is better to rewrite is as interation, here is a sketch of an algorithm:

worklist = queue(parent_container)

while worklist not empty:
  container = worklist.dequeue()
  header = validate_header(container)
  
  subcontainer_headers = {}
  for all subcontainers in header:
    subcont_header = validate_header(subcontainer)
    subcontainer_header.push_back(subcontainer_header)
    worklist.queue(subcontainer)

  validate_instructions(container, subcontainer_headers)
  validate_stack(container) etc.

Essentially you need to validate child container headers before validating instructions of the parent one.

gumb0 avatar Jan 15 '24 12:01 gumb0