1.0.0 • Published 3 years ago
@nomad-xyz/contracts-da-bridge v1.0.0
Nomad DA Bridge
Solidity implementation of the Nomad Avail Data Attestation Bridge. This application receive data roots from the Avail chain and stores them in a mapping of block numbers to data roots.
Setup
yarn bootstrap:yarn cleanandyarn build
Build
yarn build: compile smart contracts and create definitions for the SDK
Test
For testing, we use Foundry.
- Run
yarn build:accumulator-clifrom the root directory of the monorepo. It will build a rust-based cli tool that creates Sparse Merkle Tree proofs for arbitrary data. It's used in our testing suite via the--ffiflag for Forge. The binary is built in there/scriptstop-level directory of the monorepo --ffimeans that Forge will run arbitrary shell commands as part of the testing suite. You should never runforge --ffiwithout knowing what exactly are the shell commands that will be executed, as the testing suite could be malicious and execute malicious commands. This is why the feature is disabled by default and must be explicitly enabled.yarn test:unitwill run all unit tests. Note that--ffiis enabled by default,yarn snapshotwill create a new.gas-snapshot. You can inspect the different gas usage viagit diff- 'yarn snapshot:check' will run the test suite and check gas consumption against the existing
.gas-snapshot. It willpassonly if there is no change in the gas consumption yarn gen-proofwill execute theaccumulator-clibinary
Suggested workflow
- Define feature
- Write tests based on Foundry best practices and the existing test structure
- Run test suite with
FOUNDRY_PROFILE=core forge test --ffi -vvvand verify that your new testsFAIL - Write the new feature
- Run again the test suite and verify that the tests
PASS - Run
yarn snapshotto produce the new gas snapshot. You can't useyarn snapshot:check, since you added new tests that are not present in the current.gas-snapshot. Gas snapshots showcase how much gas your tests consume and are useful to serve as a benchmark for the gas consumption of your code. As you write new features and/or refactor your code, the gas snapshot can change, illustrating where your changes affected the already defined codepaths. You can read more about gas snapshots on the Foyndry book - Run
yarn storage-inspect:checkto see if the storage layout of the smart contracts have changed. If it has, this could potentially create problems in the upgrade process. If the new layout is correct, runyarn storage-inspect:generateto create a new layout file (replacing the old one) and commit the new file. If we don't commit the new layout, the CI will fail.
Tip: It is advised to run the forge commands on their own and not via yarn or npm for faster development cycle. yarn will add a few seconds of lag, due to the fact that it has to spin up a Node runtime and the interpret the yarn source code.
Static Analysis
We suggest all contributors to use slither while developing, to avoid common mistakes.
- Install Slither
- Run
yarn test:static-analyze
We use a yarn command because we need to link the top-level node_modules directory in the core-contracts package. It's a known issue for which the workaround is to link the directory.
1.0.0
3 years ago