Integrate da
This document shows you how to integrate a third-party data availability (DA) solution into your CDK stack.
Prerequisites¶
Tip
Make sure you have upgraded your CDK stack if necessary.
Set up contracts¶
This section shows you how to create a custom CDK validium DAC contract.
-
Clone zkevm-contracts.
-
cdintozkevm-contractsand checkout tagv8.0.0-rc.3-fork.12. -
Run
npm installfrom the root. -
cdto thecontracts/v2/consensus/validiumdirectory.Tip
- Until further notice, these contracts run on the banana release.
-
Create your custom contract in the same directory, and make sure it implements the IDataAvailabilityProtocol interface.
Tip
- Use the Polygon DAC implementation contract: PolygonDataCommittee.sol as a guide.
- The contract supports custom smart contract implementation and, through this, DACs can add their custom on-chain verification logic.
-
You can leave the
verifyMessagefunction empty but make sure thegetProcotolNamefunction returns a unique name (such as Avail, Celestia, etc). The following example code comes from the PolygonDataCommitee.sol implementation.// Name of the data availability protocol string internal constant _PROTOCOL_NAME = "<MY_PROTOCOL_NAME>"; ... /** * @notice Return the protocol name */ function getProcotolName() external pure override returns (string memory) { return _PROTOCOL_NAME; } -
Update the /deployment/v2/4_createRollup.ts script to add your contract name.
const supporteDataAvailabilityProtocols = ["<CONTRACT_NAME>"]; -
Make your contract deployable by copying, editing for your custom implementation, and pasting back in, the
ifstatement from the /deployment/v2/4_createRollup.ts#L251 node creation script.
PolygonValidiumEtrog.sol solution
The Etrog DAC integration contract is still work-in-progress at the time of writing but there are some interesting things to note.
-
It implements the function
verifyMessagefunction:// Validate that the data availability protocol accepts the dataAvailabilityMessage // note This is a view function, so there's not much risk even if this contract was vulnerable to reentrant attacks dataAvailabilityProtocol.verifyMessage( accumulatedNonForcedTransactionsHash, dataAvailabilityMessage );where
accumulatedNonForcedTransactionsHashis used for verification against the protocol anddataAvailabilityMessageis a byte array containing the signature and addresses of the committee in ascending order. -
It also implements a function to set the data availability protocol at line 287 to see how they do this.
/** * @notice Allow the admin to set a new data availability protocol * @param newDataAvailabilityProtocol Address of the new data availability protocol */ function setDataAvailabilityProtocol( IDataAvailabilityProtocol newDataAvailabilityProtocol ) external onlyAdmin { dataAvailabilityProtocol = newDataAvailabilityProtocol; emit SetDataAvailabilityProtocol(address(newDataAvailabilityProtocol)); }
Deploy Docker image¶
This section shows you how to deploy the Docker image containing your custom DAC contract.
-
Edit the following parameters in the
docker/scripts/v2/deploy_parameters_docker.jsonfile:"minDelayTimelock": 3600, // BECOMES "minDelayTimelock": 1, -
Edit the following parameters in the
/docker/scripts/v2/create_rollup_parameters_docker.jsonfile:"consensusContract": "PolygonValidiumEtrog", // CHANGE THIS TO YOUR CONTRACT NAME "dataAvailabilityProtocol": "PolygonDataCommittee", // ADD THIS PARAMETER -
Run the following command:
cp docker/scripts/v2/hardhat.example.paris hardhat.config.ts -
Edit docker/scripts/v2/deploy-docker.sh to add the following line:
sudo chmod -R go+rxw docker/gethData before docker build -t hermeznetwork/geth-zkevm-contracts -f docker/Dockerfile . -
In the deployment/v2/4_createRollup.ts file, uncomment the 290-291, and add a
console.logoutput that grabs the address of the DAC:// Setup data committee to 0 await (await polygonDataCommittee?.setupCommittee(0, [], "0x")).wait(); console.log(dataAvailabilityProtocol, "deployed to:", polygonDataCommittee.target); -
Build the image with the following commands:
sudo npx hardhat compile sudo npm run docker:contracts -
Tag the image with the following command, where
XXXXis custom:docker image tag hermeznetwork/geth-zkevm-contracts hermeznetwork/geth-cdk-validium-contracts:XXXX
Set up the node¶
This section shows you how to set up your CDK node that sends and receives data from the DAC.
-
Create a package that implements the
DABackenderinterface and place it under thecdk-validium-node/tree/develop/dataavailabilitydirectory. -
Add a new constant to the /dataavailability/config.go file that represents the DAC.
const ( // DataAvailabilityCommittee is the DAC protocol backend DataAvailabilityCommittee DABackendType = "DataAvailabilityCommittee" )where
DataAvailabilityCommitteematches the_PROTOCOL_NAMEsee in the Set up contracts section. -
OPTIONAL: Add a config struct to the new package inside the main config.go file so that your package can receive custom configurations using the node’s main config file.
-
Instantiate your package and use it to create the main data availability instance, as done in the Polygon implementation.
Test the integration¶
Tip
- By default, all E2E tests run using the DAC.
- It is possible to run the E2E tests using other DAC backends by amending the
test.node.config.tomlfile.
To test your DAC integration, follow the steps below.
-
Create an E2E test that uses your protocol by following the test/e2e/datacommittee_test.go example.
-
Generate a docker image containing the changes to the node:
make build-docker -
Build the genesis file for the node:
- First, clone the cdk-validium-node repo and checkout v0.6.4-cdk.5.
- Edit the
test/config/test.genesis.config.jsonfile taking values in the generated output files created previously in the contract repo’sdocker/deploymentOutputsfolder:
Parameters to change
l1Config.polygonZkEVMAddress ==>rollupAddress@create_rollup_output.jsonl1Config.polygonRollupManagerAddress==>polygonRollupManager@deploy_output.jsonl1Config.polTokenAddress==>polTokenAddress@deploy_output.jsonl1Config.polygonZkEVMGlobalExitRootAddress==>polygonZkEVMGlobalExitRootAddress@deploy_output.jsonrollupCreationBlockNumber==>createRollupBlock@create_rollup_output.jsonrollupManagerCreationBlockNumber==>deploymentBlockNumber@deploy_output.jsonroot==>root@genesis.jsongenesis==>genesis@genesis.jsonImportant
- You should follow this step every time you build a new Docker image.
-
Update the contracts Docker image tag with the custom tag you created at the deploy Docker image section, step 7, by amending the node’s Docker compose file.
-
Modify the Makefile so it can run your test. Use the Polygon DAC Makefile as an example.