Esempio n. 1
0
def test_get_contribution_and_proof_signature(spec, state):
    privkey = privkeys[3]
    pubkey = pubkeys[3]

    contribution_and_proof = spec.ContributionAndProof(
        aggregator_index=10,
        contribution=spec.SyncCommitteeContribution(
            slot=10,
            beacon_block_root=b'\x12' * 32,
            subcommittee_index=1,
            aggregation_bits=spec.Bitvector[spec.SYNC_COMMITTEE_SIZE //
                                            spec.SYNC_COMMITTEE_SUBNET_COUNT]
            (),
            signature=b'\x34' * 96,
        ),
        selection_proof=b'\x56' * 96,
    )
    contribution_and_proof_signature = spec.get_contribution_and_proof_signature(
        state,
        contribution_and_proof,
        privkey,
    )
    contribution = contribution_and_proof.contribution
    domain = spec.get_domain(state, spec.DOMAIN_CONTRIBUTION_AND_PROOF,
                             spec.compute_epoch_at_slot(contribution.slot))
    signing_root = spec.compute_signing_root(contribution_and_proof, domain)
    assert bls.Verify(pubkey, signing_root, contribution_and_proof_signature)
def run_get_signature_test(spec,
                           state,
                           obj,
                           domain,
                           get_signature_fn,
                           privkey,
                           pubkey,
                           signing_ssz_object=None):
    if signing_ssz_object is None:
        signing_ssz_object = obj
    signature = get_signature_fn(state, obj, privkey)
    signing_root = spec.compute_signing_root(signing_ssz_object, domain)
    assert bls.Verify(pubkey, signing_root, signature)
Esempio n. 3
0
def test_get_sync_committee_selection_proof(spec, state):
    slot = 1
    subcommittee_index = 0
    privkey = privkeys[1]
    sync_committee_selection_proof = spec.get_sync_committee_selection_proof(
        state,
        slot,
        subcommittee_index,
        privkey,
    )

    domain = spec.get_domain(state, spec.DOMAIN_SYNC_COMMITTEE_SELECTION_PROOF,
                             spec.compute_epoch_at_slot(slot))
    signing_data = spec.SyncAggregatorSelectionData(
        slot=slot,
        subcommittee_index=subcommittee_index,
    )
    signing_root = spec.compute_signing_root(signing_data, domain)
    pubkey = pubkeys[1]
    assert bls.Verify(pubkey, signing_root, sync_committee_selection_proof)
Esempio n. 4
0
def case02_verify():
    for i, privkey in enumerate(PRIVKEYS):
        for message in MESSAGES:
            # Valid signature
            signature = bls.Sign(privkey, message)
            pubkey = bls.SkToPk(privkey)

            assert milagro_bls.SkToPk(to_bytes(privkey)) == pubkey
            assert milagro_bls.Sign(to_bytes(privkey), message) == signature

            identifier = f'{encode_hex(pubkey)}_{encode_hex(message)}'

            assert bls.Verify(pubkey, message, signature)
            assert milagro_bls.Verify(pubkey, message, signature)

            yield f'verify_valid_case_{(hash(bytes(identifier, "utf-8"))[:8]).hex()}', {
                'input': {
                    'pubkey': encode_hex(pubkey),
                    'message': encode_hex(message),
                    'signature': encode_hex(signature),
                },
                'output': True,
            }

            # Invalid signatures -- wrong pubkey
            wrong_pubkey = bls.SkToPk(PRIVKEYS[(i + 1) % len(PRIVKEYS)])
            identifier = f'{encode_hex(wrong_pubkey)}_{encode_hex(message)}'
            assert not bls.Verify(wrong_pubkey, message, signature)
            assert not milagro_bls.Verify(wrong_pubkey, message, signature)
            yield f'verify_wrong_pubkey_case_{(hash(bytes(identifier, "utf-8"))[:8]).hex()}', {
                'input': {
                    'pubkey': encode_hex(wrong_pubkey),
                    'message': encode_hex(message),
                    'signature': encode_hex(signature),
                },
                'output': False,
            }

            # Invalid signature -- tampered with signature
            tampered_signature = signature[:-4] + b'\xFF\xFF\xFF\xFF'
            identifier = f'{encode_hex(pubkey)}_{encode_hex(message)}'
            assert not bls.Verify(pubkey, message, tampered_signature)
            assert not milagro_bls.Verify(pubkey, message, tampered_signature)
            yield f'verify_tampered_signature_case_{(hash(bytes(identifier, "utf-8"))[:8]).hex()}', {
                'input': {
                    'pubkey': encode_hex(pubkey),
                    'message': encode_hex(message),
                    'signature': encode_hex(tampered_signature),
                },
                'output': False,
            }

    # Invalid pubkey and signature with the point at infinity
    assert not bls.Verify(Z1_PUBKEY, SAMPLE_MESSAGE, Z2_SIGNATURE)
    assert not milagro_bls.Verify(Z1_PUBKEY, SAMPLE_MESSAGE, Z2_SIGNATURE)
    yield f'verify_infinity_pubkey_and_infinity_signature', {
        'input': {
            'pubkey': encode_hex(Z1_PUBKEY),
            'message': encode_hex(SAMPLE_MESSAGE),
            'signature': encode_hex(Z2_SIGNATURE),
        },
        'output': False,
    }
Esempio n. 5
0
    'b12af968a0f2b6f55b448dd395a3cc2a88b07f902cbddc1ec735dde573c6cad67c099241c50ce9e856a7a2c6ef3f8f08105d3ed5227bcee0356d3a471748bcd445c4f4471d540b3049fa324d519b0bd13e16dbcb340ebc90f165f005fa81ff7d'
)
deposit_root = Root(
    'ba066d557b3b27a55ae129f01c569dff5daa9ca8a3e45f13188dcb1ac01cb1c5')

fork_version = Version('0x00000001')

deposit_message = DepositMessage(
    pubkey=pubkey,
    withdrawal_credentials=withdrawal_creds,
    amount=amount,
)
domain = compute_domain(domain_type=DOMAIN_DEPOSIT, fork_version=fork_version)
signing_root = compute_signing_root(deposit_message, domain)

if bls.Verify(pubkey, signing_root, signature):
    print("GOOD signature")
else:
    print("BAD signature")

deposit_data = DepositData(
    pubkey=pubkey,
    withdrawal_credentials=withdrawal_creds,
    amount=amount,
    signature=signature,
)
if deposit_data.hash_tree_root() == deposit_root:
    print("GOOD deposit root")
else:
    print("BAD deposit root")