PCL Quickstart
A quickstart guide to using the PCL CLI
Introduction
This guide will walk you through the process of creating, testing, and submitting an assertion using the PCL (Phylax Credible Layer) CLI. By the end of this tutorial, you’ll understand how to:
- Set up your project structure
- Write a simple assertion
- Test your assertion
- Build and store your assertion
- Submit your assertion to the Credible Layer
You can find the example used in this guide plus some additional examples in the pcl repository.
Prerequisites
Before you begin, make sure you have:
- PCL CLI installed (see the Installation Guide)
- Solidity knowledge (basic understanding of contracts and functions)
- A wallet for authentication (MetaMask or similar)
- Taken a look at the Assertion Guide to understand the basics of assertions
- Foundry installed (see the Foundry Installation Guide)
1. Project Setup
First, let’s set up a project with the correct directory structure:
Next, in order to make sure that forge works correctly, we need to the root folder of the project to be a git repository.
Installing the credible-std Library
Next, you need to install the credible-std
library, which provides the base contracts and utilities for writing assertions:
After installation, create a remappings.txt
file at the root of your project with the following content:
These remappings will ensure that your imports work correctly when referencing the credible-std library. The PCL CLI will automatically detect and use these remappings when compiling your contracts.
Next, let’s create the smart contract that our assertion will monitor. This is a simple Ownable
contract that tracks ownership of a contract.
Create a file src/Ownable.sol
:
2. Writing Your First Assertion
Assertions in PCL are Solidity contracts that inherit from the Assertion
base contract. They define checks that can be run against smart contracts to verify specific properties.
Let’s create a simple assertion that checks if an Ownable
contract’s ownership has changed after a transaction.
For a detailed breakdown of the assertion code, see the Assertion Guide.
Create a file assertions/src/OwnableAssertion.a.sol
:
Key Components of an Assertion:
- Inheritance: All assertions must inherit from the
Assertion
base contract. - Constructor: Initialize references to the contracts you want to monitor.
- Triggers Function: Register which assertion functions should be triggered.
- Assertion Functions: Implement the actual checks using pre and post transaction states.
3. Testing Your Assertion
To test your assertion, create a test file in the assertions/test
directory:
Create a file assertions/test/OwnableAssertion.t.sol
:
4. Running Tests
Use the PCL CLI to run your tests:
This command will compile your assertion and run the tests. You should see output looking like this indicating that the tests have passed:
Troubleshooting Test Issues
If your tests fail, check for these common issues:
- Compilation errors: Ensure your Solidity syntax is correct
- Incorrect imports: Verify all import paths are correct
- State mismatch: Make sure your test properly sets up the initial state
- Assertion logic: Double-check the logic in your assertion function
5. Building Your Assertion
Before you can submit your assertion, you need to build it:
This will compile your assertion and generate the necessary artifacts.
6. Authenticating with PCL
Before submitting your assertion, you need to authenticate:
This will open a browser window where you can connect your wallet and authenticate with the Credible Layer.
If authentication fails, ensure:
- Your wallet has the correct network selected
- You have an internet connection
- The PCL CLI is properly installed
7. Storing Your Assertion
Next, store your assertion in the Assertion Data Availability layer (Assertion DA):
This command submits your assertion’s bytecode and source code to be stored by the Assertion DA, making it available for verification by the network.
8. Submitting Your Assertion
Finally, submit your assertion to the Credible Layer dApp:
This will prompt you to select the project and assertion(s) you want to submit. Follow the interactive prompts to complete the submission.
Alternatively, you can specify the project and assertion directly:
Conclusion
Congratulations! You’ve successfully created, tested, and submitted your first assertion using the PCL CLI. You can now create more complex assertions to verify various properties of smart contracts.
Next Steps
- Try more complex assertions: Check out the examples repository for more advanced assertion patterns
- Integrate with your own projects: Apply assertions to your existing smart contracts
- Join the community: Share your assertions and learn from others in the Phylax Telegram
For more detailed information about the PCL CLI and its commands, see the CLI Reference Guide.
For a comprehensive list of terms and concepts used in PCL, see the Glossary.