Skip to content
This repository has been archived by the owner on Jul 1, 2021. It is now read-only.

Potential bug in state transition #727

Closed
ChihChengLiang opened this issue Jun 16, 2019 · 2 comments
Closed

Potential bug in state transition #727

ChihChengLiang opened this issue Jun 16, 2019 · 2 comments
Labels

Comments

@ChihChengLiang
Copy link
Contributor

ChihChengLiang commented Jun 16, 2019

What is wrong?

def apply_state_transition(self,
state: BeaconState,
block: BaseBeaconBlock,
check_proposer_signature: bool=True) -> BeaconState:
if state.slot >= block.slot:
return state
for _ in range(state.slot, block.slot):
state = self.cache_state(state)
if (state.slot + 1) % self.config.SLOTS_PER_EPOCH == 0:
state = self.per_epoch_transition(state)
state = self.per_slot_transition(state)
if state.slot == block.slot:
state = self.per_block_transition(state, block, check_proposer_signature)
break
else:
raise Exception(
f"Invariant: state.slot ({state.slot}) should be less "
f"than block.slot ({block.slot}) so that state transition terminates"
)
return state

There should be a per_block_transition on state.slot == slot for the case that the state is a pre-state of a block.

How can it be fixed

The spec now has a python state transition function specified, maybe can be fixed in #714.

@ralexstokes
Copy link
Member

@ChihChengLiang is this not what is happening on L55?

could you elaborate what you think is wrong or post a code snippet to illustrate the bug?

happy to update this code but i don't see the problem at the moment

@ChihChengLiang
Copy link
Contributor Author

This is no longer an issue after the spec update.

The issue was if a state is a pre-state of a block, then the state and the block has the same slot. So everything in the loop is noop, including L55.

In [1]: for _ in range(5, 5):
   ...:     print(_)
   ...:     
<nothing>

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

2 participants