Ejemplo n.º 1
0
 def sender(self):
     if not self._sender:
         if self.r >= secpk1n or self.s >= secpk1n or self.r == 0 or self.s == 0:
             raise InvalidTransaction("Invalid signature values!")
         if self.version == 0:
             pub = ecrecover_to_pub(self.hash_unsigned, self.v, self.r,
                                    self.s)
         if self.version == 1:
             pub = ecrecover_to_pub(self.hash_typed, self.v, self.r, self.s)
         if pub == b"\x00" * 64:
             raise InvalidTransaction(
                 "Invalid signature (zero privkey cannot sign)")
         self._sender = sha3_256(pub)[-20:]
     return self._sender
Ejemplo n.º 2
0
def proc_ecrecover(ext, msg):
    # print('ecrecover proc', msg.gas)
    OP_GAS = opcodes.GECRECOVER
    gas_cost = OP_GAS
    if msg.gas < gas_cost:
        return 0, 0, []

    message_hash_bytes = [0] * 32
    msg.data.extract_copy(message_hash_bytes, 0, 0, 32)
    message_hash = b''.join(map(ascii_chr, message_hash_bytes))

    # TODO: This conversion isn't really necessary.
    # TODO: Invesitage if the check below is really needed.
    v = msg.data.extract32(32)
    r = msg.data.extract32(64)
    s = msg.data.extract32(96)

    if r >= secp256k1n or s >= secp256k1n or v < 27 or v > 28:
        return 1, msg.gas - opcodes.GECRECOVER, []
    try:
        pub = utils.ecrecover_to_pub(message_hash, v, r, s)
    except Exception as e:
        return 1, msg.gas - gas_cost, []
    o = [0] * 12 + [safe_ord(x) for x in utils.sha3(pub)[-20:]]
    return 1, msg.gas - gas_cost, o
Ejemplo n.º 3
0
 def sender(self):
     if not self._sender:
         if self.r >= secpk1n or self.s >= secpk1n or self.r == 0 or self.s == 0:
             raise InvalidTransaction("Invalid signature values!")
         if self.version == 0:
             pub = ecrecover_to_pub(self.hash_unsigned, self.v, self.r,
                                    self.s)
         if self.version == 1:
             pub = ecrecover_to_pub(self.hash_typed, self.v, self.r, self.s)
         if self.version == 2:
             v = 35 - 27 + self.network_id * 2
             if self.v < v:
                 raise InvalidTransaction(
                     "Invalid signature (wrong v with tx version = 2)")
             v = self.v - v
             pub = ecrecover_to_pub(self.hash_unsigned, v, self.r, self.s)
         if pub == b"\x00" * 64:
             raise InvalidTransaction(
                 "Invalid signature (zero privkey cannot sign)")
         self._sender = sha3_256(pub)[-20:]
     return self._sender