Note: One of the biggest crypto winners in the 2024 US election is the prediction market Polymarket. Polymarket successfully predicted that Trump would win the US election comprehensively, with a trading volume of more than $3 billion. On November 14, 2024, eight days after the election, the FBI raided the New York residence of Polymarket CEO Coplan and demanded the surrender of electronic devices. Anonymous sources said that the FBI may suspect that the platform is manipulating the election market. Whether anyone can manipulate Polymarket involves the mechanism of how Polymarket actually works. Solidity developer Pavel Naydanov published an article on Hackernoon, "Polymarket Explained" to explain in detail the working mechanism of Polymarket. Golden Finance xiaozou compiled this article as follows:
Polymarket is one of the largest and most popular blockchain prediction markets. It supports users to bet on the results of various events, including sports, politics, culture, and more.
User assets are stored in non-custodial wallets. The protocol does not store users' private keys and cannot access user assets.
1. Internal wallet
When users use Polymarket for the first time, they need to create an internal wallet. There are usually two options:
● Use their existing EOA (external account) such as Metamask, Coinbase, or WalletConnect.
● Use an email address through a technology called Magic Link. Enter an email and receive a specific link to access the service.
This internal wallet is created through a dedicated smart contract factory with 1/1 multi-signature capabilities, which means that the wallet is completely controlled by the user.
Using an internal wallet allows Polymarket to provide a better user experience, such as enabling multiple transactions at once.
2. Prediction market
The prediction market starts with predictions. Predictions are the basis for building user scenarios. In prediction markets, such statements are called conditions. It can be a question, statement, description of an expected outcome, event, prediction, etc. We can think of it as any form of assertion about a future fact.
Examples of predictions are:
A 7.0 magnitude earthquake will occur in September.
Will GPT-5 be released in 2024?
Will Bieber's baby be a boy or a girl?
What is the highest grossing movie in 2024?
Will the price of ETH reach $10,000 in 2024?
Each prediction has a validation deadline: whether the prediction comes true or not. Polymarket has a special oracle that is responsible for determining the outcome of each prediction
What is the role of an oracle? Polymarket is built on blockchain technology and uses oracles to transmit data to the network. The oracle is designed to make its results trustworthy for any prediction.
Usually, a prediction has multiple possible outcomes. The oracle will decide the prediction outcome among these outcomes.
The resulting prediction examples are as follows:
Will GPT-5 be released in 2024?
Yes
No
What is the highest-grossing movie in 2024?
Inside Out 2
Others
Deadpool 3
Joker 2
Despicable Me 4
Dune 2
Mad Max: Fury
A typical prediction market structure is as follows:
The first step is to create a market and add a new prediction (condition) with a certain period. During this period, users can choose the outcome they think is most likely. In the final step, the oracle determines which group of users is correct and which group is wrong.
Users who choose the correct outcome will receive rewards, which are derived from the contributions of all participants. Each user contributes a certain amount of assets to the prediction market by voting for a specific outcome. So, users who choose the wrong one will get nothing.
This may lead one to conclude that prediction markets are essentially gambling. Yes and no. The main idea behind prediction markets was proposed by Vitalik in his blog. He believes that these services can serve as a neutral source for predicting or analyzing the probability of various events. People can make informed management decisions based on this data.
3. How accurate are the predictions?
In general, the view that prediction markets can be quite accurate is supported by the Efficient Market Hypothesis. According to this hypothesis, the price of any asset directly corresponds to its true value because all available information is already included in the price.
Take a simple example:
Suppose an investor knows the market value of a commodity. As long as it is profitable, they will continue to buy. Gradually, demand will increase and the price of the good will increase with it, until the price of the good reaches a level that makes it no longer profitable to buy.
Studies have shown that, on average, prediction markets are much more accurate than social surveys and expert opinions. The accuracy of prediction markets has been studied by numerous researchers in a variety of fields, including testing theories and laboratory data, healthcare, and management decisions.
Participants in prediction markets analyze a wide variety of information: news, sports, innovations, events, development trends, environmental issues, politics, and more. Their financial incentives ensure that their impact on market prices (or probabilities) is precisely adjusted to reflect the truth of the prediction.
Therefore, prediction markets are considered one of the best sources of real-time event probabilities. Polymarket is such a service that has attracted increasing attention recently.
How does Polymarket work? Let's take a quick look.
To understand how the Polymarket service works, first we click on a random event on Polymarket to browse its interface.
In the image above, the event title "Will Bitcoin exceed $60,000 on August 30?" is highlighted along with the possible outcomes. In this example, there are only two outcomes: "Yes" and "No". However, it is important to remember that there may be more than two outcomes. Let's take a look at the screenshot below to understand the interface in more detail.
Multiple results will be displayed directly below the event title. The right panel shows the most popular results, which are currently selected by most users. This allows quick access to this result option.
What does the "Buy" button mean?
Under the hood, each result is represented by a specific share of tokens based on the ERC-1155 standard. The Buy button is used to buy tokens for the selected result, and users need to pay the underlying asset USDC.
The buying process can be seen as a form of voting. Users vote for one of the results by using real assets to support their choices, which ensures the accountability of the decision. The corresponding sell process allows users to hold the opposite position.
Each vote represents a user's stance on a particular event. A variety of words can be used to describe the purchase process: "vote", "bet", "stand", "buy", etc. Users can choose the words they feel most comfortable with, but all of them indicate the user's opinion on an event.
The price of the "Yes" outcome is 98.8 cents, which indicates that the probability of the event "Bitcoin exceeds $5.5 on September 13" will occur is 98%. Therefore, the price of 2.3 cents indicates that there is a 2% probability that Bitcoin will be below $55,000.
Essentially, the price reflects the probability of a certain outcome. The user's statement is that the higher the price, the more likely the event will occur. If a user believes that Bitcoin has a good chance of exceeding $55,000, they can buy a “Yes” token for 98.8 cents.
If the user is correct and Bitcoin does exceed $55,000, then each “Yes” token purchased will be worth $1. Therefore, the user will make a profit of 1.2 cents per token. At the same time, all users holding “No” tokens will face a loss of investment as these tokens will become worthless.
It is worth noting that users do not need to hold their positions to the end; they can sell their shares at any time at the current market price.
4. Technical Details
Now let’s take a deep dive into the technical aspects of the protocol. Are you ready?
(1) Tokenized Results
We have made it clear that all event results on Polymarket are tokenized. Let’s review what we already know:
● This token can be called a share token.
● Share tokens are purchased with the underlying asset, so they are fully collateralized.
● Share tokens can be sold back to the underlying asset.
Now let’s look at some new information. Share tokens are based on the Gnosis Conditional Token Framework (CTF) implementing ERC-1155, which has proven its effectiveness and has been tested on multiple protocols.
CTF can support up to 256 outcomes per event.
Each prediction is identified in the CTF. For this purpose, it is assigned a conditionalId. The conditionalId is unique because of the hash of the following three parameters:
● oracle: The address of the oracle that determines the outcome of the event. This ensures that only the specified oracle can solve the prediction.
● questionId: The prediction identifier, which is set by the creator of the prediction. This can be a simple counter where it increments by 1 for each new prediction, or a more complex scheme calculated using hashes of text and other data.
● outcomeSlotCount: The number of possible outcomes of the prediction.
The following diagram depicts how CTF (Conditional Token Framework) works.
Users provide underlying assets when placing bets and receive share tokens, which are called conditional tokens in CTF. After the oracle completes the prediction, users can receive rewards from CTF based on the prediction results.
When a user receives a conditional token, they are considered to have taken a specific position. In CTF, a position represents a set of possible outcome combinations for each prediction. CTF generates these positions for each prediction, and each position corresponds to a user-selectable outcome combination.
For example:
What is the highest-grossing movie in 2024?
● Inside Out 2
● Others
● Deadpool 3
● Joker 2
● Despicable Me 4
● Dune 2
● Mad Max: Fury
Users can vote that Inside Out 2 will be the highest-grossing movie, while Dune 2 will definitely not be the highest-grossing movie in 2024. This combination of predictions will be considered as their position.
CTF provides two interesting position handling mechanisms: split and merge. The split mechanism allows a single position to be split into multiple independent results, while the merge mechanism merges different results into a single position. These mechanisms add flexibility to users' position management.
In my opinion, CTF provides four important advantages for Polymarket:
● Share tokens are used to confirm users' votes for specific prediction results.
● It implements a flexible system that allows users' votes to be combined into various positions.
● Based on the oracle's signal, the result calculation responsibility is delegated to the CTF.
● Rewards are calculated based on the amount of share tokens of the winning result.
It is particularly important to note that CTF can organize related events and combine users' positions. However, I did not find such an example in Polymarket.
I really like the CTF concept, although it is complex for me and I cannot fully understand it.
(2) Order
Now, let's look at the most mysterious aspect of Polymarket - order.
For purchases, the Polymarket interface offers three types of orders:
● Market order – buy immediately at the current market price.
● Limit order – deferred order allows the user to specify a price, once reached, the purchase will be initiated.
● AMM order – buy at an automatically determined price based on the amount of reserves in the pool, similar to a decentralized exchange.
Currently, the AMM order feature does not seem to work well. I did not find an event that allows purchases through AMM. After searching the protocol’s Discord, I found a recent comment posted by a user that gave me some insight into the situation. See the screenshot below.
According to the protocol’s documentation, AMM uses smart contracts developed as a component of the Conditional Token Framework. Therefore, AMM is used to determine the purchase price of share tokens.
This basic mechanism has liquidity requirements to ensure price stability and reduce volatility. Liquidity providers need an economic incentive to get rewards from each purchase to keep the system running.
Sadly, I am new to Polymarket, but I guess that initially, the protocol should have been based entirely on the CTF framework, with AMM used for price determination. Over time, the protocol developed a hybrid solution with an order book, and the other two types of orders (limit orders and market orders) began to work on a customized solution. This solution is called CLOB (Central Limit Order Book) or BLOB (Binary Limit Order Book).
(3) CLOB and BLOB
CLOB (Central Current Price Order Book) or BLOB (Binary Limit Order Book) is a hybrid decentralized order book system. In this system, there is a dedicated operator who handles order matching and initiates the execution of smart contracts.
Without going into too many details, the system can be described as follows:
Users create execution orders, which can be limit orders or market orders. The operator matches user orders and initiates the execution of smart contracts. Creating an order means creating a data structure signed with the user's private key according to the EIP-712 standard. Since orders are stored off-chain before execution, order terms can be adjusted quickly and costlessly, or even canceled outright.
For those who want to know more details, everything related to the order book and order matching is only accessible through the API. For convenience, Polymarket provides two clients: one for JavaScript and one for Python.
The Exchange.sol smart contract is the open source contract responsible for creating user positions within the CTF framework. It also supports the management of user positions and the transfer of holdings between assets, ensuring security and transparency within the protocol.
The smart contract has been audited. The audit report is attached to the repository.
(4) Smart Contracts
The Exchange smart contract actually has a more specific name - CTFExchange.sol. It is not very large, only about 100 lines of code, but it does have a large number of dependencies.
Most of them are small smart contracts with only a limited number of functions:
●BaseExchange.sol. Abstract smart contract that implements the ability to receive ERC-1155 tokens and is also responsible for preventing reentrancy attacks.
●Auth.sol. Role manager. Define validation functions and modifiers for CTFExchange.sol to set roles: admin and operator.
● Assets.sol. Defines two assets: the base asset (collateral) and the CTF address.
● Fees.sol. Defines protocol fees.
● Pausable.sol. Defines the ability to abort smart contract operations. A form of centralization agreed upon by the protocol in unforeseen circumstances. Available only to the admin role.
● AssetOperation.sol. Defines operations for base assets and CTFs. Includes transfers, splits, and merges of positions.
● Signature.sol. Defines code for verifying user signatures used for order processing.
● Hashing.sol. Defines hash calculations of order parameters for signature verification.
● Registry.sol. Defines the process of registering predictions in the system and registering tokens for predictions.
Note that everything related to the actual order execution is deployed in the smart contract - Trading.sol.
It is also simple to explore the smart contract by browsing the code. The structure clearly defines the entry points through functions:
● fillOrder() - executes an order between the user who created it and the maker selected by the user (another order).
● fillOrders() - the same as fillOrder(), but for a list of orders.
● matchOrders() - the operator selects two different orders and executes them.
All the above functions can only be called by the operator.
No matter how the call enters the smart contract, the result is the same: the two users will exchange tokens according to their orders.
(5) Protocol Fees
Fees are charged on the output assets. For binary predictions, the fees are symmetric, which means: if a user sells a token at $0.99, they will pay the same fee as a buyer who buys the token at $0.01.
The calculation formula is very simple (extracted from the document):
(6) Liquidity Reward Program
The overall goal of the program is to incentivize market liquidity.
We know that for an order book-based exchange to work, someone needs to create limit orders. Limit orders provide liquidity, allowing market orders to be executed immediately. Users who create limit orders are called market makers. The closer the limit order is to the market price, the faster the market order can be executed and the larger the trading volume, which is of course beneficial to end users. In addition, the more liquidity there is, the more difficult it is to manipulate the market.
To ensure sufficient liquidity, Polymarket has developed a special reward program to incentivize users to create limit orders.
The closer the limit order is to the market average price, the higher the reward. The reward will be automatically paid at midnight (UTC time) every day.
(7) Oracle
The oracle is used to deliver the predicted results - regardless of whether the event occurs or not. The oracle is one of the most critical components of the protocol, but it is deployed by a third party rather than the Polymarket team. The oracle is called UMA.
UMA is a decentralized oracle that specializes in recording all types of data on the blockchain except for unverifiable data. The oracle is considered to be in optimistic mode, and the data is considered correct if there is no dispute. UMA has its own arbitration system for resolving disputes, and the arbitrators are participants in the UMA ecosystem, especially holders of UMA tokens. This system is called DVM (Data Verification Mechanism).
The following multi-step process is used to determine the prediction results and record them on the blockchain:
● Statement. The prediction is added to the oracle along with the reward. Anyone who successfully challenges the prediction result can get the reward.
● Challenge period. During this period, anyone can challenge the prediction result. If no challenge occurs and the time expires, the prediction result is considered to be finalized, indicating its accuracy.
● Dispute. Any protocol participant can dispute the result, either for the reward or for fairness (just kidding). In practice, this rarely happens because game theory shows that most participants behave honestly.
● Voting. If a dispute is raised, UMA token holders vote to resolve the dispute. UMA is the protocol token used for voting, and participants are rewarded for participating.
● Settlement. The final step is the settlement process, which is the actual recording of the data on the blockchain. After this, the predictions can be considered reliable and accurate.
The entire protocol is based on sophisticated game theory, and it is economically disadvantageous for any participant to engage in malicious behavior.
Here are some examples:
● Participants who submit predictions for voting provide collateral to the smart contract. If their results are disputed, they lose their collateral; otherwise, they get their collateral back and receive a reward. This creates a strong incentive to only submit accurate results.
● Participants who disagree with the predictions also provide collateral. If they are correct, they get their collateral back and receive a reward; otherwise, they lose their collateral. This incentivizes participants to only challenge results that they are sure are wrong.
● Participants who resolve disputes. They must stake UMA tokens and are rewarded for resolving disputes. If they vote incorrectly or not at all, they lose part of their stake; otherwise, they are rewarded. So, malfeasance is impossible.
It is particularly noteworthy that the dispute voting process is divided into two stages using the commit/reveal scheme:
● Commit. Participants vote in secret by submitting the hash of their vote to the smart contract. This means that no one can tell the voting choice of the participant by looking at the hash.
● Reveal. After the voting phase is over, participants reveal their vote. The smart contract verifies that the vote matches the previously submitted hash.
This two-stage voting process prevents collusion between voters to discredit the oracle or attack services that rely on the predicted results.
The predicted results can be challenged multiple times. In this case, UMA allows the decision-making process to be reopened after the previous dispute is over.
The dispute initiation process is as follows:
5. Conclusion
The seemingly simple staking and prediction system actually consists of three main modules, each developed by a different protocol and team:
●CTF (Conditional Token Framework): manages the combination, position, and user share in the prediction. Thanks to Gnosis for creating such a flexible framework, this framework is very suitable for prediction markets.
●CLOB (Central Limit Order Book): Polymarket's own solution for deploying order books and limit orders. CLOB enables users to participate in the ecosystem efficiently and helps to aggregate liquidity.
● UMA: This is a decentralized oracle with a unique dispute resolution arbitration system. UMA is the real core component of this system, transmitting prediction results through the blockchain.
This system can be seen as a betting system, but when I started to dig deeper into Polymarket, I didn't expect that I would have to split my research into three different protocols, nor did I expect to spend so much time on it. Technically, the protocol is impressive and very interesting, and it successfully combines technology from different projects, making it particularly attractive to developers.
My final point is: I really want to see this protocol be useful, as Vitalik Buterin said. May it become a prediction, decision-making, and analysis tool. However, despite such potential, the protocol is still most commonly used for election predictions, and the demand for related predictions has soared.