示例#1
0
def validate_transaction_signature(transaction):
    vrs = (transaction.v, transaction.r, transaction.s)
    unsigned_transaction = transaction.as_unsigned_transaction()
    msg_hash = keccak(rlp.encode(unsigned_transaction))
    try:
        public_key = get_ecc_backend().ecdsa_raw_recover(msg_hash, vrs)
    except BadSignature as e:
        raise ValidationError("Bad Signature: {0}".format(str(e)))

    if not get_ecc_backend().ecdsa_raw_verify(msg_hash, vrs, public_key):
        raise ValidationError("Invalid Signature")
示例#2
0
def precompile_ecrecover(computation):
    computation.gas_meter.consume_gas(constants.GAS_ECRECOVER, reason="ECRecover Precompile")
    raw_message_hash = computation.msg.data[:32]
    message_hash = pad32r(raw_message_hash)

    v_bytes = pad32r(computation.msg.data[32:64])
    v = big_endian_to_int(v_bytes)

    r_bytes = pad32r(computation.msg.data[64:96])
    r = big_endian_to_int(r_bytes)

    s_bytes = pad32r(computation.msg.data[96:128])
    s = big_endian_to_int(s_bytes)

    try:
        validate_lt_secpk1n(r)
        validate_lt_secpk1n(s)
        validate_lte(v, 28)
        validate_gte(v, 27)
    except ValidationError:
        return computation

    try:
        raw_public_key = get_ecc_backend().ecdsa_raw_recover(message_hash, (v, r, s))
    except BadSignature:
        return computation

    public_key = encode_raw_public_key(raw_public_key)
    address = public_key_to_address(public_key)
    padded_address = pad32(address)

    computation.output = padded_address
    return computation
示例#3
0
def extract_transaction_sender(transaction):
    vrs = (transaction.v, transaction.r, transaction.s)
    unsigned_transaction = transaction.as_unsigned_transaction()
    raw_public_key = get_ecc_backend().ecdsa_raw_recover(
        keccak(rlp.encode(unsigned_transaction)),
        vrs,
    )
    public_key = encode_raw_public_key(raw_public_key)
    sender = public_key_to_address(public_key)
    return sender
def test_ecdsa_raw_recover():
    raw_public_key = get_ecc_backend().ecdsa_raw_recover(MSG_HASH, (V, R, S))
    assert raw_public_key == purePython.ecdsa_raw_recover(MSG_HASH, (V, R, S))
def test_ecdsa_recover():
    public_key = get_ecc_backend().ecdsa_recover(MSG, SIGNATURE)
    assert public_key == purePython.ecdsa_recover(MSG, SIGNATURE)
def test_ecdsa_raw_verify():
    is_valid = get_ecc_backend().ecdsa_raw_verify(MSG_HASH, (V, R, S), RAW_PUBLIC_KEY)
    assert is_valid is purePython.ecdsa_raw_verify(MSG_HASH, (V, R, S), RAW_PUBLIC_KEY)
def test_ecdsa_verify():
    is_valid = get_ecc_backend().ecdsa_verify(MSG, SIGNATURE, PUBLIC_KEY)
    assert is_valid is purePython.ecdsa_verify(MSG, SIGNATURE, PUBLIC_KEY)
def test_ecdsa_raw_sign():
    raw_signature = get_ecc_backend().ecdsa_raw_sign(MSG_HASH, PRIVATE_KEY)
    assert raw_signature == purePython.ecdsa_raw_sign(MSG_HASH, PRIVATE_KEY)
def test_ecdsa_sign():
    signature = get_ecc_backend().ecdsa_sign(MSG, PRIVATE_KEY)
    assert signature == purePython.ecdsa_sign(MSG, PRIVATE_KEY)
示例#10
0
def create_transaction_signature(unsigned_txn, private_key):
    v, r, s = get_ecc_backend().ecdsa_raw_sign(
        keccak(rlp.encode(unsigned_txn)), private_key)
    return v, r, s