Skip to content
This repository was archived by the owner on Jul 5, 2024. It is now read-only.

Enforce ExecutionState transition#110

Merged
han0110 merged 4 commits into
privacy-ethereum:masterfrom
han0110:feature/execution-state-transition
Mar 1, 2022
Merged

Enforce ExecutionState transition#110
han0110 merged 4 commits into
privacy-ethereum:masterfrom
han0110:feature/execution-state-transition

Conversation

@han0110
Copy link
Copy Markdown
Contributor

@han0110 han0110 commented Jan 29, 2022

This PR aims to add missing ExecutionState transition constraint. Currently there are 3 of ExecutionStates which need to be protected to avoid non-halting opcodes trying to halt unexpectedly. They are:

  • BeginTx - Can only from EndTx
  • EndTx - Can only from ExecutionState which halts or BeginTx
  • EndBlock - Can only from EndTx or EndBlock

Also it adds some missing ErrorOutOfGas cases and remove some unused information.

Comment thread src/zkevm_specs/evm/instruction.py Outdated
if self.next.execution_state == ExecutionState.BeginTx:
assert self.curr.execution_state == ExecutionState.EndTx
elif self.next.execution_state == ExecutionState.EndTx:
assert self.curr.execution_state.halts() or self.curr.execution_state == ExecutionState.BeginTx
Copy link
Copy Markdown
Collaborator

@DreamWuGit DreamWuGit Feb 11, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what is the case of the BeginTx direct follows by EndTx ?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When callee has empty code. But we could also remove this branch if we decide to always dive into call, even if code is empty.

@han0110 han0110 force-pushed the feature/execution-state-transition branch from ac5e5cf to 2a78c98 Compare February 24, 2022 14:11
@han0110 han0110 mentioned this pull request Feb 25, 2022
Copy link
Copy Markdown
Collaborator

@ChihChengLiang ChihChengLiang left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Comment on lines +22 to +23
for idx in range(len(steps) - 1):
curr, next = steps[idx], steps[idx + 1]
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could do something like

Suggested change
for idx in range(len(steps) - 1):
curr, next = steps[idx], steps[idx + 1]
for curr, _next in zip(steps, steps[1:]):

This works even if steps has 1 element.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just found we still need the idx, so I keep the current version. Also in #116, we can't extend the steps with a None, so iterating on range seems easier.

Comment thread src/zkevm_specs/evm/instruction.py
return [
(self, opcode, stack_pointer, 0) for opcode, stack_pointer in stack_overflow_pairs()
]
else:
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since you remove these tags from the fixed table, what will be the strategy to prove that that an opcode can be "invalid", be a "state write" or cause a "stack overflow/underflow"?

Also, with this deletion the functions invalid_opcodes, state_write_opcodes, stack_underflow_pairs and stack_overflow_pairs are no longer used. Will they be used elsewhere? Or can they be removed?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since you remove these tags from the fixed table, what will be the strategy to prove that that an opcode can be "invalid", be a "state write" or cause a "stack overflow/underflow"?

I am thinking we can put all these stuff in Fixed::ResponsibleOpcode, and make use of the unused fourth column as auxiliary data. I was planning to add them in the following PR, but let me add them now to make it clear.

For invalid opcodes, the ExecutionState::ErrorInvalidOpcode should be responsible for them (weird but I think it somehow makes sense).

For state write opcodes, we only use them when ExecutionState::ErrorWriteProtection, so it's responsible for them.

For stack overflow/underflow, we can reduce to a single state ExecutionState::ErrorStack, with the stack_pointer in fourth column.

Also, with this deletion the functions invalid_opcodes, state_write_opcodes, stack_underflow_pairs and stack_overflow_pairs are no longer used. Will they be used elsewhere? Or can they be removed?

I am going to add those pairs mentioned above into Fixed::ResponsibleOpcode sub-table, then these fns will be used.

Copy link
Copy Markdown
Contributor Author

@han0110 han0110 Feb 26, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Markdown and table are fixed in 044f4f6.

@ed255 ed255 mentioned this pull request Feb 25, 2022
@han0110 han0110 force-pushed the feature/execution-state-transition branch from 044f4f6 to 2501f3f Compare February 28, 2022 04:49
Comment thread src/zkevm_specs/evm/table.py Outdated
@ed255
Copy link
Copy Markdown
Contributor

ed255 commented Feb 28, 2022

A part from the possible typo mentioned in #110 (comment) the rest LGTM!

Co-authored-by: Eduard S. <eduardsanou@posteo.net>
@han0110 han0110 merged commit db1016a into privacy-ethereum:master Mar 1, 2022
@han0110 han0110 deleted the feature/execution-state-transition branch March 1, 2022 15:01
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants