def ecmul(computation): computation.consume_gas(constants.GAS_ECMUL, reason='ECMUL Precompile') try: result = _ecmull(computation.msg.data) except ValidationError: raise VMError("Invalid ECMUL parameters") result_x, result_y = result result_bytes = b''.join(( pad32(int_to_big_endian(result_x.n)), pad32(int_to_big_endian(result_y.n)), )) computation.output = result_bytes return computation
def get_message_for_signing(self, chain_id: int = None) -> bytes: if chain_id is None: chain_id = self.chain_id transaction_parts = rlp.decode(rlp.encode(self), use_list=True) transaction_parts_for_signature = transaction_parts[:-3] + [ int_to_big_endian(chain_id), b'', b'' ] message = rlp.encode(transaction_parts_for_signature) return message
def get_storage(self, address, slot): validate_canonical_address(address, title="Storage Address") validate_uint256(slot, title="Storage Slot") account = self._get_account(address) storage = HashTrie(HexaryTrie(self._journaldb, account.storage_root)) slot_as_key = pad32(int_to_big_endian(slot)) if slot_as_key in storage: encoded_value = storage[slot_as_key] return rlp.decode(encoded_value, sedes=rlp.sedes.big_endian_int) else: return 0
def modexp(computation): """ https://github.com/ethereum/EIPs/pull/198 """ gas_fee = _compute_modexp_gas_fee(computation.msg.data) computation.consume_gas(gas_fee, reason='MODEXP Precompile') result = _modexp(computation.msg.data) _, _, modulus_length = _extract_lengths(computation.msg.data) result_bytes = zpad_left(int_to_big_endian(result), to_size=modulus_length) computation.output = result_bytes return computation
def set_storage(self, address, slot, value): validate_uint256(value, title="Storage Value") validate_uint256(slot, title="Storage Slot") validate_canonical_address(address, title="Storage Address") account = self._get_account(address) storage = HashTrie(HexaryTrie(self._journaldb, account.storage_root)) slot_as_key = pad32(int_to_big_endian(slot)) if value: encoded_value = rlp.encode(value) storage[slot_as_key] = encoded_value else: del storage[slot_as_key] self._set_account(address, account.copy(storage_root=storage.root_hash))
def get_message_for_signing(self): if is_eip_155_signed_transaction(self): txn_parts = rlp.decode(rlp.encode(self)) txn_parts_for_signing = txn_parts[:-3] + [ int_to_big_endian(self.chain_id), b'', b'' ] return rlp.encode(txn_parts_for_signing) else: return rlp.encode( SpuriousDragonUnsignedTransaction( nonce=self.nonce, gas_price=self.gas_price, gas=self.gas, to=self.to, value=self.value, data=self.data, ))
def _pop(self, num_items, type_hint): for _ in range(num_items): if type_hint == constants.UINT256: value = self.values.pop() if isinstance(value, int): yield value else: yield big_endian_to_int(value) elif type_hint == constants.BYTES: value = self.values.pop() if isinstance(value, bytes): yield value else: yield int_to_big_endian(value) elif type_hint == constants.ANY: yield self.values.pop() else: raise TypeError( "Unknown type_hint: {0}. Must be one of {1}".format( type_hint, ", ".join((constants.UINT256, constants.BYTES)), ) )