Пример #1
0
    def delete_code(self, address):
        validate_canonical_address(address, title="Storage Address")

        key = get_code_key(address)
        self._check_accessibility(key)

        del self._trie[key]
Пример #2
0
 def get_code(self, address):
     validate_canonical_address(address)
     account = self._get_account(address)
     try:
         return self.db[account.code_hash]
     except KeyError:
         return b''
Пример #3
0
    def get_code(self, address):
        validate_canonical_address(address, title="Storage Address")

        try:
            return self._journaldb[self.get_code_hash(address)]
        except KeyError:
            return b""
Пример #4
0
    def set_balance(self, address, balance):
        validate_canonical_address(address, title="Storage Address")
        validate_uint256(balance, title="Account Balance")

        account = self._get_account(address)
        account.balance = balance
        self._set_account(address, account)
Пример #5
0
 def add_log_entry(self, account: bytes, topics: List[int],
                   data: bytes) -> None:
     validate_canonical_address(account, title="Log entry address")
     for topic in topics:
         validate_uint256(topic, title="Log entry topic")
     validate_is_bytes(data, title="Log entry data")
     self.log_entries.append((account, topics, data))
Пример #6
0
 def add_log_entry(self, account: Address, topics: List[int], data: bytes) -> None:
     validate_canonical_address(account, title="Log entry address")
     for topic in topics:
         validate_uint256(topic, title="Log entry topic")
     validate_is_bytes(data, title="Log entry data")
     self._log_entries.append(
         (self.transaction_context.get_next_log_counter(), account, topics, data))
Пример #7
0
    def set_code(self, address, code):
        validate_canonical_address(address, title="Storage Address")
        validate_is_bytes(code, title="Code")

        key = get_code_key(address)
        self._check_accessibility(key)

        self._trie[key] = code
Пример #8
0
    def set_balance(self, address, balance):
        validate_canonical_address(address)
        validate_uint256(balance)

        account = self._get_account(address)
        account.balance = balance

        self._set_account(address, account)
Пример #9
0
    def set_nonce(self, address, nonce):
        validate_canonical_address(address)
        validate_uint256(nonce)

        account = self._get_account(address)
        account.nonce = nonce

        self._set_account(address, account)
Пример #10
0
 def validate(self):
     validate_uint256(self.nonce)
     validate_is_integer(self.gas_price)
     validate_uint256(self.gas)
     if self.to != CREATE_CONTRACT_ADDRESS:
         validate_canonical_address(self.to)
     validate_uint256(self.value)
     validate_is_bytes(self.data)
Пример #11
0
    def register_account_for_deletion(self, beneficiary):
        validate_canonical_address(beneficiary)

        if self.msg.storage_address in self.accounts_to_delete:
            raise ValueError(
                "Invariant.  Should be impossible for an account to be "
                "registered for deletion multiple times")
        self.accounts_to_delete[self.msg.storage_address] = beneficiary
Пример #12
0
    def set_nonce(self, address, nonce):
        validate_canonical_address(address, title="Storage Address")
        validate_uint256(nonce, title="Nonce")

        account = self._get_account(address)
        account.nonce = nonce

        self._set_account(address, account)
Пример #13
0
    def set_balance(self, address, balance):
        validate_canonical_address(address, title="Storage Address")
        validate_uint256(balance, title="Account Balance")

        key = get_balance_key(address)
        self._check_accessibility(key)

        self._trie[key] = int_to_big_endian(balance)
Пример #14
0
    def set_code(self, address, code):
        validate_canonical_address(address, title="Storage Address")
        validate_is_bytes(code, title="Code")

        account = self._get_account(address)

        code_hash = keccak(code)
        self._journaldb[code_hash] = code
        self._set_account(address, account.copy(code_hash=code_hash))
Пример #15
0
 def validate(self):
     validate_uint256(self.nonce)
     validate_is_integer(self.gas_price)
     validate_uint256(self.gas)
     if self.to != CREATE_CONTRACT_ADDRESS:
         validate_canonical_address(self.to)
     validate_uint256(self.value)
     validate_is_bytes(self.data)
     super(FrontierUnsignedTransaction, self).validate()
Пример #16
0
 def validate(self):
     validate_uint256(self.nonce, title="Transaction.nonce")
     validate_is_integer(self.gas_price, title="Transaction.gas_price")
     validate_uint256(self.gas, title="Transaction.gas")
     if self.to != CREATE_CONTRACT_ADDRESS:
         validate_canonical_address(self.to, title="Transaction.to")
     validate_uint256(self.value, title="Transaction.value")
     validate_is_bytes(self.data, title="Transaction.data")
     super(FrontierUnsignedTransaction, self).validate()
Пример #17
0
    def __init__(self,
                 gas,
                 gas_price,
                 to,
                 sender,
                 value,
                 data,
                 code,
                 origin=None,
                 depth=0,
                 create_address=None,
                 code_address=None,
                 should_transfer_value=True,
                 is_static=False):
        validate_uint256(gas, title="Message.gas")
        self.gas = gas

        validate_uint256(gas_price, title="Message.gas_price")
        self.gas_price = gas_price

        if to != CREATE_CONTRACT_ADDRESS:
            validate_canonical_address(to, title="Message.to")
        self.to = to

        validate_canonical_address(sender, title="Message.sender")
        self.sender = sender

        validate_uint256(value, title="Message.value")
        self.value = value

        validate_is_bytes(data, title="Message.data")
        self.data = data

        if origin is not None:
            validate_canonical_address(origin, title="Message.origin")
        self.origin = origin

        validate_is_integer(depth, title="Message.depth")
        validate_gte(depth, minimum=0, title="Message.depth")
        self.depth = depth

        validate_is_bytes(code, title="Message.code")
        self.code = code

        if create_address is not None:
            validate_canonical_address(create_address, title="Message.storage_address")
        self.storage_address = create_address

        if code_address is not None:
            validate_canonical_address(code_address, title="Message.code_address")
        self.code_address = code_address

        validate_is_boolean(should_transfer_value, title="Message.should_transfer_value")
        self.should_transfer_value = should_transfer_value

        validate_is_boolean(is_static, title="Message.is_static")
        self.is_static = is_static
Пример #18
0
    def validate(self):
        super().validate()  # includes validation of `(int_)gas_price`

        validate_canonical_address(self.destination, "Transaction.destination")
        validate_uint256(self.value, "Transaction.value")
        validate_uint256(self.min_block, "Transaction.min_block")
        validate_uint256(self.max_block, "Transaction.max_block")
        validate_uint256(self.nonce, "Transaction.nonce")
        validate_is_bytes(self.msg_data, "Transaction.msg_data")
Пример #19
0
 def validate(self):
     validate_uint256(self.nonce, title="Transaction.nonce")
     validate_is_integer(self.gas_price, title="Transaction.gas_price")
     validate_uint256(self.gas, title="Transaction.gas")
     if self.to != CREATE_CONTRACT_ADDRESS:
         validate_canonical_address(self.to, title="Transaction.to")
     validate_uint256(self.value, title="Transaction.value")
     validate_is_bytes(self.data, title="Transaction.data")
     super(FrontierUnsignedTransaction, self).validate()
Пример #20
0
    def set_code(self, address, code):
        validate_canonical_address(address)
        validate_is_bytes(code)

        account = self._get_account(address)

        account.code_hash = keccak(code)
        self.db[account.code_hash] = code
        self._set_account(address, account)
Пример #21
0
    def register_account_for_deletion(self, beneficiary):
        validate_canonical_address(beneficiary, title="Self destruct beneficiary address")

        if self.msg.storage_address in self.accounts_to_delete:
            raise ValueError(
                "Invariant.  Should be impossible for an account to be "
                "registered for deletion multiple times"
            )
        self.accounts_to_delete[self.msg.storage_address] = beneficiary
Пример #22
0
    def get_balance(self, address):
        validate_canonical_address(address, title="Storage Address")

        key = get_balance_key(address)
        self._check_accessibility(key)

        if key in self._trie:
            return big_endian_to_int(self._trie[key])
        else:
            return 0
Пример #23
0
    def get_code(self, address):
        validate_canonical_address(address, title="Storage Address")

        key = get_code_key(address)
        self._check_accessibility(key)

        if key in self._trie:
            return self._trie[key]
        else:
            return b""
Пример #24
0
 def __init__(self, origin, sig_hash, transaction_gas_limit):
     validate_canonical_address(origin, title="TransactionContext.origin")
     self._origin = origin
     validate_sig_hash(sig_hash,
                       title="ShardingTransactionContext.sig_hash")
     self._sig_hash = sig_hash
     validate_uint256(
         transaction_gas_limit,
         title="ShardingTransactionContext.transaction_gas_limit",
     )
     self._transaction_gas_limit = transaction_gas_limit
Пример #25
0
 def account_is_empty(self, address):
     validate_canonical_address(address, title="Storage Address")
     account = self._get_account(address)
     if account.code_hash != EMPTY_SHA3:
         return False
     elif account.balance != 0:
         return False
     elif account.nonce != 0:
         return False
     else:
         return True
Пример #26
0
    def get_storage(self, address, slot):
        validate_canonical_address(address, title="Storage Address")
        validate_uint256(slot, title="Storage Slot")

        key = get_storage_key(address, slot)
        self._check_accessibility(key)

        if key in self._trie:
            return big_endian_to_int(self._trie[key])
        else:
            return 0
Пример #27
0
    def __init__(self,
                 gas,
                 gas_price,
                 to,
                 sender,
                 value,
                 data,
                 code,
                 origin=None,
                 depth=0,
                 create_address=None,
                 code_address=None,
                 should_transfer_value=True):
        validate_uint256(gas)
        self.gas = gas

        validate_uint256(gas_price)
        self.gas_price = gas_price

        if to != CREATE_CONTRACT_ADDRESS:
            validate_canonical_address(to)
        self.to = to

        validate_canonical_address(sender)
        self.sender = sender

        validate_uint256(value)
        self.value = value

        validate_is_bytes(data)
        self.data = data

        if origin is not None:
            validate_canonical_address(origin)
        self.origin = origin

        validate_is_integer(depth)
        validate_gte(depth, minimum=0)
        self.depth = depth

        validate_is_bytes(code)
        self.code = code

        if create_address is not None:
            validate_canonical_address(create_address)
        self.storage_address = create_address

        if code_address is not None:
            validate_canonical_address(code_address)
        self.code_address = code_address

        validate_is_boolean(should_transfer_value)
        self.should_transfer_value = should_transfer_value
Пример #28
0
    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")

        key = get_storage_key(address, slot)
        self._check_accessibility(key)

        if value:
            self._trie[key] = int_to_big_endian(value)
        else:
            del self._trie[key]
Пример #29
0
    def get_storage(self, address, slot):
        validate_canonical_address(address)
        validate_uint256(slot)

        account = self._get_account(address)
        storage = StateTrie(Trie(self.db, 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
Пример #30
0
    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
Пример #31
0
    def validate(self):
        validate_uint256(self.chain_id, title="Transaction.chain_id")
        validate_uint256(self.shard_id, title="Transaction.shard_id")

        validate_canonical_address(self.to, title="Transaction.to")
        validate_is_bytes(self.data, title="Transaction.data")

        validate_uint256(self.gas, title="Transaction.gas")
        validate_uint256(self.gas_price, title="Transaction.gas_price")

        validate_transaction_access_list(self.access_list, title="Transaction.access_list")

        validate_is_bytes(self.code, title="Transaction.code")

        super(ShardingTransaction, self).validate()
Пример #32
0
    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))
Пример #33
0
    def validate(self):
        validate_uint256(self.nonce, title="Transaction.nonce")
        validate_uint256(self.gas_price, title="Transaction.gas_price")
        validate_uint256(self.gas, title="Transaction.gas")
        if self.to != CREATE_CONTRACT_ADDRESS:
            validate_canonical_address(self.to, title="Transaction.to")
        validate_uint256(self.value, title="Transaction.value")
        validate_is_bytes(self.data, title="Transaction.data")

        validate_uint256(self.v, title="Transaction.v")
        validate_uint256(self.r, title="Transaction.r")
        validate_uint256(self.s, title="Transaction.s")

        validate_lt_secpk1n(self.r, title="Transaction.r")
        validate_gte(self.r, minimum=1, title="Transaction.r")
        validate_lt_secpk1n(self.s, title="Transaction.s")
        validate_gte(self.s, minimum=1, title="Transaction.s")

        validate_gte(self.v, minimum=27, title="Transaction.v")
        validate_lte(self.v, maximum=28, title="Transaction.v")

        super(FrontierTransaction, self).validate()
Пример #34
0
    def __init__(self,
                 gas,
                 to,
                 sender,
                 value,
                 data,
                 code,
                 depth=0,
                 create_address=None,
                 code_address=None,
                 should_transfer_value=True,
                 is_static=False):
        validate_uint256(gas, title="Message.gas")
        self.gas = gas

        if to != CREATE_CONTRACT_ADDRESS:
            validate_canonical_address(to, title="Message.to")
        self.to = to

        validate_canonical_address(sender, title="Message.sender")
        self.sender = sender

        validate_uint256(value, title="Message.value")
        self.value = value

        validate_is_bytes(data, title="Message.data")
        self.data = data

        validate_is_integer(depth, title="Message.depth")
        validate_gte(depth, minimum=0, title="Message.depth")
        self.depth = depth

        validate_is_bytes(code, title="Message.code")
        self.code = code

        if create_address is not None:
            validate_canonical_address(create_address, title="Message.storage_address")
        self.storage_address = create_address

        if code_address is not None:
            validate_canonical_address(code_address, title="Message.code_address")
        self.code_address = code_address

        validate_is_boolean(should_transfer_value, title="Message.should_transfer_value")
        self.should_transfer_value = should_transfer_value

        validate_is_boolean(is_static, title="Message.is_static")
        self.is_static = is_static
Пример #35
0
 def add_log_entry(self, account, topics, data):
     validate_canonical_address(account, title="Log entry address")
     for topic in topics:
         validate_uint256(topic, title="Log entry topic")
     validate_is_bytes(data, title="Log entry data")
     self.log_entries.append((account, topics, data))
Пример #36
0
 def __init__(self, gas_price, origin):
     validate_uint256(gas_price, title="TransactionContext.gas_price")
     self._gas_price = gas_price
     validate_canonical_address(origin, title="TransactionContext.origin")
     self._origin = origin
Пример #37
0
def test_validate_canonical_address(value, is_valid):
    if is_valid:
        validate_canonical_address(value)
    else:
        with pytest.raises(ValidationError):
            validate_canonical_address(value)