-
Notifications
You must be signed in to change notification settings - Fork 122
Operator Contract
Loopring Protocol 3.0 is a protocol for DEXs that uses zero-knowledge proofs (zkSNARKs) for scalability. Requests (ring settlements, deposits, ...) are bundled into blocks and these blocks are committed and verified on-chain. Data is stored in Merkle trees, but only the Merkle tree root is actually stored on-chain. For this to work state changes need to be done sequentially: we need to start from a known old state (the Merkle root stored on-chain) and go to a new state (the new Merkle root). The entity that is responsible for creating, committing and proving blocks is called the operator.
The operator can be a single entity. In that case this single entity is responsible for creating all the blocks and generating all the proofs. While this doesn't have any impact on the security of the protocol there are still good reasons for allowing multiple operators to create and prove blocks:
- The proof generation is computationally heavy. Because committing blocks and verifying blocks are done independently of each other proofs can be generated in parallel by the different operators.
- For off-chain requests the operator can choose which requests to include (or not to include) in a block. In other words, the operator can censor any request he wants for any reason. When anyone can become an operator an operator can still try to censor requests but another operator will be able to include the request in a block.
- Multiple operators makes the protocol more decentralized. A single operator also means a single point of failure.
Once the operator has committed a block he needs to do the following:
- For all blocks types: Generate a proof and verify the proof on-chain. If the operator fails to do so the operator is punished by burning the complete stake.
- For withdrawal blocks: After the block is verified all withdrawals need to distributed. If the operator fails to do this in time he is punished by burning a part of the stake (depends on the number of withdrawals).
- For deposit and on-chain withdrawal blocks: Once the block is finalized the block fee can be withdrawn
If a sup-operator does not verify a block in time the block needs to be reverted.
Write an Operator contract that allows multiple independent sub-operators to work together.
Requested properties:
- Only a single operator can commit blocks at any time.
- Operators need to stake LRC. The time allocated to a certain operator is proportional to the amount staked.
- The logic required to calculate the active operator (the operator that can commit blocks) should be very cheap (O(1)).
- An operator is selected in a fair way that cannot be exploited in any way.
- At any time anyone should be able to become an operator and also stop being an operator. When someone wants to stop being an operator he should immediately stop getting time to commit blocks. Make sure the operator can still be punished for blocks that still need additional work!
- The correct operator needs to be punished when a block committed by him isn't proven in time or when the withdrawals aren't distributed.
- The correct operator needs to get the block fee (only applicable for blocks containing on-chain requests).
Clone https://github.com/Loopring/protocols.git
. Checkout the ethnewyork
branch. This branch contains pre-compiled circuit binaries for linux and mac.
Navigate to protocols/packages/loopring_v3
and set everything up:
./install
npm run compile
If you run macOS you need to delete build/circuit/dex_circuit
(which is the linux binary) and rename build/circuit/dex_circuit_mac
to build/circuit/dex_circuit
.
A minimal implementation of an Operator contract is provided in contracts/test/Operator.sol
. Modify this contract to add the requested features.
You can use test/testOperator.js
to test your contract. This test file includes the different scenarios the operator contract needs to handle. Modify this file to test your operator contract.
In a separate terminal run (and keep open):
npm run ganache
You can then run the tests like this:
npm run test -- transpiled/test/testOperator.js -x
Loopring Foundation
nothing here