Skip to content

Commit fcaa822

Browse files
committed
Merge remote-tracking branch 'origin/main' into v0.2.0
2 parents 723c101 + 3a79e78 commit fcaa822

File tree

91 files changed

+4956
-883
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

91 files changed

+4956
-883
lines changed

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ repos:
6868
entry: python -c "import sys, re; sys.exit(1 if any(not re.match(r'^[a-z0-9_.-]+$', f.split('/')[-1]) for f in sys.argv[1:]) else 0)"
6969
language: python
7070
types: [file]
71-
exclude: '.pre-commit.*|^overrides.*|^docs/(assets|images)/|^formal.*|.*Package.juvix.*|^\.github/.*|CITATION|LICENSE|Makefile|README\.md|VERSION|.changelog/.*'
71+
exclude: '\.git/|\.pre-commit.*|^overrides.*|^docs/(assets|images)/|^formal.*|.*Package\.juvix.*|^\.github/.*|CITATION|LICENSE|Makefile|README\.md|VERSION|\.changelog/.*'
7272

7373
- id: typecheck
7474
name: typecheck

docs/arch/integrations/adapters/evm.md

Lines changed: 16 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -34,25 +34,25 @@ Only the protocol adapter can call [non-view functions](https://docs.soliditylan
3434

3535
### Commitment Accumulator
3636

37-
The implementation uses a modified version of the [OpenZeppelin `MerkleTree` v.5.2.0](https://github.com/OpenZeppelin/openzeppelin-contracts/blob/v5.2.0/contracts/utils/structs/MerkleTree.sol) that populates the binary tree from left to right and stores leaf indices in a hash table
37+
The [implementation](https://github.com/anoma/evm-protocol-adapter/blob/6f7cde40aaec5e385408012269b85bb8173a9b87/contracts/src/state/CommitmentAccumulator.sol) uses a modified version of the [OpenZeppelin `MerkleTree` v.5.2.0](https://github.com/OpenZeppelin/openzeppelin-contracts/blob/v5.2.0/contracts/utils/structs/MerkleTree.sol) that populates the binary tree from left to right and [stores commitment indices in a hash table](https://github.com/anoma/evm-protocol-adapter/blob/6f7cde40aaec5e385408012269b85bb8173a9b87/contracts/src/state/CommitmentAccumulator.sol#L21)
3838

3939
```solidity
4040
mapping(bytes32 commitment => uint256 index) internal _indices;
4141
```
4242

4343
allowing for commitment existence checks.
4444

45-
In addition to the leaves, the [modified implementation](https://github.com/anoma/evm-protocol-adapter/blob/main/src/state/CommitmentAccumulator.sol) stores also the intermediary node hashes.
45+
In addition to the leaves, the [modified Merkle tree implementation](https://github.com/anoma/evm-protocol-adapter/blob/6f7cde40aaec5e385408012269b85bb8173a9b87/contracts/src/libs/MerkleTree.sol) stores also the intermediary node hashes, which allows to [obtain Merkle proofs directly from the contract](https://github.com/anoma/evm-protocol-adapter/blob/6f7cde40aaec5e385408012269b85bb8173a9b87/contracts/src/libs/MerkleTree.sol#L88-L136).
4646

4747
Historical Merkle tree roots are stored in an [OpenZeppelin `EnumerableSet` v5.2.0](https://github.com/OpenZeppelin/openzeppelin-contracts/blob/v5.2.0/contracts/utils/structs/EnumerableSet.sol) allowing for existence checks.
4848

4949
### Nullifier Set
5050

51-
The implementation uses an [OpenZeppelin `EnumerableSet` v5.2.0](https://github.com/OpenZeppelin/openzeppelin-contracts/blob/v5.2.0/contracts/utils/structs/EnumerableSet.sol) to store nullifiers of consumed resources and allow for existence checks.
51+
The [implementation](https://github.com/anoma/evm-protocol-adapter/blob/6f7cde40aaec5e385408012269b85bb8173a9b87/contracts/src/state/NullifierSet.sol) uses an [OpenZeppelin `EnumerableSet` v5.2.0](https://github.com/OpenZeppelin/openzeppelin-contracts/blob/v5.2.0/contracts/utils/structs/EnumerableSet.sol) to store nullifiers of consumed resources and allow for existence checks.
5252

5353
### Blob Storage
5454

55-
The [implementation](https://github.com/anoma/evm-protocol-adapter/blob/main/src/state/BlobStorage.sol) uses a simple hash table to store blobs content-addressed.
55+
The [implementation](https://github.com/anoma/evm-protocol-adapter/blob/6f7cde40aaec5e385408012269b85bb8173a9b87/contracts/src/state/BlobStorage.sol) uses a simple hash table to store blobs content-addressed.
5656

5757
```solidity
5858
mapping(bytes32 blobHash => bytes blob) internal _blobs;
@@ -73,7 +73,7 @@ For hashing, we compute the SHA-256 hash of the [strictly ABI-encoded](https://d
7373

7474
## Types & Computable Components
7575

76-
The RM-related type and computable component definitions in Solidity can be found in the [`src/Types.sol`](https://github.com/anoma/evm-protocol-adapter/blob/main/src/Types.sol) and [`src/libs/ComputableComponents.sol`](https://github.com/anoma/evm-protocol-adapter/blob/main/src/libs/ComputableComponents.sol) file, respectively.
76+
The RM-related type and computable component definitions in Solidity can be found in the [`src/Types.sol`](https://github.com/anoma/evm-protocol-adapter/blob/6f7cde40aaec5e385408012269b85bb8173a9b87/contracts/src/Types.sol) and [`src/libs/ComputableComponents.sol`](https://github.com/anoma/evm-protocol-adapter/blob/6f7cde40aaec5e385408012269b85bb8173a9b87/contracts/src/libs/ComputableComponents.sol) file, respectively.
7777

7878
## Proving Systems
7979

@@ -85,18 +85,19 @@ For proof verification, we use the [RISC ZERO verifier contracts](https://dev.ri
8585

8686
For the current prototype and the only supported example application [basic shielded Kudos ](https://research.anoma.net/t/basic-e2e-shielded-kudos-app/1237), we use a specific circuit resulting in the loss of function privacy. This will be improved in future iterations.
8787

88-
The associated types are defined in [`proving/Compliance.sol`](https://github.com/anoma/evm-protocol-adapter/blob/main/src/proving/Compliance.sol).
88+
The associated types are defined in [`proving/Compliance.sol`](https://github.com/anoma/evm-protocol-adapter/blob/6f7cde40aaec5e385408012269b85bb8173a9b87/contracts/src/proving/Logic.sol).
8989

9090
### Compliance Proofs
9191

9292
Compliance units have a fixed size and contain references to one consumed and one created resource. For transaction with $n_\text{consumed} \neq n_\text{created}$, we expect padding resources (ephemeral resources with quantity 0) to be used.
9393

94-
The associated types are defined in [`proving/Compliance.sol`](https://github.com/anoma/evm-protocol-adapter/blob/main/src/proving/Compliance.sol).
94+
The associated types are defined in [`proving/Compliance.sol`](https://github.com/anoma/evm-protocol-adapter/blob/6f7cde40aaec5e385408012269b85bb8173a9b87/contracts/src/proving/Compliance.sol).
9595

9696
### Delta Proofs
9797

98-
The delta values are computed as 2D points (`uint256[2]`) on the `secp256k1` (K-256) curve and can be verified using ECDSA.
98+
The delta values are computed as 2D points (`uint256[2]`) on the `secp256k1` (K-256) elliptic curve and can be verified using ECDSA.
9999

100+
The associated elliptic curve addition and conversion methods are defined in [`proving/Delta.sol`](https://github.com/anoma/evm-protocol-adapter/blob/6f7cde40aaec5e385408012269b85bb8173a9b87/contracts/src/proving/Delta.sol).
100101
The curve implementation is taken from [Witnet's `eliptic-curve-solidity` library v0.2.1](https://github.com/witnet/elliptic-curve-solidity/tree/0.2.1). This includes
101102

102103
- [curve parameters](https://github.com/witnet/elliptic-curve-solidity/blob/0.2.1/examples/Secp256k1.sol)
@@ -105,15 +106,9 @@ The curve implementation is taken from [Witnet's `eliptic-curve-solidity` librar
105106

106107
We use the zero delta public key derived from the private key `0`.
107108

108-
As the message digest, we use the transaction hash that we've defined as follows (see [`src/ProtocolAdapter.sol`](https://github.com/anoma/evm-protocol-adapter/blob/main/src/ProtocolAdapter.sol)):
109+
As the verifying key (a.k.a. message digest), we use the keccak-256 hash over the list of all nullifier and commitments pairs being obtained by iterating over the compliance units (see [`src/proving/Delta.sol`](https://github.com/anoma/evm-protocol-adapter/blob/6f7cde40aaec5e385408012269b85bb8173a9b87/contracts/src/proving/Delta.sol#L31-L37)).
109110

110-
```solidity
111-
function _transactionHash(bytes32[] memory tags) internal pure returns (bytes32 txHash) {
112-
txHash = sha256(abi.encode(tags));
113-
}
114-
```
115-
116-
For key recovery from the message digest and signature, we use [OpenZeppelin's `ECDSA` library](https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/utils/cryptography/ECDSA.sol).
111+
For key recovery from the verifying key and signature, we use [OpenZeppelin's `ECDSA` library](https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/utils/cryptography/ECDSA.sol).
117112

118113
## EVM and RM State Correspondence
119114

@@ -143,7 +138,7 @@ and allows the application to ensure the correspondence.
143138

144139
This works as follows:
145140

146-
The protocol adapter accepts an optional `ForwarderCalldata` struct with the RM transaction object as part of the action object (see [`src/Types.sol`](https://github.com/anoma/evm-protocol-adapter/blob/main/src/Types.sol)):
141+
The protocol adapter accepts an optional `ForwarderCalldata` struct with the RM transaction object as part of the action object (see [`src/Types.sol`](https://github.com/anoma/evm-protocol-adapter/blob/6f7cde40aaec5e385408012269b85bb8173a9b87/contracts/src/Types.sol#L46-L53)):
147142

148143
```solidity
149144
struct ForwarderCalldata {
@@ -193,9 +188,7 @@ Besides referencing the external contract by its address, the forwarder contract
193188
the resource kind of the associated [calldata carrier resource](#calldata-carrier-resource) that the protocol adapter will require be created. This allows the forwarder contract to also to enforce its own contract address to be part of the carrier resource label, which ensures that the correspondence between the forwarder and carrier resource is unique.
194189

195190
!!! note
196-
The mutual dependency between
197-
- the calldata carrier resource label containing the forwarder contract address
198-
- the forwarder contract referencing the calldata carrier resource label
191+
The mutual dependency between - the calldata carrier resource label containing the forwarder contract address - the forwarder contract referencing the calldata carrier resource label
199192

200193
can be established by deterministic deployment or post-deployment initialization of the forwarder contract.
201194

@@ -225,7 +218,7 @@ contract ExampleForwarder is Ownable {
225218
}
226219
```
227220

228-
The required calldata is passed with the RM transaction object as part of the `Action` struct (see [`src/Types.sol`](https://github.com/anoma/evm-protocol-adapter/blob/main/src/Types.sol)).
221+
The required calldata is passed with the RM transaction object as part of the `Action` struct (see [`src/Types.sol`](https://github.com/anoma/evm-protocol-adapter/blob/6f7cde40aaec5e385408012269b85bb8173a9b87/contracts/src/Types.sol#L43)).
229222

230223
```solidity
231224
struct ForwarderCalldata {
@@ -247,7 +240,7 @@ function _executeForwarderCall(ForwarderCalldata calldata call) internal {
247240
}
248241
```
249242

250-
The forwarder contract base class can be found in [`src/ForwarderBase.sol`](https://github.com/anoma/evm-protocol-adapter/blob/main/src/ForwarderBase.sol).
243+
The forwarder contract base class can be found in [`src/ForwarderBase.sol`](https://github.com/anoma/evm-protocol-adapter/blob/6f7cde40aaec5e385408012269b85bb8173a9b87/contracts/src/forwarders/ForwarderBase.sol).
251244

252245
### Calldata Carrier Resource
253246

@@ -257,7 +250,7 @@ By default, calldata carrier resources can be consumed by everyone (because thei
257250
!!! note
258251
When the singleton calldata carrier resource is consumed in a transaction, subsequent transactions in the same block cannot consume it anymore. This effectively limits the current design to a single forwarder contract call per block (if the commitment of the latest, unspent calldata carrier resource is not known to the subsequent transaction ahead of time). This will be improved in upcoming protocol adapter versions.
259252

260-
The calldata carrier resource object is passed to the protocol adapter together with the `ForwarderCalldata` struct (see [`src/Types.sol`](https://github.com/anoma/evm-protocol-adapter/blob/6cdf69b92f58d56dc13df1c0b52539295ea59814/src/Types.sol#L31)):
253+
The calldata carrier resource object is passed to the protocol adapter together with the `ForwarderCalldata` struct (see [`src/Types.sol`](https://github.com/anoma/evm-protocol-adapter/blob/6f7cde40aaec5e385408012269b85bb8173a9b87/contracts/src/Types.sol#L55-L64)):
261254

262255

263256
```solidity

docs/arch/node/engines/commitment.juvix.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ maintaining the security of the underlying signing keys.
6060
```juvix
6161
CommitmentEngine : Type :=
6262
Engine
63-
CommitmentCfg
63+
CommitmentLocalCfg
6464
CommitmentLocalState
6565
CommitmentMailboxState
6666
CommitmentTimerHandle

docs/arch/node/engines/commitment_behaviour.juvix.md

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ CommitmentActionArguments : Type := List CommitmentActionArgument;
158158
```juvix
159159
CommitmentAction : Type :=
160160
Action
161-
CommitmentCfg
161+
CommitmentLocalCfg
162162
CommitmentLocalState
163163
CommitmentMailboxState
164164
CommitmentTimerHandle
@@ -175,7 +175,7 @@ CommitmentActionArguments : Type := List CommitmentActionArgument;
175175
```juvix
176176
CommitmentActionInput : Type :=
177177
ActionInput
178-
CommitmentCfg
178+
CommitmentLocalCfg
179179
CommitmentLocalState
180180
CommitmentMailboxState
181181
CommitmentTimerHandle
@@ -203,7 +203,7 @@ CommitmentActionArguments : Type := List CommitmentActionArgument;
203203
```juvix
204204
CommitmentActionExec : Type :=
205205
ActionExec
206-
CommitmentCfg
206+
CommitmentLocalCfg
207207
CommitmentLocalState
208208
CommitmentMailboxState
209209
CommitmentTimerHandle
@@ -242,11 +242,11 @@ commitAction
242242
case getEngineMsgFromTimestampedTrigger tt of {
243243
| some emsg :=
244244
case emsg of {
245-
| EngineMsg.mk@{msg := Anoma.PreMsg.MsgCommitment (CommitmentMsg.Request request)} :=
245+
| EngineMsg.mk@{msg := Anoma.Msg.Commitment (CommitmentMsg.Request request)} :=
246246
let
247247
signedData := Signer.sign
248-
(CommitmentCfg.signer (EngineCfg.cfg cfg))
249-
(CommitmentCfg.backend (EngineCfg.cfg cfg))
248+
(CommitmentLocalCfg.signer (EngineCfg.cfg cfg))
249+
(CommitmentLocalCfg.backend (EngineCfg.cfg cfg))
250250
(RequestCommitment.data request);
251251
responseMsg := ReplyCommitment.mkReplyCommitment@{
252252
commitment := signedData;
@@ -259,7 +259,7 @@ commitAction
259259
sender := getEngineIDFromEngineCfg cfg;
260260
target := EngineMsg.sender emsg;
261261
mailbox := some 0;
262-
msg := Anoma.PreMsg.MsgCommitment (CommitmentMsg.Reply responseMsg)
262+
msg := Anoma.Msg.Commitment (CommitmentMsg.Reply responseMsg)
263263
}
264264
];
265265
timers := [];
@@ -292,7 +292,7 @@ commitActionLabel : CommitmentActionExec := ActionExec.Seq [ commitAction ];
292292
```juvix
293293
CommitmentGuard : Type :=
294294
Guard
295-
CommitmentCfg
295+
CommitmentLocalCfg
296296
CommitmentLocalState
297297
CommitmentMailboxState
298298
CommitmentTimerHandle
@@ -311,7 +311,7 @@ commitActionLabel : CommitmentActionExec := ActionExec.Seq [ commitAction ];
311311
```juvix
312312
CommitmentGuardOutput : Type :=
313313
GuardOutput
314-
CommitmentCfg
314+
CommitmentLocalCfg
315315
CommitmentLocalState
316316
CommitmentMailboxState
317317
CommitmentTimerHandle
@@ -328,7 +328,7 @@ commitActionLabel : CommitmentActionExec := ActionExec.Seq [ commitAction ];
328328
```juvix
329329
CommitmentGuardEval : Type :=
330330
GuardEval
331-
CommitmentCfg
331+
CommitmentLocalCfg
332332
CommitmentLocalState
333333
CommitmentMailboxState
334334
CommitmentTimerHandle
@@ -348,12 +348,12 @@ Condition
348348
```juvix
349349
commitGuard
350350
(tt : TimestampedTrigger CommitmentTimerHandle Anoma.Msg)
351-
(cfg : EngineCfg CommitmentCfg)
351+
(cfg : CommitmentCfg)
352352
(env : CommitmentEnv)
353353
: Option CommitmentGuardOutput :=
354354
case getEngineMsgFromTimestampedTrigger tt of {
355355
| some EngineMsg.mk@{
356-
msg := Anoma.PreMsg.MsgCommitment (CommitmentMsg.Request _);
356+
msg := Anoma.Msg.Commitment (CommitmentMsg.Request _);
357357
} := some GuardOutput.mk@{
358358
action := commitActionLabel;
359359
args := [];
@@ -371,7 +371,7 @@ commitGuard
371371
```juvix
372372
CommitmentBehaviour : Type :=
373373
EngineBehaviour
374-
CommitmentCfg
374+
CommitmentLocalCfg
375375
CommitmentLocalState
376376
CommitmentMailboxState
377377
CommitmentTimerHandle

docs/arch/node/engines/commitment_config.juvix.md

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ tags:
1818
import prelude open;
1919
import arch.node.engines.commitment_messages open;
2020
import arch.system.identity.identity as Identity;
21+
import arch.system.identity.identity as Identity;
2122
import arch.node.types.engine open;
2223
import arch.node.types.messages open;
2324
import arch.node.types.identities open;
@@ -29,20 +30,20 @@ tags:
2930

3031
The commitment engine configuration contains static information for commitment engine instances, namely the signer and the backend.
3132

32-
## The Commitment Configuration
33+
## The Commitment Local Configuration
3334

34-
The configuration of a Commitment Engine instance includes the identity's signing capabilities.
35+
### `CommitmentLocalCfg`
3536

36-
### `CommitmentCfg`
37+
The type for engine-specific local configuration.
3738

38-
<!-- --8<-- [start:CommitmentCfg] -->
39+
<!-- --8<-- [start:CommitmentLocalCfg] -->
3940
```juvix
40-
type CommitmentCfg := mk@{
41+
type CommitmentLocalCfg := mk@{
4142
signer : Identity.Signer Backend Signable Commitment;
4243
backend : Backend;
4344
};
4445
```
45-
<!-- --8<-- [end:CommitmentCfg] -->
46+
<!-- --8<-- [end:CommitmentLocalCfg] -->
4647

4748
???+ code "Arguments"
4849

@@ -52,17 +53,29 @@ type CommitmentCfg := mk@{
5253
`backend`:
5354
: The backend to use for signing.
5455

56+
## The Commitment Configuration
57+
58+
### `CommitmentCfg`
59+
60+
<!-- --8<-- [start:CommitmentCfg] -->
61+
```juvix
62+
CommitmentCfg : Type :=
63+
EngineCfg
64+
CommitmentLocalCfg;
65+
```
66+
<!-- --8<-- [end:CommitmentCfg] -->
67+
5568
#### Instantiation
5669

5770
<!-- --8<-- [start:commitmentCfg] -->
5871
```juvix extract-module-statements
5972
module commitment_config_example;
6073
61-
commitmentCfg : EngineCfg CommitmentCfg :=
74+
commitmentCfg : CommitmentCfg :=
6275
EngineCfg.mk@{
6376
node := PublicKey.Curve25519PubKey "0xabcd1234";
6477
name := "commitment";
65-
cfg := CommitmentCfg.mk@{
78+
cfg := CommitmentLocalCfg.mk@{
6679
signer := Identity.Signer.mkSigner@{
6780
sign := \{_ x := Signature.Ed25519Signature "0xabcd1234"};
6881
};

docs/arch/node/engines/decryption.juvix.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ decryption keys.
6464
```juvix
6565
DecryptionEngine : Type :=
6666
Engine
67-
DecryptionCfg
67+
DecryptionLocalCfg
6868
DecryptionLocalState
6969
DecryptionMailboxState
7070
DecryptionTimerHandle

0 commit comments

Comments
 (0)