Skip to content

Commit e2c8f0d

Browse files
Merge branch 'cartesi:Staging' into Staging
2 parents 45ff97d + 1bad6d9 commit e2c8f0d

9 files changed

Lines changed: 154 additions & 81 deletions

File tree

cartesi-rollups_versioned_docs/version-2.0/api-reference/backend/vouchers.md

Lines changed: 56 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ async function emitSafeERC20Transfer(token, to, amount) {
171171
</code></pre>
172172
</TabItem>
173173

174-
<TabItem value="Python" label="Python" default>
174+
<TabItem value="Python" label="Python">
175175
<pre><code>
176176

177177
```python
@@ -194,6 +194,61 @@ def emit_safe_erc20_transfer(token, to, amount):
194194
</code></pre>
195195
</TabItem>
196196

197+
<TabItem value="Go" label="Go">
198+
<pre><code>
199+
200+
```go
201+
package main
202+
203+
import (
204+
"encoding/json"
205+
"fmt"
206+
"strings"
207+
208+
"github.com/ethereum/go-ethereum/accounts/abi"
209+
"github.com/ethereum/go-ethereum/common"
210+
)
211+
212+
func emitSafeERC20Transfer(token, to common.Address, amount *big.Int) error {
213+
// Define the ABI for the safeTransfer function
214+
abiJSON := `[{
215+
"type":"function",
216+
"name":"safeTransfer",
217+
"inputs":[
218+
{"type":"address"},
219+
{"type":"address"},
220+
{"type":"uint256"}
221+
]
222+
}]`
223+
224+
// Parse the ABI
225+
abiInterface, err := abi.JSON(strings.NewReader(abiJSON))
226+
if err != nil {
227+
return fmt.Errorf("failed to parse ABI: %w", err)
228+
}
229+
230+
// Pack the function call
231+
payload, err := abiInterface.Pack("safeTransfer", token, to, amount)
232+
if err != nil {
233+
return fmt.Errorf("failed to pack ABI: %w", err)
234+
}
235+
236+
// Create the DELEGATECALL voucher
237+
voucher := map[string]interface{}{
238+
"destination": "0xfafafafafafafafafafafafafafafafafafafafa", // contract address containing the logic
239+
"payload": common.Bytes2Hex(payload),
240+
}
241+
242+
// Send the voucher to the rollup server
243+
// Note: In a real implementation, you would use the rollmelette.Env interface
244+
// env.DelegateCallVoucher(common.HexToAddress("0xfafafafafafafafafafafafafafafafafafafafa"), payload)
245+
246+
return nil
247+
}
248+
```
249+
250+
</code></pre>
251+
</TabItem>
197252
</Tabs>
198253

199254
### Implementation Considerations

cartesi-rollups_versioned_docs/version-2.0/api-reference/contracts/application.md

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,7 @@ resources:
1010

1111
The **Application** contract serves as the base layer representation of the application running on the execution layer. The application can interact with other smart contracts through the execution and validation of outputs. These outputs, generated by the application backend on the execution layer, can be proven in the base layer through claims submitted by a consensus contract.
1212

13-
Every Application is subscribed to a consensus contract and governed by a single address—the owner. The consensus has the authority to submit claims, which are then used to validate outputs. The owner has complete control over the Application and can replace the consensus at any time. Consequently, users of an Application must trust both the consensus and the application owner. Depending on centralization or ownership concerns, the ownership model can be modified. This process is managed by the consensus contract. For more information about different ownership and consensus models, refer to the [consensus contracts](./consensus/overview.md).
14-
15-
This contract inherits from the following contracts:
16-
17-
- `IApplication`
18-
- `Ownable`
19-
- `ERC721Holder`
20-
- `ERC1155Holder`
21-
- `ReentrancyGuard`
22-
23-
For more information, please consult [OpenZeppelin's official documentation](https://docs.openzeppelin.com/contracts/5.x/).
13+
Every Application is subscribed to a consensus contract and governed by a single address (owner). The consensus has the authority to submit claims, which are then used to validate outputs. The owner has complete control over the Application and can replace the consensus at any time. Consequently, users of an Application must trust both the consensus and the application owner. Depending on centralization or ownership concerns, the ownership model can be modified. This process is managed by the consensus contract. For more information about different ownership and consensus models, refer to the [consensus contracts](./consensus/overview.md).
2414

2515
## Functions
2616

cartesi-rollups_versioned_docs/version-2.0/api-reference/contracts/consensus/abstractconsensus.md renamed to cartesi-rollups_versioned_docs/version-2.0/api-reference/contracts/consensus/abstract-consensus.md

File renamed without changes.

cartesi-rollups_versioned_docs/version-2.0/api-reference/contracts/consensus/iconsensus.md

Lines changed: 84 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,52 @@ The acceptance criteria for claims may depend on the type of consensus, and is n
2424
- Submitted and not proven wrong after some period of time or
2525
- Submitted and proven correct through an on-chain tournament
2626

27+
## Functions
28+
29+
### `submitClaim()`
30+
31+
```solidity
32+
function submitClaim(
33+
address appContract,
34+
uint256 lastProcessedBlockNumber,
35+
bytes32 outputsMerkleRoot
36+
) external
37+
```
38+
39+
Submit a claim to the consensus.
40+
41+
**Parameters**
42+
43+
| Name | Type | Description |
44+
|------|------|-------------|
45+
| `appContract` | `address` | The application contract address |
46+
| `lastProcessedBlockNumber` | `uint256` | The number of the last processed block |
47+
| `outputsMerkleRoot` | `bytes32` | The outputs Merkle root |
48+
49+
**Events:**
50+
- `ClaimSubmitted`: Must be fired
51+
- `ClaimAccepted`: MAY be fired, if the acceptance criteria is met
52+
53+
### `getEpochLength()`
54+
55+
```solidity
56+
function getEpochLength() external view returns (uint256)
57+
```
58+
59+
Get the epoch length, in number of base layer blocks.
60+
61+
**Return Values**
62+
63+
| Name | Type | Description |
64+
|------|------|-------------|
65+
| `[0]` | `uint256` | The epoch length |
66+
67+
**Note:** The epoch number of a block is defined as the integer division of the block number by the epoch length.
68+
2769
## Events
2870

29-
### `ClaimSubmitted`
71+
### `ClaimSubmitted()`
72+
3073
```solidity
3174
event ClaimSubmitted(
3275
address indexed submitter,
@@ -38,13 +81,17 @@ event ClaimSubmitted(
3881

3982
Must trigger when a claim is submitted.
4083

41-
**Parameters:**
42-
- `submitter` (address): The submitter address
43-
- `appContract` (address): The application contract address
44-
- `lastProcessedBlockNumber` (uint256): The number of the last processed block
45-
- `outputsMerkleRoot` (bytes32): The outputs Merkle root
84+
**Parameters**
85+
86+
| Name | Type | Description |
87+
|------|------|-------------|
88+
| `submitter` | `address` | The submitter address |
89+
| `appContract` | `address` | The application contract address |
90+
| `lastProcessedBlockNumber` | `uint256` | The number of the last processed block |
91+
| `outputsMerkleRoot` | `bytes32` | The outputs Merkle root |
92+
93+
### `ClaimAccepted()`
4694

47-
### `ClaimAccepted`
4895
```solidity
4996
event ClaimAccepted(
5097
address indexed appContract,
@@ -55,81 +102,62 @@ event ClaimAccepted(
55102

56103
Must trigger when a claim is accepted.
57104

58-
**Parameters:**
59-
- `appContract` (address): The application contract address
60-
- `lastProcessedBlockNumber` (uint256): The number of the last processed block
61-
- `outputsMerkleRoot` (bytes32): The outputs Merkle root
105+
**Parameters**
106+
107+
| Name | Type | Description |
108+
|------|------|-------------|
109+
| `appContract` | `address` | The application contract address |
110+
| `lastProcessedBlockNumber` | `uint256` | The number of the last processed block |
111+
| `outputsMerkleRoot` | `bytes32` | The outputs Merkle root |
62112

63113
**Note:** For each application and lastProcessedBlockNumber, there can be at most one accepted claim.
64114

65115
## Errors
66116

67-
### `NotEpochFinalBlock`
117+
### `NotEpochFinalBlock()`
118+
68119
```solidity
69120
error NotEpochFinalBlock(uint256 lastProcessedBlockNumber, uint256 epochLength)
70121
```
71122

72123
The claim contains the number of a block that is not at the end of an epoch (its modulo epoch length is not epoch length - 1).
73124

74-
**Parameters:**
75-
- `lastProcessedBlockNumber` (uint256): The number of the last processed block
76-
- `epochLength` (uint256): The epoch length
77-
78-
### `NotPastBlock`
79-
```solidity
80-
error NotPastBlock(uint256 lastProcessedBlockNumber, uint256 currentBlockNumber)
81-
```
125+
**Parameters**
82126

83-
The claim contains the number of a block in the future (it is greater or equal to the current block number).
127+
| Name | Type | Description |
128+
|------|------|-------------|
129+
| `lastProcessedBlockNumber` | `uint256` | The number of the last processed block |
130+
| `epochLength` | `uint256` | The epoch length |
84131

85-
**Parameters:**
86-
- `lastProcessedBlockNumber` (uint256): The number of the last processed block
87-
- `currentBlockNumber` (uint256): The number of the current block
132+
### `NotPastBlock()`
88133

89-
### `NotFirstClaim`
90134
```solidity
91-
error NotFirstClaim(address appContract, uint256 lastProcessedBlockNumber)
135+
error NotPastBlock(uint256 lastProcessedBlockNumber, uint256 currentBlockNumber)
92136
```
93137

94-
A claim for that application and epoch was already submitted by the validator.
95-
96-
**Parameters:**
97-
- `appContract` (address): The application contract address
98-
- `lastProcessedBlockNumber` (uint256): The number of the last processed block
99-
100-
## Functions
101-
102-
### `submitClaim`
103-
```solidity
104-
function submitClaim(
105-
address appContract,
106-
uint256 lastProcessedBlockNumber,
107-
bytes32 outputsMerkleRoot
108-
) external
109-
```
138+
The claim contains the number of a block in the future (it is greater or equal to the current block number).
110139

111-
Submit a claim to the consensus.
140+
**Parameters**
112141

113-
**Parameters:**
114-
- `appContract` (address): The application contract address
115-
- `lastProcessedBlockNumber` (uint256): The number of the last processed block
116-
- `outputsMerkleRoot` (bytes32): The outputs Merkle root
142+
| Name | Type | Description |
143+
|------|------|-------------|
144+
| `lastProcessedBlockNumber` | `uint256` | The number of the last processed block |
145+
| `currentBlockNumber` | `uint256` | The number of the current block |
117146

118-
**Events:**
119-
- `ClaimSubmitted`: Must be fired
120-
- `ClaimAccepted`: MAY be fired, if the acceptance criteria is met
147+
### `NotFirstClaim()`
121148

122-
### `getEpochLength`
123149
```solidity
124-
function getEpochLength() external view returns (uint256)
150+
error NotFirstClaim(address appContract, uint256 lastProcessedBlockNumber)
125151
```
126152

127-
Get the epoch length, in number of base layer blocks.
153+
A claim for that application and epoch was already submitted by the validator.
128154

129-
**Returns:**
130-
- (uint256): The epoch length
155+
**Parameters**
131156

132-
**Note:** The epoch number of a block is defined as the integer division of the block number by the epoch length.
157+
| Name | Type | Description |
158+
|------|------|-------------|
159+
| `appContract` | `address` | The application contract address |
160+
| `lastProcessedBlockNumber` | `uint256` | The number of the last processed block |
133161

134162
## Related Contracts
135163

cartesi-rollups_versioned_docs/version-2.0/api-reference/contracts/consensus/ioutputsmerklerootvalidator.md renamed to cartesi-rollups_versioned_docs/version-2.0/api-reference/contracts/consensus/ioutputs-merkle-root-validator.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,4 @@ Check whether an outputs Merkle root is valid.
3131
## Related Contracts
3232

3333
- [`IConsensus`](./iconsensus.md): Interface that inherits from this interface
34-
- [`AbstractConsensus`](./abstractconsensus.md): Abstract implementation that implements this interface
34+
- [`AbstractConsensus`](./abstract-consensus.md): Abstract implementation that implements this interface

cartesi-rollups_versioned_docs/version-2.0/api-reference/contracts/consensus/overview.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,16 @@ The framework supports different consensus mechanisms:
1818
## Core Interfaces
1919

2020
- **[IConsensus](./iconsensus.md)**: Main interface defining the consensus contract behavior
21-
- **[IOutputsMerkleRootValidator](./ioutputsmerklerootvalidator.md)**: Interface for validating outputs Merkle roots
22-
- **[AbstractConsensus](./abstractconsensus.md)**: Abstract implementation providing common consensus functionality
21+
- **[IOutputsMerkleRootValidator](./ioutputs-merkle-root-validator.md)**: Interface for validating outputs Merkle roots
22+
- **[AbstractConsensus](./abstract-consensus.md)**: Abstract implementation providing common consensus functionality
2323

2424
## Consensus Mechanism
2525

2626
A claim consists of:
2727

28-
- **Application Contract Address**: The address of the dApp being validated
29-
- **Last Processed Block Number**: The block number up to which inputs have been processed
30-
- **Outputs Merkle Root**: The root hash of the Merkle tree containing all outputs produced by the application
28+
- Application Contract Address: The address of the dApp being validated
29+
- Last Processed Block Number: The block number up to which inputs have been processed
30+
- Outputs Merkle Root: The root hash of the Merkle tree containing all outputs produced by the application
3131

3232
The consensus contract validates that:
3333
- The block number is at the end of an epoch (modulo epoch length equals epoch length - 1)

cartesi-rollups_versioned_docs/version-2.0/api-reference/contracts/input-box.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ function addInput(address appContract, bytes calldata payload) external override
4242

4343
Send an input to an application.
4444

45-
*MUST fire an InputAdded event.*
45+
*Must fire an InputAdded event.*
4646

4747
**Parameters**
4848

cartesi-rollups_versioned_docs/version-2.0/api-reference/contracts/overview.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ To interact with an Ethereum-compatible blockchain, the application frontend mus
1414

1515
Clients can interact with Ethereum-compatible nodes using the JSON-RPC API in two ways:
1616

17-
- **Querying state (read operations)** The state can be queried by calling functions that neither alter the blockchain state nor incur gas fees.
17+
- Querying state: The state can be queried by calling functions that neither alter the blockchain state nor incur gas fees.
1818

19-
- **Changing state (write operations)** The state is changed by submitting a transaction that incurs gas fees. The transaction must be cryptographically signed by an Ethereum account with sufficient funds in its wallet.
19+
- Changing state: The state is changed by submitting a transaction that incurs gas fees. The transaction must be cryptographically signed by an Ethereum account with sufficient funds in its wallet.
2020

2121
## Cartesi Rollups Smart Contracts
2222

@@ -26,6 +26,6 @@ Clients can interact with Ethereum-compatible nodes using the JSON-RPC API in tw
2626

2727
- [`ApplicationFactory`](../contracts/application-factory.md): This contract enables anyone to deploy [`Application`](../contracts/application.md) contracts with a simple function call. It provides greater convenience to the deployer and security to users and validators, as they can verify that the bytecode has not been maliciously altered.
2828

29-
- Portals: These contracts are used to safely transfer assets from the base layer to the execution environment of your application. Currently, Portal contracts are available for the following types of assets: [Ether (ETH)](../contracts/portals/EtherPortal.md), [ERC-20 (Fungible tokens)](../contracts/portals/ERC20Portal.md), [ERC-721 (Non-fungible tokens)](../contracts/portals/ERC721Portal.md), [ERC-1155 single transfer](../contracts/portals/ERC1155SinglePortal.md), and [ERC-1155 batch token transfers](../contracts/portals/ERC1155BatchPortal.md).
30-
29+
- [`Portals`](../contracts/portals/): These contracts are used to safely transfer assets from the base layer to the execution environment of your application. Currently, Portal contracts are available for the following types of assets: [Ether (ETH)](../contracts/portals/EtherPortal.md), [ERC-20 (Fungible tokens)](../contracts/portals/ERC20Portal.md), [ERC-721 (Non-fungible tokens)](../contracts/portals/ERC721Portal.md), [ERC-1155 single transfer](../contracts/portals/ERC1155SinglePortal.md), and [ERC-1155 batch token transfers](../contracts/portals/ERC1155BatchPortal.md).
3130

31+
- [`Consensus`](../contracts/consensus/overview.md): These contracts are crucial for the framework's security and integrity. They validate and accept claims submitted by validators, ensuring the rollup's integrity by validating outputs Merkle roots. The framework supports different consensus mechanisms including [Authority-based consensus](../contracts/consensus/authority/authority.md) for single-owner control and [Quorum-based consensus](../contracts/consensus/quorum/quorum.md) for multi-validator approval.

cartesi-rollups_versioned_sidebars/version-2.0-sidebars.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@
4343
"items": [
4444
"api-reference/contracts/consensus/overview",
4545
"api-reference/contracts/consensus/iconsensus",
46-
"api-reference/contracts/consensus/ioutputsmerklerootvalidator",
47-
"api-reference/contracts/consensus/abstractconsensus",
46+
"api-reference/contracts/consensus/ioutputs-merkle-root-validator",
47+
"api-reference/contracts/consensus/abstract-consensus",
4848
{
4949
"type": "category",
5050
"label": "Authority",

0 commit comments

Comments
 (0)