Skip to content

Commit 778d781

Browse files
docs: update precompile docs (#410)
also update Address and ComputationAPI docs
1 parent 22e6a81 commit 778d781

5 files changed

Lines changed: 81 additions & 16 deletions

File tree

docs/api/common_classes/address.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ The `Address` class represents an Ethereum address in Titanoboa. It provides a t
1010

1111
```python
1212
import boa
13-
from boa import Address
13+
from boa.util.abi import Address
1414

1515
# From hex string
1616
addr1 = Address("0x0000000000000000000000000000000000000001")

docs/api/common_classes/deployer.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ Create a contract instance at an existing address.
5757
existing = deployer.at("0x1234567890123456789012345678901234567890")
5858

5959
# Works with Address objects too
60-
from boa import Address
60+
from boa.util.abi import Address
6161
addr = Address("0x1234567890123456789012345678901234567890")
6262
existing = deployer.at(addr)
6363
```

docs/api/env/env.md

Lines changed: 35 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ A wrapper class around py-evm which provides a "contract-centric" API. More deta
169169

170170
## `execute_code`
171171

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

174174
**Description**
175175

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

192192
**Returns**
193193

194-
The return value from the top-level call.
194+
A `ComputationAPI` object containing the execution result. Key attributes include:
195+
- `output`: The return data as bytes
196+
- `is_error`: Boolean indicating if the execution failed
197+
- `error`: The exception if execution failed
198+
- `gas_used`: Amount of gas consumed
199+
200+
---
201+
202+
**Note**
203+
204+
Unlike `raw_call`, this method returns the computation object directly without raising exceptions on errors.
195205

196206
---
197207

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

525535
## `raw_call`
526536

527-
!!! function "`boa.env.raw_call(to_address) -> bytes`"
537+
!!! function "`boa.env.raw_call(to_address) -> ComputationAPI`"
528538

529539
**Description**
530540

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

534543
---
535544

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

544554
---
545555

546556
**Returns**
547557

548-
The return value from the top-level call.
558+
A `ComputationAPI` object containing the execution result. Key attributes include:
559+
- `output`: The return data as bytes
560+
- `is_error`: Boolean indicating if the execution failed
561+
- `error`: The exception if execution failed
562+
- `gas_used`: Amount of gas consumed
563+
564+
---
565+
566+
**Important**
567+
568+
Unlike `execute_code`, if the computation fails (`is_error` is True), this method raises the error as an exception.
569+
570+
---
571+
572+
**Example**
573+
574+
```python
575+
>>> computation = boa.env.raw_call(contract_address, data=b"\x00\x00\x00\x00")
576+
>>> print(computation.output.hex())
577+
```
549578

550579
---
551580

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,37 @@
1-
# `deregister_precompile`
1+
# `deregister_raw_precompile`
22

33
### Signature
44

55
```python
6-
deregister_precompile(address: str, force: bool = True)
6+
from boa.vm.py_evm import deregister_raw_precompile
7+
8+
deregister_raw_precompile(address: str, force: bool = True)
79
```
810

911
### Description
1012

11-
Deregister a precompile.
13+
Remove a previously registered precompile.
14+
15+
**Note:** `deregister_precompile` has been renamed to `deregister_raw_precompile`. The old name is deprecated.
16+
17+
**Important:** This function is not available directly from the `boa` module. You must import it from `boa.vm.py_evm`.
1218

1319
- `address`: The address of a previously registered precompile.
1420
- `force`: Whether to force removal of the precompile at the specified address.
1521
- Raises `ValueError`: If a precompile is not registered at the specified address and the force argument is `False`.
22+
23+
### Examples
24+
25+
```python
26+
>>> from boa.vm.py_evm import register_raw_precompile, deregister_raw_precompile
27+
>>>
28+
>>> # Register a precompile
29+
>>> register_raw_precompile("0x00000000000000000000000000000000000000ff", lambda c: None)
30+
>>>
31+
>>> # Remove it
32+
>>> deregister_raw_precompile("0x00000000000000000000000000000000000000ff")
33+
```
34+
35+
### See Also
36+
37+
- [`register_raw_precompile`](./register_precompile.md) - Register a precompile function
Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,40 @@
1-
# `register_precompile`
1+
# `register_raw_precompile`
22

33
### Signature
44

55
```python
6-
register_precompile(address: str, fn: Callable[[eth.abc.ComputationAPI], None], force: bool = False)
6+
from boa.vm.py_evm import register_raw_precompile
7+
8+
register_raw_precompile(address: str, fn: Callable[[eth.abc.ComputationAPI], None], force: bool = False)
79
```
810

911
### Description
1012

11-
Register a precompile.
13+
Register a raw precompile function. This is the low-level interface for registering precompiles.
14+
15+
**Note:** `register_precompile` has been renamed to `register_raw_precompile`. The old name is deprecated.
16+
17+
**Important:** This function is not available directly from the `boa` module. You must import it from `boa.vm.py_evm`.
1218

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

1824
### Examples
1925

2026
```python
27+
>>> from boa.vm.py_evm import register_raw_precompile
2128
>>> import boa
29+
>>>
2230
>>> log = lambda computation: print("0x" + computation.msg.sender.hex())
23-
>>> boa.register_precompile("0x00000000000000000000000000000000000000ff", log)
31+
>>> register_raw_precompile("0x00000000000000000000000000000000000000ff", log)
2432
>>> boa.eval("raw_call(0x00000000000000000000000000000000000000ff, b'')")
2533
0x0000000000000000000000000000000000000069
2634
```
35+
36+
### See Also
37+
38+
- [`deregister_raw_precompile`](./deregister_precompile.md) - Remove a registered precompile
39+
- [`@precompile` decorator](../../guides/advanced_features.md#precompiles) - Higher-level interface for creating precompiles
40+
- [`patch_opcode`](./patch_opcode.md) - Modify EVM opcodes

0 commit comments

Comments
 (0)