
The Matic team has put together a Proof-of-Concept for the Reddit Scaling Bake-Off. We think Matic is the most apt solution for the scaling requirements of Reddit, keeping in mind it’s current and future needs.
We believe that the Matic Layer 2 platform is the most complete solution out there in terms of the features and fits right in with what Reddit requires:
- Security via Plasma predicates on Ethereum: Reliable exits to Ethereum (Proof-of-Stake based decentralized multi-operator Plasma construction which mitigates mass exit occurrence)
- Composability (EVM Support),
- Extremely high scalability with each sidechain (multiple sidechains in future, hence suitable for the scale of Reddit)
- Ability to add custom smart contract features (via Ethereum Plasma predicates) for future product innovation
TL;DR: The Matic sidechain processed 3mn transactions over 12 hours with a total gas fees of USD 3.52 as part of the Great Reddit Scaling Bake-Off PoC.
The PoC used a few addresses only for the purpose of the demo, and the total throughput with millions of user addresses can go up to 7200 TPS per sidechain.
The PoC touches upon various aspects of the solution required – scalability that will need to meet Reddit’s requirements over time (more sub-reddits using Community Points), faster transaction times, inexpensive minting of Community Points, decentralization, accessible developer tooling, use of meta-transactions to pay for gas on behalf of users, open source code, extensibility, ability to exit back to Ethereum, if needed and more.
What is Matic?
Matic Network is a Layer 2 scaling solution for Ethereum that provides hybrid Proof-of-Stake and Plasma-enabled sidechains. We just released version 1 of our mainnet in May 2020 – https://blog.matic.network/the-matic-network-mainnet-is-now-live/.
Matic implements an account-based variant of MoreVP (More Viable Plasma), with support for custom Plasma predicates. The Plasma framework with predicates is used to guarantee the security of assets and specific smart contracts using Plasma predicates, while arbitrary smart contracts are secured by a Proof-of-Stake network, with validators staking Matic tokens on Ethereum. Matic sidechains are essentially EVM-enabled chains and are conducive to ready deployment of Solidity smart contracts, essentially making it an easy tool for Ethereum developers to use it for scaling their dApps/Protocols.
We are submitting the following:
- A live proof-of-concept which demonstrates the scale required for the bakeoff and future requirements
- We did over 3,000,000 (3 million) transactions in our scaling PoC bulk run over a period of ~12 hours (yes that’s 3 mn transactions):
- 1,000,000 point claims (minting & distributing points)
- 1,000,000 subscriptions and 1,000,000 burns
- 1,000,000 transfers
- Proof-of-Concept repo – https://github.com/maticnetwork/reddit-bakeoff-poc
- A detailed explanation of the demo is given here: https://github.com/maticnetwork/reddit-bakeoff-poc/blob/develop/README.md
- The following contracts have been deployed on Mumbai testnet –
- SubredditPoints: 0xc4f93FeF8086c452134B0F15a5AE963ACe6A7748
- Distributions: 0xd7ab2634121e7afCE48b2A8Ea5db908869158D3E
- Subscriptions: 0x94B8f2A9a36Be215F2D4211DFee523f204f0a897
- Refer https://github.com/maticnetwork/reddit-bakeoff-poc/blob/develop/README.md#workflows for the end-to-end flow of the PoC
- User requests a claim from Owner account, and submits the claim to the distributions contract which then (internally) calls Subreddit Points contract to
mint
tokens. - User can
transfer
SubredditPoints tokens to another user - User submits
subscribe
transaction to place a subscription intent, therebyburning
some amount of their tokens.
- User requests a claim from Owner account, and submits the claim to the distributions contract which then (internally) calls Subreddit Points contract to
- Wiki for more information on the PoC and relevant Matic links can be found here: https://github.com/maticnetwork/reddit-bakeoff-poc/wiki [WIP]
- Single user scripts can be found here – https://github.com/maticnetwork/reddit-bakeoff-poc/tree/develop/scripts
- Single user scripts with meta-transaction support (gas to be paid on behalf of the user) can be found here:
- Bulk transaction scripts can be found here: https://github.com/maticnetwork/reddit-bakeoff-poc/tree/reddit_benchmark
- The bulk transaction run of
3 million transactions
can be found here- 1,000,000 point claims (minting & distributing points)
- 1,000,000 subscriptions and 1,000,000 burns
- 1,000,000 transfers
- Bulk transaction logs can be found here: https://drive.google.com/…/1r1X0RNTIpE0w4MY599t9TO8PHvdQXqqz
- A previous run of the bulk transactions having 300k transactions can be found here – https://www.notion.so/maticnetwork/Reddit-PoC-bulk-transaction-script-results-5aac772b3c0b424b93c7700ad53dc30c
- The bulk transaction run of
- Total cost of the PoC (1 mn transactions each – total 3 mn txs) – ~3.52 US$ at current price
- Claim and mint points: ~71 Matic tokens (~1.4 US$)
- Subscribe and burn points: ~52 Matic tokens (~1.02 US$)
- Transfer points: ~56 Matic tokens (~1.1 US$)
- We did over 3,000,000 (3 million) transactions in our scaling PoC bulk run over a period of ~12 hours (yes that’s 3 mn transactions):
- A live mainnet (we just launched in May 2020 after 2+ years of development!)
- Very cheap transactions
- ~4000 TPS, but we have gotten around 17,000 TPS while benchmarking
- Block time is ~2 seconds
- Code, which is already open source – audited by 3 different audit firms
- Documentation, including architecture
- EVM compatible interface – web3js and other web3 library support
- Standard Solidity support to enable existing smart contracts to be deployed without major rework
- EVM compatibility results in support for all Ethereum developer and user tooling
- Account-based Plasma MoreVP implementation, with Plasma predicates support to enable more expressive, custom fraud proofs, if required
- Reddit smart contracts can be modified and appropriate fraud proofs via predicates can be written to ensure changes can be done later
- Decentralization: Validators operating the Plasma chain need to stake Matic tokens on our staking smart contracts deployed on Ethereum. They can be slashed in case they resort to adversarial behavior.
- GSN and Biconomy support for meta-transactions (Reddit can pay gas fees on behalf of their users)
- Fast exits/withdrawals from Ethereum to Matic via our tokenized NFT/ERC721 exit mechanism
- Fully functional Blockchain explorer
- Tokens can be withdrawn to Ethereum in case the Matic sidechain goes down by way of our Plasma MoreVP mechanism
- Plasma contracts have been audited by a leading audit firm
- Inexpensive minting on Matic directly
- Early on, we got requests from a lot of ERC721-based collectibles related games on the need to support minting on Matic directly. We already have support for minting of ERC721s on Matic via our MintableERC721 predicate – https://github.com/maticnetwork/…/MintableERC721Predicate.sol.
- We have created a similar predicate for
MintableERC20
– https://github.com/maticnetwork/reddit-bakeoff-poc/blob/develop/contracts/root/predicate/MintableERC20Predicate.sol. This means that Reddit will be able to mint tokens directly on Matic first, and all subsequent actions occur on the Matic sidechain, includingmint
,transfer
,subscribe
andburn
. - As and when users do want to exit to Ethereum, they can do so via the
MintableERC20
predicate. Once they exit to Ethereum, the exited token amount isburned
on the Matic sidechain and correspondinglyminted
on the mapped Ethereum Subreddit ERC20 token contract. The only requirement here is that the Ethereum and Matic ERC20 token contracts be mapped in advance once in the Matic Plasma contracts on Ethereum. - We are also releasing an ERC20 exchange contract and a NFT marketplace contract to enable trade of ERC20 and ERC721 tokens. This will allow trading of tokens to happen directly on Matic. Other third-party decentralized exchanges and marketplaces are also expected to come up on Matic shortly.
- We are also onboarding
fiat-to-crypto
off-ramps on Matic this next month for users to buy crypto directly on Matic. Exchange support will be added soon for deposits and withdrawals of Matic and other ERC20 tokens directly to Matic mainnet. - All this will ensure easy trading/exchange/transfer of ERC20 tokens such as MOON/BRICKS and others from Matic itself in the future.
Tradeoffs:
- Block time on the Matic sidechain is ~2 seconds. This provides partial finality. Validators of the chain submit a state snapshot/checkpoint of the sidechain state to Ethereum every ~30 minutes. This helps in proving transaction inclusion of any transaction on the Matic sidechain on Ethereum after a period of ~30 minutes, assuming data is available.
- Data availability is based on 2/3+1 BFT majority on the Matic Heimdall chain by validators who stake Matic tokens on the staking smart contracts on Ethereum, and are incentivized to do so. Matic can be thought of a Proof-of-Stake based multi-operator Plasma which mitigates the possible requirement of a mass exit to a great extent.
- Do note that a
mass exit
is not possible as long as >2/3 of Matic validators are honest – there is a crypto-economic cost associated to violating this condition in terms of the MATIC token stake locked in Matic staking contracts that can be slashed for misbehavior. We think this is an acceptable tradeoff for Reddit. - Reddit will need to run a watcher node to watch transactions on the Matic sidechain on behalf of their users. We believe this is an acceptable tradeoff to have. Any one else can also run the watcher node on behalf of Reddit users including the Matic foundation, if required.
- The withdrawal period for our Plasma MoreVP is 7 days currently. There is an issue of
mass exits
with the Plasma framework, but we believe increasing the withdrawal delay by way of configuration mitigates the issue to a large extent. This essentially means tokens can be withdrawn securely to Ethereum, although in the worst case, that would entail a longer time delay.
Future:
- Multiple sidechains are planned to be implemented in the future to increase throughput. It can be the case that multiple future subreddit contracts could be deployed in different chains (partitioning deployment by subreddits) to ensure growth in Reddit transaction volume.
- Research is in active progress to verify state transitions on sidechain with zero knowledge cryptographic approaches instead of current challenge mechanism.
We are happy to say we meet all of the Reddit challenge requirements. Here is a checklist that we have made for the challenge requirements – https://www.notion.so/maticnetwork/Reddit-bakeoff-checklist-b7a5252171ba48d49c5cc816ffd4a0c7.
Requirements from Reddit:
Scaling. This PoC should scale to the numbers below with minimal costs (both on & off-chain). There should also be a clear path to supporting hundreds of millions of users.
- Over a 12 hour period, our scaling PoC was able to handle: 3,000,000 (3mn transactions):
- 1,000,000 point claims (minting & distributing points)
- 1,000,000 subscriptions and 1,000,000 burns
- 1,000,000 transfers
This was on one sidechain. In the future, there will be multiple sidechains added.
Decentralization. Solutions should not depend on any single third-party provider. We prefer solutions that do not depend on specific entities such as Reddit or another provider, and solutions with no single point of control or failure in off-chain components, but recognize there are numerous trade-offs to consider
Data availability on the Matic sidechains are based on 2/3+1 BFT majority on the Matic Heimdall chain by validators who stake Matic tokens on the staking smart contracts on Ethereum, and are incentivized to do so. The Plasma framework with predicates is used to guarantee the security of assets and specific smart contracts using Plasma predicates – this allows trustless exit from Matic sidechains in the worst case scenario if the Matic sidechain goes down.
Usability. Scaling solutions should have a simple end user experience.
Most wallets such as Portis, Torus, Fortmatic, Metamask and others already have support for the Matic mainnet sidechain
Users shouldn’t have to maintain any extra state/proofs, regularly monitor activity, keep track of extra keys, or sign anything other than their normal transactions.
Reddit will need to run a watcher node to watch transactions on the Matic sidechain on behalf of their users. We believe this is an acceptable tradeoff to have. Any one else can also run the watcher node on behalf of Reddit users including the Matic foundation, if required.
Running a watcher node will have the following requirements as that of a sentry node – https://docs.matic.today/docs/validate/technical-requirements/.
Transactions complete in a reasonable amount of time (seconds or minutes, not hours or days)
Block time on the Matic sidechain is ~2 seconds.
Free to use for end users (no gas fees, or fixed/minimal fees that Reddit can pay on their behalf)
Very cheap transactions. The Reddit PoC consisting of 3,000,000 transactions (1mn minting, 1mn transfers, 1m subscriptions and burns) cost around ~US$ 3.5 to run. Reddit can easily pay this by using meta-transactions on behalf of users.
Bonus points: Users should be able to view their balances & transactions via a blockchain explorer-style interface
Matic has a beautiful block explorer – https://explorer.matic.network/ – and third-party explorer support is increasing as time progresses.
Exiting is fast & simple
Exiting is fast and immediate using a fast-exit liquidity mechanism in lieu of fees. Users interested in exiting to Ethereum instantly can exit via a fast-exit liquidity contract mechanism, that Reddit or other interested parties can run. You can refer https://github.com/maticnetwork/reddit-poc/blob/master/docs/withdraw.md for more details.
Here is an example of this fast-exit contract – https://github.com/maticnetwork/fast-exits.
Interoperability. Compatibility with third party apps (wallets/contracts/etc) is necessary.
Scaling solutions should be extensible and allow third parties to build on top of it
- Account-based Plasma MoreVP implementation, with Plasma predicates support is present to enable more expressive, custom fraud proofs, if required
- Reddit smart contracts can be modified in the future and appropriate fraud proofs via predicates can be written to ensure changes can be done later
APIs should be well documented and stable
Documentation should be clear and complete
Third-party permissionless integrations should be possible & straightforward
Simple is better. Learning an uncommon or proprietary language should not be necessary. Advanced knowledge of mathematics, cryptography, or L2 scaling should not be required. Compatibility with common utilities & toolchains is expected.
- EVM compatible interface – web3js and other web3 library support is present
- Standard Solidity support to enable existing smart contracts to be deployed without major rework
- EVM compatibility results in support for all Ethereum developer and user tooling
Security. Users have full ownership & control of their points.
Balances and transactions cannot be forged, manipulated, or blocked by Reddit or anyone else
Users should own their points and be able to get on-chain ERC20 tokens without permission from anyone else
Points should be recoverable to on-chain ERC20 tokens even if all third-parties involved go offline
- Tokens can be withdrawn to Ethereum in case the Matic sidechain goes down by way of our Plasma MoreVP mechanism
- The withdrawal period for our Plasma MoreVP is 7 days currently. There is an issue of
mass exits
with the Plasma framework, but we believe increasing the withdrawal delay by way of configuration mitigates the issue to a large extent. This essentially means tokens can be withdrawn securely to Ethereum, although in the worst case, that would entail a longer time delay. - Do note that a
mass exit
is possible only in the case when >1/3 of Matic validators behave maliciously – there is a crypto-economic cost associated to that in terms of the stake locked in Matic staking contracts. At the time of writing, >$14.5 mn worth of Matic tokens have been staked and this number is expected to only increase going forward. We think this is an acceptable tradeoff for Reddit.
A public, third-party review attesting to the soundness of the design should be available
Bonus points: Public, third-party implementation review available or in progress
- Plasma contracts – audited by 1 third-party auditor
- Staking contracts – audited by 2 third-party auditors
- Heimdall and Bor – audited by 1 third-party auditor
All audit reports are available on request.
Fully open-source solutions are strongly preferred
All code is open source – https://github.com/maticnetwork
Important repos:
- https://github.com/maticnetwork/contracts
- https://github.com/maticnetwork/heimdall
- https://github.com/maticnetwork/bor
- https://github.com/maticnetwork/matic.js
- https://github.com/maticnetwork/dagger.js
We are excited to see what’s in store! Boo yah 🙂