A cross-chain state synchronization system built on Polymer, enabling seamless state sharing across multiple EVM chains.
- Cross-chain state synchronization using Polymer Protocol's Prover
- Support for multiple EVM chains (Optimism, Base, Mode, Bob, Ink, Unichain)
- Asynchronous state propagation to all chains
- Automatic proof generation and validation with Polymer's Prover API
- Simple key-value storage interface
- Node.js (v18 or higher)
npmoryarn- A wallet with some testnet ETH on all supported chains:
- Optimism Sepolia
- Base Sepolia
- Mode Sepolia
- Bob Sepolia
- Ink Sepolia
- Unichain Sepolia
- Polymer API Key for requesting the cross-chain proof
-
Clone the repository:
git clone https://github.com/stevenlei/polymer-state-sync.git cd polymer-state-sync -
Install dependencies:
npm install
-
Configure environment variables:
- Copy
.env.exampleto.env - Add your private key
- Add RPC URLs for each chain
- Add Polymer Prover addresses for each chain (already defined in
.env.example) - Contract addresses will be automatically updated during deployment
- Copy
You can deploy the contract to either a single chain or all supported chains:
npm run deploy:allThis will:
- Deploy to all supported chains sequentially
- Update contract addresses in
.envautomatically - Show deployment progress and results
npm run deploy:optimism # Deploy to Optimism Sepolia
npm run deploy:base # Deploy to Base Sepolia
npm run deploy:mode # Deploy to Mode Sepolia
npm run deploy:bob # Deploy to Bob Sepolia
npm run deploy:ink # Deploy to Ink Sepolia
npm run deploy:unichain # Deploy to Unichain SepoliaStart the relayer to monitor and propagate state changes:
npm run relayerThe relayer will:
- Monitor events from all chains
- Generate proofs using Polymer Protocol
- Propagate state changes to all other chains asynchronously
Set a value that will be synchronized across all chains:
npm run setQuery a value from any chain:
npm run get-
Smart Contract (
StateSync.sol)- Stores key-value pairs
- Emits events for state changes
- Validates proofs with Polymer's Prover API
-
Relayer (
relayer.js)- Starts with
npm run relayer - Monitors all chains for events
- Generates proofs for state changes
- Propagates changes to all other chains
- Handles async submissions
- Starts with
-
Scripts
setValue.js: Set a value on any chain (Starts withnpm run set)getValue.js: Query value from any chain (Starts withnpm run get)deploy.js: Deploy to specific chain (Starts withnpm run deploy:{chain})deploy-all.js: Deploy to all chains (Starts withnpm run deploy:all)
- Proof validation prevents unauthorized state changes
- Replay attack protection using proof hashes and nonce
- Key ownership validation for updates
Currently supported networks (Sepolia testnet):
- Optimism
- Base
- Mode
- Bob
- Ink
- Unichain
This is a proof of concept and is not intended for production use. It may contain bugs, vulnerabilities, or other issues that make it unsuitable for use in a production environment. I am not responsible for any issues that may arise from using this project on mainnet.
Contributions are welcome! Please feel free to submit a Pull Request.
This project is licensed under the MIT License - see the LICENSE file for details.