Skip to content

Commit

Permalink
testing
Browse files Browse the repository at this point in the history
  • Loading branch information
glasgowm148 committed Aug 30, 2024
1 parent 4ce4649 commit 5b2d50e
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 12 deletions.
15 changes: 8 additions & 7 deletions docs/dev/data-model/data-structures.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
---
tags:
- Data Structures
- Data Structures
- Cryptography
- Security
---

# Data Structures
# Data Structures in Ergo

In Ergo, several key data structures are employed to support its blockchain and smart contract functionality. Here's a list of the main data structures used within the Ergo ecosystem:
In Ergo, several key data structures are employed to support its blockchain and smart contract functionality. These data structures are designed to ensure efficient and secure access to data, guaranteeing optimal performance and data integrity. Here's a list of the main data structures used within the Ergo ecosystem:

## 1. **AVL Trees (Authenticated Dynamic Dictionaries)**
- **Purpose**: AVL Trees in Ergo are used to store and authenticate dynamic sets of data in a compact and efficient manner. They are particularly useful for stateful smart contracts.
- **Usage**:
- **Purpose**: AVL Trees in Ergo are a specialized type of self-balancing binary search tree, used to store and authenticate dynamic sets of data in a compact and efficient manner. They ensure efficient and secure access to your data, guaranteeing optimal performance and data integrity.
- **Usage**:
- In the storage of UTXO states, where efficient verification of state changes is required.
- In applications like off-chain code and distributed systems managing the Plasma infrastructure, where privacy-preserving transactions need to verify inclusion or exclusion of certain elements without revealing all details.
- **Documentation Reference**: [AVL Trees in Ergo](avl.md), [Plasma](plasma.md)
Expand All @@ -19,7 +21,7 @@ In Ergo, several key data structures are employed to support its blockchain and
- **Usage**:
- In the construction of the [Transaction Merkle Tree](tx-merkle.md), combining all transactions and their corresponding spending proofs into a single Merkle Tree.
- In the [Extension Block Merkle Tree](merkle-extension.md), securing key-value data like miner votes and protocol parameters.
- In creating [Merkle Batch Proofs](merkle-batch-proof.md), allowing efficient verification of multiple data elements within a Merkle Tree.
- In creating [Merkle Batch Proofs](merkle-batch-proof.md), allowing efficient validation of the integrity and authenticity of data transactions. It supports the serialization and deserialization of Merkle proofs in batches, significantly improving the speed and efficiency of data verification processes.
- In generating compact proofs of state transitions, enabling lightweight clients to securely participate in the network. An example of how a lite client can check a Merkle-tree-based membership proof is detailed in the [Lite Client Checking Merkle Proof](merkle-light-proof.md) documentation.
- **Documentation Reference**: [Merkle Trees in Ergo](merkle-tree.md)

Expand Down Expand Up @@ -79,4 +81,3 @@ UTREEXO is a more efficient alternative for representing the UTXO set compared t
## Partially Stateless Clients

Ergo currently employs an approach outlined in [this paper](https://eprint.iacr.org/2016/994.pdf) to support partially stateless clients. This approach balances security and efficiency, as fully stateless clients still depend on archival nodes for storing and updating client proofs.

25 changes: 20 additions & 5 deletions docs/dev/data-model/structures/merkle/merkle-batch-testing.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
---
tags:
- Merkle
---

# Testing Merkle Batch Proofs

### Testing Merkle Batch Proofs in `sigma-rust` (Rust)
Testing Merkle Batch Proofs is crucial to ensure the correctness of their implementation in the Ergo blockchain. This section provides examples of how to write tests for Merkle Batch Proofs using both Rust (`sigma-rust`) and Scala (`scrypto`). These tests cover the creation, verification, serialization, and deserialization of batch Merkle proofs.

### Rust (`sigma-rust`) Testing

Here is a set of Rust-based tests using the `sigma-rust` library:
In Rust, the `sigma-rust` library provides the necessary tools to create and test Merkle Batch Proofs. Below is a series of tests written using the Rust testing framework.

```rust
#[cfg(test)]
Expand Down Expand Up @@ -80,9 +87,14 @@ mod tests {
}
```

### Testing Merkle Batch Proofs in `scrypto` (Scala)
#### Code References:
- **MerkleTree**: [`merkletree.rs`](https://github.com/ergoplatform/sigma-rust/blob/develop/ergo-merkle-tree/src/merkletree.rs)
- **BatchMerkleProof**: [`batchmerkleproof.rs`](https://github.com/ergoplatform/sigma-rust/blob/develop/ergo-merkle-tree/src/batchmerkleproof.rs)
- **Serialization Methods**: [`scorex_serializable.rs`](https://github.com/ergoplatform/sigma-rust/blob/develop/sigma-ser/src/scorex_serializable.rs)

### Scala (`scrypto`) Testing

Here is a set of Scala-based tests using the `scrypto` library:
For Scala, the `scrypto` library is used to test Merkle Batch Proofs. Below are the test cases using ScalaTest, covering tree creation, proof generation, verification, and serialization.

```scala
import org.scalatest.flatspec.AnyFlatSpec
Expand Down Expand Up @@ -146,4 +158,7 @@ class MerkleBatchProofSpec extends AnyFlatSpec with Matchers {
4. **Serialization and Deserialization**:
- Serialization tests verify that the proofs can be serialized and deserialized without losing integrity, which is crucial for storing and transmitting proofs.

These tests can be run using standard Rust and Scala testing tools (`cargo test` for Rust, `sbt test` for Scala) and are critical for validating the correctness of Merkle Batch Proof implementations in Ergo-based applications.
These tests can be run using standard Rust and Scala testing tools (`cargo test` for Rust, `sbt test` for Scala) and are critical for validating the correctness of Merkle Batch Proof implementations in Ergo-based applications.#### Code References:
- **MerkleTree**: [`MerkleTree.scala`](https://github.com/ScorexFoundation/scrypto/blob/master/src/main/scala/scorex/crypto/authds/merkle/MerkleTree.scala)
- **BatchMerkleProof**: [`BatchMerkleProof.scala`](https://github.com/ScorexFoundation/scrypto/blob/master/src/main/scala/scorex/crypto/authds/merkle/BatchMerkleProof.scala)
- **BatchMerkleProofSerializer**: [`BatchMerkleProofSerializer.scala`](https://github.com/ScorexFoundation/scrypto/blob/master/src/main/scala/scorex/crypto/authds/merkle/serialization/BatchMerkleProofSerializer.scala)

0 comments on commit 5b2d50e

Please sign in to comment.