def test_old_signature_scheme_does_not_work_any_longer(testlang, utxo):
    # In this test I will challenge standard exit with old signature schema to show it no longer works
    # Then passing new signature to the same challenge data, challenge will succeed
    alice = testlang.accounts[0]
    outputs = [(alice.address, NULL_ADDRESS, 50)]
    spend_id = testlang.spend_utxo([utxo.spend_id], [alice], outputs)

    testlang.start_standard_exit(spend_id, alice)
    exit_id = testlang.get_standard_exit_id(spend_id)

    # let's prepare old schema signature for a transaction with an input of exited utxo
    spend_tx = Transaction(inputs=[decode_utxo_id(spend_id)], outputs=outputs)
    old_signature = alice.key.sign_msg_hash(spend_tx.hash).to_bytes()

    # challenge will fail on signature verification
    with pytest.raises(TransactionFailed):
        testlang.root_chain.challengeStandardExit(exit_id, spend_tx.encoded, 0,
                                                  old_signature)

    # sanity check: let's provide new schema signature for a challenge
    new_signature = alice.key.sign_msg_hash(
        hash_struct(spend_tx,
                    verifying_contract=testlang.root_chain)).to_bytes()
    testlang.root_chain.challengeStandardExit(exit_id, spend_tx.encoded, 0,
                                              new_signature)
 def sign(self, index, account, verifying_contract=None):
     msg_hash = hash_struct(self, verifying_contract=verifying_contract)
     sig = account.key.sign_msg_hash(msg_hash)
     self.signatures[index] = amend_signature(sig.to_bytes())
     self._signers[index] = sig.recover_public_key_from_msg_hash(
         msg_hash).to_canonical_address(
         ) if sig != NULL_SIGNATURE else NULL_ADDRESS
Exemple #3
0
def test_signature_scheme_respects_verifying_contract(testlang, utxo):
    alice = testlang.accounts[0]
    outputs = [(alice.address, NULL_ADDRESS, 50)]
    spend_id = testlang.spend_utxo([utxo.spend_id], [alice.key], outputs)

    testlang.start_standard_exit(spend_id, alice.key)
    exit_id = testlang.get_standard_exit_id(spend_id)

    spend_tx = Transaction(inputs=[decode_utxo_id(spend_id)], outputs=outputs)

    bad_contract_signature = sign(hash_struct(spend_tx, verifyingContract=None), alice.key)

    # challenge will fail on signature verification
    with pytest.raises(TransactionFailed):
        testlang.root_chain.challengeStandardExit(exit_id, spend_tx.encoded, 0, bad_contract_signature)

    # sanity check
    proper_signature = sign(hash_struct(spend_tx, verifyingContract=testlang.root_chain), alice.key)
    testlang.root_chain.challengeStandardExit(exit_id, spend_tx.encoded, 0, proper_signature)
def test_signature_scheme_respects_verifying_contract(testlang, utxo):
    alice = testlang.accounts[0]
    outputs = [(alice.address, NULL_ADDRESS, 50)]
    exiting_tx_id = testlang.spend_utxo([utxo.spend_id], [alice], outputs)
    exiting_tx = testlang.child_chain.get_transaction(exiting_tx_id)

    testlang.start_standard_exit(exiting_tx_id, alice)
    exit_id = testlang.get_standard_exit_id(exiting_tx_id)

    spend_tx = Transaction(inputs=[decode_utxo_id(exiting_tx_id)], outputs=outputs)

    bad_contract_signature = amend_signature(alice.key.sign_msg_hash(hash_struct(spend_tx, verifying_contract=None)).to_bytes())

    # challenge will fail on signature verification
    with pytest.raises(TransactionFailed):
        testlang.root_chain.challengeStandardExit(exit_id, spend_tx.encoded, 0, bad_contract_signature, exiting_tx.encoded, keccak(hexstr=testlang.accounts[0].address))

    # sanity check
    proper_signature = amend_signature(alice.key.sign_msg_hash(hash_struct(spend_tx, verifying_contract=testlang.root_chain)).to_bytes())
    testlang.root_chain.challengeStandardExit(exit_id, spend_tx.encoded, 0, proper_signature, exiting_tx.encoded, keccak(hexstr=testlang.accounts[0].address))
def test_transaction_with_metadata(hash_lib_wrapper):
    tx = Transaction(inputs=inputs, outputs=outputs, metadata=metadata)
    assert hash_struct(tx, test_domain) == hash_lib_wrapper.hashTx(verifyingContract, tx.encoded)
def test_sample_transaction(hash_lib_wrapper):
    tx = Transaction(inputs=inputs, outputs=outputs)
    assert hash_struct(tx, test_domain) == hash_lib_wrapper.hashTx(verifyingContract, tx.encoded)
Exemple #7
0
def test_transaction_with_metadata():
    tx = Transaction(inputs=inputs, outputs=outputs, metadata=metadata)
    assert hash_struct(tx, test_domain).hex(
    ) == '5f9adeaaba8d2fa17de40f45eb12136c7e7f26ea56567226274314d0a563e81d'
Exemple #8
0
def test_sample_transaction():
    tx = Transaction(inputs=inputs, outputs=outputs)
    assert hash_struct(tx, test_domain).hex(
    ) == 'b42dc40570279af9faa05e64d62f54db0fd2b768a4a69646efba068cf88eb7a2'
Exemple #9
0
def test_empty_transaction():
    empty_tx = Transaction(inputs=[], outputs=[])
    assert hash_struct(empty_tx, test_domain).hex(
    ) == '992ac0f45bff7d9fb74636623e5d8b111b49b818cadcf3a91c035735a84d154f'
 def sign(self, index, key, verifyingContract=None):
     hash = hash_struct(self, verifyingContract=verifyingContract)
     sig = sign(hash, key)
     self.signatures[index] = sig
     self._signers[index] = get_signer(hash, sig) if sig != NULL_SIGNATURE else NULL_ADDRESS