Payment Service Contract
The Payment Service handles users payments to fund the verification of their proofs.
To be able to use the batcher, a user must fund its transactions. For this, there is a simple Batcher Payment System.
The Batcher has an associated Batcher Payments smart contract, which is in charge of receiving user's payments, and it guarantees that it can only spend these funds to send users' proofs to Aligned.
Users must first deposit into this contract, via a normal transfer to its address, where the Batcher Payment System will update the User's balance.
Users send proofs to the Batcher, which checks whether there are enough funds. Once a batch is complete, the Batcher calls its smart contract with the collected user data
The smart contract deducts funds from senders' balances and creates a new Batch in the Aligned Service Manager, including tokens for batch verification payment to the Aggregator.
Users can then withdraw extra funds deposited to the Batcher Payments smart contract, or leave them to fund future proofs. To avoid causing a Denial of Service on the Batcher, Users must first call the contract's unlock
function, and then call withdraw
at least 100 blocks later, to finish their withdrawal process. This enables the Batcher to be sure the User will have funds to pay for his proofs when createNewTask
is called.
This way, the Batcher can only use the User's funds to pay for the verification of the User's proofs. The Batcher Payment Service guarantees that the Batcher will not be able to spend the user funds for anything other than submitting the user's proofs to Aligned.
The flow is:
When the batcher calls the smart contract to create a new batch, it gets the batch merkle tree leaves, with each leaf, signed by the user.
The contract then rebuilds the merkle tree to check the batch merkle root and verifies the user signatures.
Each signature also contains a nonce that can only be used once per user, to avoid the batcher being able to reuse the same signature.
Only if the merkle root and the signatures are valid, the contract will discount the corresponding funds from the user's balance and create a new batch in the Aligned Service Manager.
Payment service architecture and flow
Details of the contract
API
Receive funds
This function will be called every time a User transfers funds to the smart contract. It will not only receive the funds, but it will also register internally how much the User deposited, to keep track of each User's funds separately.
Create New Task
This function will be executed only by the Batcher when it has a batch to post to Aligned. It contains all the information needed to post the batch in Aligned Service Manager (batchMerkleRoot
and batchDataPointer
), plus an array containing which are the proofSubmitters
, to discount gasPerProof
from these, and also the gasForAggregator
, declaring how much will need to go pay for the response of the batch.
Unlock
Any user can call this function to unlock its funds for withdrawal after 100 blocks.
Note that if the user funds are unlocked, the batcher will reject any new proofs from this user until the funds are locked again.
Lock
Any user can call this function to lock its funds again after unlocking.
Withdraw
Any User can call this function to withdraw any amount of their available balance from the contract, only when their funds are unlocked.
Last updated