-
Notifications
You must be signed in to change notification settings - Fork 212
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[interop] Epoch processing - SSZ hash of active_index_roots issue in final updates #373
Comments
Have we ruled out the possibility that |
If I skip the line active_index_roots: https://github.com/status-im/nim-beacon-chain/blob/297e9079d47f6070e06f425e8999eb46546029c8/beacon_chain/spec/state_transition_epoch.nim#L485-L494 The final state has the correct value (off-by-one processing maybe?) but we have the wrong committees root (skipped or not). It also needs to get the sszList treatment: Even with sszList we still have the wrong compact_committees_roots though. And in general, I think all our seq/arrays need to be revisited to make sure they use sszList. Note that at the moment sszList doesn't work with plain arrays due to maxChunksCount not supporting them, they need to be converted to seq first. Sidenote: int literals are not automatically converted to static int64 and return a confusing error (type mismatch with no highlight that it was the static failing) |
* Add sanity check for slot processing (also impacted by #373) * use reportDiff also for all state tests vs EF * initial sanity checks for blocks - workaround zero signature in block headers: #374 * Remove generic object variant compare commented code * Add the one block state transition sanity checks * generalize blocks test to multiple blocks * simplify slots test runner * Add official epoch transitions, sanity blocks, sanity slots to the test suite * Fix index out-of-bounds in initiate_validator_exit - enable proposer slashings unittest
I've tried to review all usages of The fixed-size array merkleization code seems to have an issue though - I'll try to push a fix tomorrow. Can you give me some pointers regarding how you run the same code in Python in order to compare the results? |
The first thing to do is extracting the python code from the markdown spec with: https://github.com/ethereum/eth2.0-specs/tree/dev/test_libs/pyspec#manual I suggest If needed the mocking proc are hidden in the utils folder: https://github.com/ethereum/eth2.0-specs/tree/dev/test_libs/pyspec/eth2spec/test/helpers The test generators for final updates is here: https://github.com/ethereum/eth2.0-specs/blob/dev/test_libs/pyspec/eth2spec/test/phase_0/epoch_processing/test_process_final_updates.py The dumps are generated here: https://github.com/ethereum/eth2.0-specs/blob/dev/test_libs/pyspec/eth2spec/test/phase_0/epoch_processing/run_epoch_process_base.py#L36 |
I've edited the original python code with debug prints on preset minimal. def process_final_updates(state: BeaconState) -> None:
current_epoch = get_current_epoch(state)
next_epoch = Epoch(current_epoch + 1)
# Reset eth1 data votes
if (state.slot + 1) % SLOTS_PER_ETH1_VOTING_PERIOD == 0:
state.eth1_data_votes = []
# Update effective balances with hysteresis
for index, validator in enumerate(state.validators):
balance = state.balances[index]
HALF_INCREMENT = EFFECTIVE_BALANCE_INCREMENT // 2
if balance < validator.effective_balance or validator.effective_balance + 3 * HALF_INCREMENT < balance:
validator.effective_balance = min(balance - balance % EFFECTIVE_BALANCE_INCREMENT, MAX_EFFECTIVE_BALANCE)
# Set active index root
index_epoch = Epoch(next_epoch + ACTIVATION_EXIT_DELAY)
index_root_position = index_epoch % EPOCHS_PER_HISTORICAL_VECTOR
indices_list = List[ValidatorIndex, VALIDATOR_REGISTRY_LIMIT](get_active_validator_indices(state, index_epoch))
print(f'\nstate hash_tree_root before: {hash_tree_root(state).hex()}')
print(f'indices_list: {indices_list}')
print(f'indices_list hash: {hash_tree_root(indices_list).hex()}')
state.active_index_roots[index_root_position] = hash_tree_root(indices_list)
# Set committees root
committee_root_position = next_epoch % EPOCHS_PER_HISTORICAL_VECTOR
state.compact_committees_roots[committee_root_position] = get_compact_committees_root(state, next_epoch)
# Reset slashings
state.slashings[next_epoch % EPOCHS_PER_SLASHINGS_VECTOR] = Gwei(0)
# Set randao mix
state.randao_mixes[next_epoch % EPOCHS_PER_HISTORICAL_VECTOR] = get_randao_mix(state, current_epoch)
... Here is the output:
And in our case (order is not kept and the OK is because I reused the test suite)
VALIDATOR_REGISTRY_LIMIT is correctly set at 1099511627776 so it seems like a ssz hashing bug of the 0 ..63 list |
As get_compact_committees_root has an issue beyond SSZ, I've opened a new issue here - #378, and will The new threads also has detailed reproduction instructions that you can use for this active_indices_root |
BTW, I had to resort to this patter of editing the Python spec myself while I was working on the SSZ suite. I think it would be valuable if we push our modifications to Status's own eth2.0-specs repo in order to make it easier for everyone to replicate the process. We can try to keep the individual testing modifications and scripts in separate branches that can be rebased and mixed in arbitrary ways. Here is my branch for SSZ tracing for example: https://github.com/status-im/eth2.0-specs/commits/ssz-tracing |
See #372 (comment)
Impacted line: https://github.com/status-im/nim-beacon-chain/blob/297e9079d47f6070e06f425e8999eb46546029c8/beacon_chain/spec/state_transition_epoch.nim#L488-L489
unit test: https://github.com/status-im/nim-beacon-chain/blob/297e9079d47f6070e06f425e8999eb46546029c8/tests/official/test_fixture_state_transition_epoch.nim#L83-L88
The text was updated successfully, but these errors were encountered: