Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/api/common_classes/address.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ The `Address` class represents an Ethereum address in Titanoboa. It provides a t

```python
import boa
from boa import Address
from boa.util.abi import Address

# From hex string
addr1 = Address("0x0000000000000000000000000000000000000001")
Expand Down
2 changes: 1 addition & 1 deletion docs/api/common_classes/deployer.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ Create a contract instance at an existing address.
existing = deployer.at("0x1234567890123456789012345678901234567890")

# Works with Address objects too
from boa import Address
from boa.util.abi import Address
addr = Address("0x1234567890123456789012345678901234567890")
existing = deployer.at(addr)
```
Expand Down
41 changes: 35 additions & 6 deletions docs/api/env/env.md
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ A wrapper class around py-evm which provides a "contract-centric" API. More deta

## `execute_code`

!!! function "`boa.env.execute_code() -> bytes`"
!!! function "`boa.env.execute_code() -> ComputationAPI`"

**Description**

Expand All @@ -191,7 +191,17 @@ A wrapper class around py-evm which provides a "contract-centric" API. More deta

**Returns**

The return value from the top-level call.
A `ComputationAPI` object containing the execution result. Key attributes include:
- `output`: The return data as bytes
- `is_error`: Boolean indicating if the execution failed
- `error`: The exception if execution failed
- `gas_used`: Amount of gas consumed

---

**Note**

Unlike `raw_call`, this method returns the computation object directly without raising exceptions on errors.

---

Expand Down Expand Up @@ -524,12 +534,11 @@ A wrapper class around py-evm which provides a "contract-centric" API. More deta

## `raw_call`

!!! function "`boa.env.raw_call(to_address) -> bytes`"
!!! function "`boa.env.raw_call(to_address) -> ComputationAPI`"

**Description**

TODO too many details this should go in the explain section
Simple wrapper around `execute_code`, to execute as if the contract is being called from an EOA.
Execute a call to a contract address, simulating an EOA transaction.

---

Expand All @@ -540,12 +549,32 @@ A wrapper class around py-evm which provides a "contract-centric" API. More deta
- `gas`: The gas limit provided for the execution (a.k.a. `msg.gas`).
- `value`: The ether value to attach to the execution (a.k.a `msg.value`).
- `data`: The data to attach to the execution (a.k.a. `msg.data`).
- `simulate`: If True, the call is executed in a context that is rolled back after execution.

---

**Returns**

The return value from the top-level call.
A `ComputationAPI` object containing the execution result. Key attributes include:
- `output`: The return data as bytes
- `is_error`: Boolean indicating if the execution failed
- `error`: The exception if execution failed
- `gas_used`: Amount of gas consumed

---

**Important**

Unlike `execute_code`, if the computation fails (`is_error` is True), this method raises the error as an exception.
Comment on lines +566 to +568
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That behavior seems a bit unintuitive, especially given that it needs a note. Would it make sense to make raw_call return bytes, like in Vyper, and leave execute_code as a low-level version? Might also need a third function for completeness, one that does not throw and returns ComputationABI but does not require passing bytecode...

We don't need to deal with that now ofc


---

**Example**

```python
>>> computation = boa.env.raw_call(contract_address, data=b"\x00\x00\x00\x00")
>>> print(computation.output.hex())
```

---

Expand Down
28 changes: 25 additions & 3 deletions docs/api/pyevm/deregister_precompile.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,37 @@
# `deregister_precompile`
# `deregister_raw_precompile`

### Signature

```python
deregister_precompile(address: str, force: bool = True)
from boa.vm.py_evm import deregister_raw_precompile

deregister_raw_precompile(address: str, force: bool = True)
```

### Description

Deregister a precompile.
Remove a previously registered precompile.

**Note:** `deregister_precompile` has been renamed to `deregister_raw_precompile`. The old name is deprecated.

**Important:** This function is not available directly from the `boa` module. You must import it from `boa.vm.py_evm`.

- `address`: The address of a previously registered precompile.
- `force`: Whether to force removal of the precompile at the specified address.
- Raises `ValueError`: If a precompile is not registered at the specified address and the force argument is `False`.

### Examples

```python
>>> from boa.vm.py_evm import register_raw_precompile, deregister_raw_precompile
>>>
>>> # Register a precompile
>>> register_raw_precompile("0x00000000000000000000000000000000000000ff", lambda c: None)
>>>
>>> # Remove it
>>> deregister_raw_precompile("0x00000000000000000000000000000000000000ff")
```

### See Also

- [`register_raw_precompile`](./register_precompile.md) - Register a precompile function
24 changes: 19 additions & 5 deletions docs/api/pyevm/register_precompile.md
Original file line number Diff line number Diff line change
@@ -1,26 +1,40 @@
# `register_precompile`
# `register_raw_precompile`

### Signature

```python
register_precompile(address: str, fn: Callable[[eth.abc.ComputationAPI], None], force: bool = False)
from boa.vm.py_evm import register_raw_precompile

register_raw_precompile(address: str, fn: Callable[[eth.abc.ComputationAPI], None], force: bool = False)
```

### Description

Register a precompile.
Register a raw precompile function. This is the low-level interface for registering precompiles.

**Note:** `register_precompile` has been renamed to `register_raw_precompile`. The old name is deprecated.

**Important:** This function is not available directly from the `boa` module. You must import it from `boa.vm.py_evm`.

- `address`: The address to register the precompile at.
- `fn`: The function to execute when the precompile is called.
- `fn`: The function to execute when the precompile is called. Receives a ComputationAPI object.
- `force`: Whether to overwrite the precompile function if one is already registered at the specified address.
- Raises `ValueError`: If a precompile is already registered at the specified address and the force argument is `False`.

### Examples

```python
>>> from boa.vm.py_evm import register_raw_precompile
>>> import boa
>>>
>>> log = lambda computation: print("0x" + computation.msg.sender.hex())
>>> boa.register_precompile("0x00000000000000000000000000000000000000ff", log)
>>> register_raw_precompile("0x00000000000000000000000000000000000000ff", log)
>>> boa.eval("raw_call(0x00000000000000000000000000000000000000ff, b'')")
0x0000000000000000000000000000000000000069
```

### See Also

- [`deregister_raw_precompile`](./deregister_precompile.md) - Remove a registered precompile
- [`@precompile` decorator](../../guides/advanced_features.md#precompiles) - Higher-level interface for creating precompiles
- [`patch_opcode`](./patch_opcode.md) - Modify EVM opcodes
Loading