In Uniswap V2, trades are executed without a central pricing function. Instead, the system checks whether the price of the trade is correct after the trade has been executed by checking the "invariant". The invariant is the relationship between the input and output amounts of a trade, and it ensures that the price of the trade is fair and reasonable.
For example, if the input amount is 1 ETH and the output amount is 100 tokens, the invariant would state that the price of the tokens should be 100 tokens/1 ETH. If the actual price of the tokens at the time of the trade is different from this, the trade would not be executed.
This approach allows for more flexibility and simplicity for users, as it allows for a more direct way to verify the price of a trade. It also separates concerns, in that the pricing function is not responsible for ensuring the safety of the trade, but just ensuring that the price is fair. Additionally, this approach also enables the system to more easily support other types of trades that may emerge in the future, such as trading at a specific price at the time of execution.
In summary, in Uniswap V2, the system ensures the fairness of price by checking the invariant after the trade is executed, instead of using a central pricing function. This allows for more flexibility, simplicity and safety for the users, and also enables the system to adapt to new trade types in future.