Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LimeChain's proposal for a research grant for the Polkadot Protocol Conformance Tests RFP #1950

Merged
merged 6 commits into from
Oct 4, 2023
159 changes: 159 additions & 0 deletions applications/Polkadot-Protocol-Conformance-Tests.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@
# Polkadot Protocol Conformance Tests Research Proposal

- **Team Name:** [LimeChain](https://github.com/LimeChain)
- **Payment Address:** 15reUHgnkE9QeH9zUoduCVYAbksTmQXvpMd6L95rBhTNFuGw (USDT)
- **[Level](https://github.com/w3f/Grants-Program/tree/master#level_slider-levels):** 3

## Project Overview :page_facing_up:

This research proposal is in response to the currently open [Polkadot Protocol Conformance Tests RFP](https://github.com/w3f/Grants-Program/blob/master/docs/RFPs/Open/polkadot-protocol_conformance_tests.md).

### Overview

Polkadot has made substantial progress over the last few years in terms of client diversification. Currently, there are 4 existing host implementations with varying features and protocol support: [Polkadot](https://github.com/paritytech/polkadot) by Parity, [Kagome](https://github.com/soramitsu/kagome) by Soramitsu, [Gossamer](https://github.com/ChainSafe/gossamer/) by ChainSafe, and [Fruzhin](https://github.com/limechain/fruzhin) by LimeChain. Having a healthy client diversity is beneficial to every blockchain protocol as it becomes more decentralised and less bug-prone. Neglecting these aspects has resulted in halting block production for some blockchain protocols in the past.

The nature of software is such that it's never perfect, and bugs happen. Therefore, multiple host implementations come with a higher probability of implementation-specific issues. It's important for a blockchain protocol that takes great pride in its decentralisation, such as Polkadot, to have a protocol compliance testing suite that verifies the behaviour of each implementation. The more comprehensive the testing suite is, the stronger security guarantees the protocol can provide.

The goal of this project is to prepare for the redesign of the existing [conformance tests repository](https://github.com/w3f/polkadot-tests). Our team envisions the redesigned testing suite to be easily extensible and flexible, welcoming contributors to enhance it with their domain-specific knowledge. Concerns have been raised regarding the "adapter" approach that the existing testing suite has taken and that the chosen language ([Julia](https://julialang.org/)) is out of sync with the one for Polkadot ([Rust](https://www.rust-lang.org/)). This proposal aims to lay the groundwork for resolving these issues by delving deep into the biggest obstacle that stands in the way: finding the correct level of abstraction and tooling that will be the cornerstone for every kind of test scenario.

### Project Details

### A host-agnostic approach

A conformance testing suite should be host-agnostic, meaning that, for the most part, the tests shouldn't be concerned with the specific Host implementation against which they are being executed. The Host exposes several interfaces that enable conformance testing; however, it’s a complex piece of engineering, and there will always be protocols and functionalities without an exposed interface. Moreover, there are integration tests that can't be conducted using an API. These scenarios are as important as the previous ones because the Host can't function properly if the modules don't work seamlessly with one another.

### Host API

The Host API consists of a set of functions that the Host exposes to the Runtime. These functions are used to access external resources for various purposes, including storage access, manipulation, memory allocation, and more. If a method within the API contains a bug, it has the potential to push the Host into an incorrect state transition. Such a scenario could lead to undefined consequences, particularly if a significant number of nodes experience the same issue.

### SCALE

Substrate employs a lightweight and efficient encoding and decoding mechanism to optimise the transmission and reception of data across the network. This protocol, known as the SCALE codec, plays a vital role in serialising and deserialising data. It serves as a critical component for data transfer across the peer network and facilitates communication between the Runtime and the Host. Consequently, the presence of comprehensive tests for SCALE encoding and decoding holds immense significance in ensuring the proper functionality of the Host.

### State Trie

The state trie is another crucial part of the Host. A radix-16 state is the data structure that Substrate uses to store the state of the blockchain. Without thoroughly tested state trie functionalities, the Host may transition to an incorrect state and get slashed if it's a block producer.

### BABE & GRANDPA

[BABE](https://spec.polkadot.network/sect-block-production) & [GRANDPA](https://github.com/paritytech/finality-grandpa) are the bread and butter of the consensus-reaching module for Polkadot. However, finding the right tools and approach to test the block production and finalisation protocols independently of the Host’s environment is a challenge that is yet to be overcome by any team.

### Zombienet

[Zombienet](https://github.com/paritytech/zombienet) aims to be a testing framework for Substrate-based blockchains, providing a CLI tool that allows users to spawn and test ephemeral networks. The assertions used in the tests can include on-chain storage, metrics, logs, and custom JavaScript scripts that interact with the chain

Our team has successfully utilised Zombienet to run PVF conformance tests as part of another W3F grant. This is the reason why we believe that Zombienet has the potential to be the go-to framework for running conformance tests on the Hosts. The research is going to focus on Zombienet, as well as on the new [Zombienet SDK](https://github.com/paritytech/zombienet-sdk).
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you please elaborate on how Zombienet was used to integrate with the PVF conformance test-suite? And briefly compare and contrast with the current project?

Copy link
Contributor

Choose a reason for hiding this comment

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

In the PVF conformance test-suite, we leveraged Zombienet's custom WASM configuration option(genesis_wasm_path) in order to inject malicious PVFs. Additionally, the team used Zombienet's DSL language in order to assert on the behaviour of the network. You can find the tests here. They're split into different folders and files mainly because it's easier to read and understand what's happening. The main difference between Polkadot and Kagome's tests is the startup command. There are also one or two differences in terms of logs emitted by each Host.

Copy link
Contributor

Choose a reason for hiding this comment

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

When it comes to comparing the 'adapter' approach with the Zombienet approach, the biggest difference is in terms of maintainability and being forward-compatible. The adapter approach is dependent on each Host not changing its implementation details. If the function's name is changed or is extracted in another module/repository, the testing suite should change as well; otherwise, it won't compile. If a function's logic is changed, then this may result in tests failing. These are all cases very relevant for Hosts in early stages of their implementation. Whereas, changes to CLI parameters and public APIs (which Zombienet uses under the hood) happen less often, which makes the approach better in terms of maintainability


### Research Scope

The main focus of the research will be on investigating each of the aforementioned protocols and functionalities and how they can be tested in a host-agnostic manner. Based on our preliminary research and the work we've conducted on the PVF conformance testing suite, our team believes that Zombienet can serve as the foundation for the testing suite. The team will examine whether Hosts and Zombienet have the required feature set to support such testing scenarios. If this is not achievable, the team will document the missing components so that they can be identified and potentially contributed in a future proposal.

Our team acknowledges that, for certain Hosts, having the Host API, SCALE, and State Trie as standalone artifacts could be beneficial for Host developers during the early phases of their implementation. However, this proposal primarily focuses on adopting a host-agnostic approach for Hosts that are already functioning with the already existing tests. Depending on the research outcomes, our team may subsequently introduce a new proposal involving the redesign of the conformance repository. In this redesign, the tests would be separated into a standalone artifact and transformed into Zombienet tests.
Copy link
Contributor

Choose a reason for hiding this comment

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

this sounds reasonable, and aligns with the definition of conformance tests. However, it is interesting to check if the conformance tests can be easily distilled to generate stand-alone tests to support early-stage host implementers.

Copy link
Contributor

Choose a reason for hiding this comment

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

We believe that generating stand-alone tests is completely feasible and it’s scope could be a completely different project as it will require delving deep in each module and understanding it to the smallest detail. Our proposal, however, aims to discover a new and better approach to running the tests for advanced Host implementations. We believe that coming up with a better approach for testing Hosts is more important than generating stand-alone artefacts as there are currently 3 advanced Host implementations(Polkadot, Kagome, Gossamer) and one in early stages of development(Fruzhin). As stated in the proposal, we have plans to work on expanding the tests and extracting them in stand-alone artefacts in the future.


### Ecosystem Fit

By delivering a research document containing insightful information about the necessary steps to commence the redesign of the Polkadot Conformance Testing repository, we aim for it to serve as a catalyst to initiate the development process

Initially, the Polkadot Conformance Testing repository will be situated in close proximity to the realm of Polkadot Hosts. Its primary target audience will be Host developers seeking comprehensive testing for their Hosts. Other individuals who might find this project valuable include experts from the Polkadot specification team, who can contribute their expertise in specific scenarios.

## Team 👥

### Team members

- Viktor Todorov
- Maksim Dimitrov
- Kristiyan Veselinov

### Contact

- **Contact Name:** Kristiyan Veselinov
- **Contact Email:** [email protected]
- **Website:** [https://limechain.tech](https://limechain.tech/)

### Legal Structure

- **Registered Address:** Bulgaria, Dragan Tsankov 23A, 1113, Sofia, Bulgaria
- **Registered Legal Entity:** LimeLabs Ltd.

### Team's experience

At LimeChain, we possess considerable expertise in developing various tools, including [Gosemble, a framework for building Substrate compatible Runtimes in Go](https://github.com/LimeChain/gosemble), [Fruzhin, a Host implementation in Java](https://github.com/limechain/fruzhin), [a framework for runtimes in AssemblyScript](https://github.com/LimeChain/subsembly), a framework for runtimes in AssemblyScript. On top of that, we’re working on a [Parachain Validation Conformance Testing suite](https://polkadot.polkassembly.io/motion/389), have substantial experience in Rust/WebAssembly developer tooling from [Matchstick](https://github.com/limeChain/matchstick/) and actively contribute to infrastructure projects in Cosmos and Hedera Hashgraph.

### Team Code Repos

- [https://github.com/LimeChain](https://github.com/LimeChain)

Please also provide the GitHub accounts of all team members. If they contain no activity, references to projects hosted elsewhere or live are also fine.

- [https://github.com/vikinatora](https://github.com/vikinatora)

### Team LinkedIn Profiles (if available)

- [https://www.linkedin.com/in/viktor-todorov-8a7434122/](https://www.linkedin.com/in/viktor-todorov-8a7434122/)
- [https://www.linkedin.com/in/chris-veselinov/](https://www.linkedin.com/in/chris-veselinov/)

## Development Status :open_book:

No actual development has been made for this RFP. However, the team has spent a significant amount of time delving into the Host’s specification as part of the Java Host implementation we're currently working on. Additionally, our work on the PVF conformance testing suite has enhanced our understanding of how to address challenging-to-test sections of the code.

## Development Roadmap :nut_and_bolt:

The primary framework under consideration for this research will be Zombienet, as it already provides the groundwork for these types of tests. Each of the steps outlined below will be dedicated to investigating the creation of Zombienet tests for the specified functionalities. The team will also document in the research report the development steps required to enable testing of the specified functionality using Zombienet.

Outlined below are the testing scenarios for each Host module that will be the focus of the research:

1. Host API
1. Storage
2. Child Storage
3. Hashing
4. Trie
2. SCALE
Copy link
Contributor

Choose a reason for hiding this comment

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

SCALE codec already has a comprehensive test-suite here which can be leveraged upon.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, that’s correct. If it’s an interest to the W3F and the community we can add more SCALE codec test scenarios to the PoC if it proves to be feasible. We’re trying to implement a different approach because as we mentioned the “adapter” approach is not very flexible

1. SCALE encoding
2. SCALE decoding
3. State Trie
1. Trie encoding
2. Trie decoding
3. Trie proof generation
4. BABE
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you elaborate more on this? Does block import include forking and longest chain related properties?

Copy link
Contributor

Choose a reason for hiding this comment

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

We’ve intentionally left out specific properties for BABE and GRANDPA as our main goal will be to establish a way to test any BABE functionality/property which implicitly includes forking and longest chain related properties. If you have specific properties that you’d want us to test, feel free to note them here as we won’t be able to cover all of them in the specified timeline.

1. Block import
2. Block validation
5. GRANDPA
Copy link
Contributor

Choose a reason for hiding this comment

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

similarly, does this cover voting and justifications of the finalisation mechanism?

Copy link
Contributor

Choose a reason for hiding this comment

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

We’ve intentionally left out specific properties for BABE and GRANDPA as our main goal will be to establish a way to test any GRANDPA functionality/property which implicitly includes voting and justifications. If you have specific properties that you’d want us to test, feel free to note them here as we won’t be able to cover all of them in the specified timeline.

1. Block import
2. Block validation

### Overview

- **Total Estimated Duration:** 10 working weeks
- **Full-Time Equivalent (FTE):** 2
- **Total Costs:** $61600

### Milestone 1 — Polkadot Conformance Testing Suite Research

- **Estimated duration:** 10 working weeks
- **FTE:** 2
- **Costs:** $61600

| Number | Deliverable | Specification |
| --- | --- | --- |
| 0a. | License | Apache 2.0 |
| 0b. | Documentation | We will provide inline documentation, as well as README file with how the suite can be executed. Additional information will be provided on how to contribute. |
| 0c. | Testing and Testing Guide | Documentation will be provided that showcases how the testing suite can be executed for different scenarios and hosts. |
| 0d. | Docker | We will provide a Dockerfile(s) that can be used to test all the functionality delivered with this milestone. |
| 0e. | Article | We will publish an article that explains what was done/achieved as part of the grant. |
| 1. | Host API Research | Research the feasibility of using Zombienet as the framework for executing Host API tests. |
| 2. | SCALE Research | Research the feasibility of using Zombienet for conducting SCALE encoding and decoding tests. |
| 3. | State Trie Research | Research the feasibility of using Zombienet for conducting State Trie encoding, decoding and generation tests. |
| 4. | BABE Research | Research the feasibility of using Zombienet for conducting BABE tests. |
| 5. | GRANDPA Research | Research the feasibility of using Zombienet as the framework for conducting GRANDPA tests. |
| 6. | Research Findings | A research document will be delivered documenting the team’s findings, as well as outline a high-level path forward for the conformance testing suite. |
| 7 | PoC development | Create one test for each module from the previous steps if the research outcome indicates that it’s possible. |

## Future Plans

Based on the research findings, our team could formulate a proposal for implementing these tests and restructuring the conformance testing suite with the new approach, and/or contributing the necessary features that would enable Zombienet to be utilised for these purposes.

## Additional Information :heavy_plus_sign:

**How did you hear about the Grants Program?**

At LimeChain, we have been contributors to the Polkadot ecosystem for the last 3+ years as we believe in a multi-chain future, based on interoperability and decentralisation. Principles that are built into the core of the Polkadot network. We possess considerable expertise in developing various tools, including [Gosemble, a framework for building Substrate compatible Runtimes in Go](https://github.com/LimeChain/gosemble), [a framework for runtimes in AssemblyScript](https://github.com/LimeChain/subsembly),, and [Parachain Validation Conformance Testing](https://polkadot.polkassembly.io/motion/389). Additionally, we have substantial experience in Rust/WebAssembly developer tooling from [Matchstick](https://github.com/limeChain/matchstick/) and have actively contributed to infrastructure projects in Cosmos, Near, Filecoin, Ledger and Hedera Hashgraph.