Beispiel #1
0
def run_process_registry_updates(spec, state, valid=True):
    """
    Run ``process_crosslinks``, yielding:
      - pre-state ('pre')
      - post-state ('post').
    If ``valid == False``, run expecting ``AssertionError``
    """
    # transition state to slot before state transition
    slot = state.slot + (spec.SLOTS_PER_EPOCH -
                         state.slot % spec.SLOTS_PER_EPOCH) - 1
    block = build_empty_block_for_next_slot(spec, state)
    block.slot = slot
    sign_block(spec, state, block)
    state_transition(state, block)

    # cache state before epoch transition
    spec.process_slot(state)

    # process components of epoch transition before registry update
    spec.process_justification_and_finalization(state)
    spec.process_crosslinks(state)
    spec.process_rewards_and_penalties(state)

    yield 'pre', state
    spec.process_registry_updates(state)
    yield 'post', state
Beispiel #2
0
def FuzzerRunOne(FuzzerInput):
    state_block = translate_value(state_block_sedes.deserialize(FuzzerInput),
                                  StateBlock)
    prestate = copy.deepcopy(prestates[state_block.stateID])

    try:
        poststate = spec.state_transition(prestate, state_block.block, False)
        return serialize(poststate)
    except AssertionError as e:
        pass
    except IndexError:
        pass
Beispiel #3
0
def FuzzerRunOne(fuzzer_input):
    state_block = translate_value(block_sedes.deserialize(fuzzer_input),
                                  BlockTestCase)

    try:
        # NOTE we don't validate state root here
        poststate = spec.state_transition(
            state=state_block.pre,
            block=state_block.block,
            validate_state_root=VALIDATE_STATE_ROOT,
        )
        return serialize(poststate)
    except (AssertionError, IndexError):
        return None
Beispiel #4
0
def pyspec_transition(pre_state, pre_block):
    yaml = YAML(typ='base')
    loaded = yaml.load(Path('min.config.bak'))
    config_data = dict()
    for k, v in loaded.items():
        if v.startswith("0x"):
            config_data[k] = bytes.fromhex(v[2:])
        else:
            config_data[k] = int(v)

    spec.apply_constants_preset(config_data)

    spec_pre_state = decoder.translate_value(pre_state, spec.BeaconState)
    spec_pre_block = decoder.translate_value(pre_block, spec.BeaconBlock)

    spec_post_block = spec.state_transition(spec_pre_state, spec_pre_block,
                                            False)
    return spec_post_block
Beispiel #5
0
def blocks(pre, post, blocks):
    block_sources = blocks

    # Read and parse prestate
    pre_state = get_pre_state(pre)

    # Read and parse blocks
    blocks = []
    for block_source in block_sources:
        with open(block_source, 'rb') as f:
            block_raw_ssz = f.read()

        blocks.append(convert_raw_to_ssz(block_raw_ssz, spec.BeaconBlock))

    # Transition state
    state = pre_state
    for block in blocks:
        state = spec.state_transition(state, block)

    write_post_state(state, post)