In-depth analysis of Reflexer stabilization mechanism: How to apply PID control theory to cryptocurrency?


 244 total views

By understanding the concept of PID controller and its parameterization in the RAI ecosystem, we can better understand how RAI responds to various attacks and exogenous impacts outside of system control.

Original title: ” New DeFi Gameplay丨Look at how Reflexer applies PID control theory to cryptocurrency
Written by: BlockScience
Translation: Yangz

From stablecoins linked to the US dollar to Fei, the recently popular algorithmic stablecoin, can there be new ways to play “stable” assets? Let’s take a look at how Reflexer applies PID control theory to cryptocurrency. Note: Reflexer is a platform that aims to build the first decentralized, non-linked stable asset RAI that only supports ETH. RAI can be used as a more “stable” collateral for other DeFi protocols (compared to ETH or BTC), or as a stable asset with embedded interest rates. It is worth noting that the official pointed out that RAI is not a stable currency, and the system behind it only cares about the market price as close to the redemption price as possible. PID control is one of the earliest control strategies developed. Because of its simple algorithm, good robustness and high reliability, it is widely used in industrial process control. So far, about 90% of control loops have PID structure. Simply put, the control deviation is formed according to the given value and the actual output value, and the deviation is formed by linear combination of proportional, integral and derivative to control the controlled object.

The following is the full text translation:

This work delves into the engineering design work carried out by the BlockScience team in cooperation with the Reflexer Lab, focusing on the parameterization of the RAI system before the launch of the main network on February 17, 2021. Covered concepts include PID controller, management surface, parameter selection under uncertainty, controller pressure test and safety system launch.


The web3 field has become the basis for rapid financial experiments in many directions. Many projects are seeking price stability for their tokens (as any useful currency should be), and often do so in different ways. From external currency pegs to repricing mechanisms, there have been many attempts at “stability”, but RAI is the first such token to use the existing control theory to move towards a reflective (or self-reflexive) stable price token system. Compared with the existing system linked to legal currency, RAI can “shock ETH” because the stable controller can reduce the price fluctuations caused by the underlying assets without the need for explicit linkage.

More specifically, by using proportional-integral-derivative (PID) controllers in system design, RAI can provide the Ethereum DeFi ecosystem with a low-volatility reserve asset that is not linked to any external assets. The depth of the existing engineering practice of deploying PID controllers in various equipment provides us with a solid engineering foundation, so we can consider the design of RAI from it.

Complex system

Optimizing the complex system infrastructure to balance the needs of multiple stakeholders is a feat of engineering design. It requires an understanding of system goals, constraints, and stakeholder needs, as well as a comprehensive analysis of the trade-offs involved. Modeling and simulation tools, such as cadCAD, can well help us manage complexity and balance optimization to ensure preferred results.

This requires us to deeply understand the system goals and the parameters involved in the mechanisms that need to be applied to achieve these goals. In this section, we will study the various goals of the RAI system and what parameters are involved, including controlled and uncontrolled.

The RAI analysis dashboard displays relevant system indicators to end users. These same indicators provide information for the design through the cadCAD model, and they have been measured even before the existence of the RAI system.

the goal

The goal of the RAI ecosystem is the primary consideration in the engineering design process. The system goal ensures the consistency of the cadCAD simulation parameters and indicators with the overall goal. The system objectives of the RAI project include:

  • Without assuming that the redemption price is linked, smooth the price changes in the secondary market.

  • The stability of the controller under a series of exogenous shocks.

  • If the secondary market violates liquidity requirements, redemption price adjustments (mechanisms) can be initiated and closed peacefully.

The next step in system design is to determine the parameters. These parameters can be divided into two categories: one is the parameters under system control (controlled parameters), and the other is the uncontrollable parameters (environmental parameters).

The controlled parameters specify the key characteristics that the system designer can choose to achieve the system goals. RAI project control parameters include:

  • Controller-specific parameters

  • Debt market specific parameters

  • Pricing oracle parameters

Environmental parameters stipulate the external characteristics of the system and also affect the realization of system goals. The environmental parameters of the RAI project include:

In addition, indicators to measure the achievement of these goals are also important. We can select control parameters based on the summary of KPIs that reflect system goals under given environmental parameters. The KPIs of the RAI project for each system goal include:

  • Responsiveness target: reasonable response time of arbitrage tools and controllers to impulses of different environmental parameters.

  • Volatility target: the statistical dispersion of price changes in the secondary market.

  • Stability goal: measure the relative frequency of stable and unstable paths in the simulation.

  • Liquidity target: the controllability of slippage in the secondary market.


The encryption economy system and the control system have a common phenomenon, that is, there is a set of parameters set by humans, which encode trade-off decisions in the system dynamics. In the encrypted economy system, we call the parameters subject to human supervision as the governance surface.

It is important to clarify the governance aspect, and where possible, it is important that the effect of adjusting this parameter is relatively straightforward. Usually, the concept of governance is used as a general concept, assuming that humans will have the expertise, procedures, and coordination to agree on future changes to these parameters.

In practice, the goal is to maintain a small governance area to reduce the frequency and complexity of governance actions. In addition, early model-based system engineering work can help determine initial parameters to develop rollout plans and/or minimize the scale of future changes.

Understand and select the controller type

RAI is an innovative encryption economy system that uses a variant of PID controller as a means to maintain market price stability. The PID controller is the most common type of controller. It uses proportional (P), integral (I) and derivative (D) to influence the future value of the time series.

A powerful feature of the PID controller is that it can continuously adapt even in the absence of prediction, because the increase in error tends to make it more adaptable. Specifically, P is an understanding of immediate measurement, I is an understanding of the past, and D is related to expected changes in the future.

For D, by extrapolating the expected changes, it is possible to reduce the noise-free (ideal) steady-state error rate, but the price is the sensitivity to sudden changes. Generally speaking, differentiation is sensitive to noise and fluctuation measurements that often appear in market prices. In an economic environment, D may become an attack vector.

In view of these considerations, (we) decided to focus the analysis on P and I, and set D to zero. The following will briefly introduce the types of analysis used to evaluate RAI parameter alternatives at startup.

Exploring P and PI variables and pre-tuning for RAI startup

So far, RAI has only used P (Kp) in response to dynamic simplicity; however, since the proportional controller is known to be affected by steady-state errors, it also needs to include an integral term. Although integral controllers can effectively deal with steady-state errors, they are easily affected by wind-up (saturation), that is, the accumulation of integral terms will lead to deviations in control actions. In order to deal with this situation, we must also consider an anti-wind-up (saturation) mechanism. Therefore, the integral leakage rate is included in our parameter selection space.

Malicious whale test

Without understanding the potential impact of large token holders (‘whales’), any experiment on price stability is incomplete. In the following scenario, we will assume that a malicious whale named Beluga bought most of the RAI supply and used it to force the market price of RAI to be kept at a constant level.

In the following example, we consider 5 available controller types of variables (positive Ki and negative Ki, leaky integrator and non-leakage integrator, and zero Ki), and verify that the parameters are reasonably selected In the long run, the whale may lose to the controller.

The first visualization is to see what happens to the redemption price if the Beluga keeps the market price unchanged. As can be seen from Figure 1 below, in all the tested solutions, except for the one where Ki is negative and there is no leakage, the redemption price will tend to zero within 2 weeks, which means this parameterized choice Not feasible.

In-depth analysis of Reflexer stabilization mechanism: How to apply PID control theory to cryptocurrency?

Compared with proportional control, the PI controller with positive Ki term accelerated the market crash induced by beluga whale. The PI controller with negative Ki can buffer the crash and restore the system. However, the leakage term is critical, because if the integral term is allowed to overwhelm the proportional term, it is equivalent to the controller surrendering to the attacker-this is something we cannot tolerate. Fortunately, there is an analytical boundary on the relationship between the leakage integral term and the proportional term, which ensures that this will not happen.

In the context of RAI economic dynamics, how did this happen? This happens because the controller automatically adjusts the redemption rate based on the market price.

When choosing a proportional controller (Kp only) or a PI controller with a leaked integral term (Kp & Ki), the steady-state dynamics can include a constant negative redemption rate, which is our goal in the RAI ecosystem. It is worth noting that if we exclude leakage, the integral term will have a counterproductive acceleration effect. When Ki is positive, the redemption rate will accelerate in the negative direction, and when Ki is negative, the redemption rate will accelerate in the positive direction. Neither of these two PI (no leakage) situations are particularly ideal.

In-depth analysis of Reflexer stabilization mechanism: How to apply PID control theory to cryptocurrency?

In the absence of leaked items, adding the points item may make the RAI system unsustainable, because it is obvious that it allows economic exploitation of users, or the tokens become increasingly unusable due to increasingly negative interest rates. Considering that the whale attack is a real problem, this analysis shows that the P controller is feasible and the PI controller is feasible only when the anti-windup (saturation) leakage mechanism is included.

Steady state error test

Another focus of RAI is steady-state error; specifically, it is possible for the system to achieve a certain degree of price stability without narrowing the expected gap between the redemption price and the market price. In fact, the only reason for introducing an integral term in the control design space is to help eliminate steady-state errors. Steady-state error problems often arise in the presence of noise or shock.

In Figure 3 below, the market evolves according to the martingale process. We have observed that the Ki item tends to bias the redemption rate (see the figure below). This deviation may be small, but over time, it will cause a huge difference in the redemption price.

In-depth analysis of Reflexer stabilization mechanism: How to apply PID control theory to cryptocurrency?Figure 3. Even if the parameters are selected properly, the hourly exchange rate changes very little (<5e-9), but over time, it will still cause a large cumulative error

In Figure 4, we can see the cumulative error over time. The positive Ki without leakage tends to increase the absolute error (larger negative error), while the negative Ki without leakage tends to reduce the absolute error (smaller negative error), both of which are measured relative to the P controller . The PI controller with negative Ki and no leakage achieves the smallest absolute error, but due to the malicious whale attack discussed above, we have ruled out this design.

In-depth analysis of Reflexer stabilization mechanism: How to apply PID control theory to cryptocurrency?

In our example, compared to the controller with only P, the benefit of adding the leakage integral term is small, so further adjustments are needed to make a meaningful distinction between the two options on the basis of steady-state error. For the time being, this means that the added complexity of adding item I cannot be proven by the benefits of system stability in the short term, and more research is needed in this direction before implementation.

Another important observation is the out-of-control trend of redemption prices. Proportional controllers and PI controllers with anti-windup (saturation) can achieve control, while PI controllers without anti-windup (saturation) will lose control. A negative Ki term will cause the redemption price to diverge (deviation to infinity), while a positive Ki term will cause the redemption price to converge to zero.

In-depth analysis of Reflexer stabilization mechanism: How to apply PID control theory to cryptocurrency?Figure 5. A non-leaking PI controller will drift in the redemption price, even if the cumulative price error is still bounded

Parameter selection of multi-dimensional system under uncertainty

While iterating the control parameters, scientific analysis of the large amount of data and complexity of the RAI system and interactions must be carried out, which requires the use of new scientific methods.

The simple model above only considers the control logic of P(I), and the model used for analysis below includes the mortgage debt position of the back RAI and the liquidity pool service as the RAI secondary market (and price sensor)

To this end, BlockScience has developed a “parameter selection under uncertainty” method to achieve data-driven informed decision-making. This article on “Performing parameter selection under uncertainty” briefly describes it and the related steps and challenges.

RAI parameter selection

In the following section, we will provide some non-exhaustive examples to illustrate some computational experiments run on a wider range of RAI system models, including SAFEs systems and liquidity pools (ETH/RAI Uniswap examples).

Scene test

Our workflow defines some test scenarios to link system goals with measurable KPIs, and ultimately with selected control parameters. The scenarios performed include:

  1. “Rationality check” to ensure that the plant performance of the system meets expectations; this will take into account the shutdown of the controller, and the only source of uncertainty is the change in the price of ETH.
  2. Impact testing, that is, introducing preset changes in the exogenous process, measuring the system’s response capabilities, and
  3. Trajectory sampling, that is, Monte Carlo runs on the realization of many random processes, and measures and evaluates the key performance indicators reflecting the system goals under various environmental conditions.

“Reasonability check” test

The baseline scenario to be tested is that the debt and secondary market systems operate on their own without a controller. This test is to ensure that the “Plant” model works properly before using it to evaluate the controller.

This rationality test replicates the controller that is’pegged to fiat currency’ by fixing the redemption price. In this case, the system should reach a state where the price change of ETH will be’transmitted’ to the market price, and the redemption price will be fixed at its initial condition (in this case, RAI is the Reflexer at the time of release. The set value, 3.14 USD/RAI). The results of the “reasonability check” are shown in Figure 6 below.

In-depth analysis of Reflexer stabilization mechanism: How to apply PID control theory to cryptocurrency?Figure 6: When the PID controller is closed, the generated ETH price signal is introduced into the model, and a corresponding change is generated in the market price of RAI

As shown in Figure 6, when the controller is closed, the change in the ETH price will produce a corresponding change in the market price of RAI, and there will be a slight upward drift (specific to the impact of the ETH price). The observed dynamics are similar to those in similar systems (such as a single collateral DAI).

Attack and failure modes of impact testing

As with any integrated system design, we need to understand the limitations of our system and under what circumstances it will fail. The shock test starts by realizing a one-time change in an external process, such as the price of ETH, and checking the resulting impact on system dynamics. Shock testing is particularly useful for selecting parameter ranges that can keep the system stable, that is, keeping prices and token balances from reaching infinity or zero.

The following is an example. For example, the price of ETH suddenly dropped by 30% after two weeks. We can see that in the case of Kp=2e-07 and 5e-09, the effect on the PI variable is out of control, while the values ​​given by the parameter recommendations remain stable and bounded.

In-depth analysis of Reflexer stabilization mechanism: How to apply PID control theory to cryptocurrency?Figure 7: Analysis of the impact of the redemption price and the market price under the ETH price ladder change after 2 weeks. Green is the feasible parameter range of the leaked PI controller, and red is an example of failure mode

Recommended parameter range

Based on the parameter selection under the uncertainty workflow, we determined that the P controller is the simplest and safest network startup configuration, and further observed that if we want to further reduce the steady-state error, we can add an integral, but only when leakage The term is included, and further satisfies the condition Kp> -Ki /(1-�), where α is the leakage integral parameter.

Figure 8 below is a simulation example using parameter values ​​taken from the recommended range, where the proportional term is positive and the integral term is negative, showing stability-the role of the controller is to weaken the changes in the exogenous random process, such as the price of ETH. In this case, the Kp term is more than 3 orders of magnitude stronger than the Ki term, and the integral term leaks 1/1000 of the value in each period. The resulting system behaves at steady state equivalent to a pure P controller (as shown in the figure below), but if steady state errors occur, they have additional capabilities to eliminate them.

In-depth analysis of Reflexer stabilization mechanism: How to apply PID control theory to cryptocurrency?Figure 8: Comparison of redemption price and ETH price, implementation using recommended parameters

In-depth analysis of Reflexer stabilization mechanism: How to apply PID control theory to cryptocurrency?Figure 9: Simulating the realization of RAI liquidity balance and RAI debt balance

Roll out gradually

When creating and deploying a new financial system, we need to conduct gradual testing and promotion to ensure the security of the system, and then open it to more users and more capital.

In October 2020, ProtoRAI (PRAI) conducted an incentive mainnet test, which was launched with a low debt ceiling to test system behavior and provide a reference for the launch of a larger-scale formal RAI system. The purpose here is to observe the small-scale low-stake situation before full deployment.

The RAI network was launched on February 17, 2021, and the initial configuration only has the Kp item of the proportional controller. The system exhibited expected behavior, consistent with our expected results in the case of a proportional controller.

In-depth analysis of Reflexer stabilization mechanism: How to apply PID control theory to cryptocurrency?As of April 2, 2021, the price of each RAI analysis dashboard

Continue to monitor real-time data and combine it with system models to reveal whether it is worth including the integrated control item Ki and its leakage “anti-saturation” mechanism. This will increase the complexity of the system, but can also ensure long-term sustainability, thereby promoting governance minimization during the life cycle of the RAI system.

Minimize governance

Trying to minimize governance by ignoring governance is like getting on a self-driving car but unable to instruct the car to navigate where it will take you.

In practice, governance minimization requires a clearly defined governance aspect first, and then a clear procedure about who, when, and how to change parameters. Successful governance minimization means making fewer, smaller, and clearer changes, and reducing business overhead.

It is rare that the parameters are completely uncoupled; more often, the appropriate values ​​are related to each other, like the Kp, Ki, and α (leakage integral parameters) we have seen. Models play an important role in monitoring the health of the system because they can help suppress governance actions taken for governance actions, which actually put the system at risk, while in turn helping to determine when actions are needed. Sufficient early warning to plan, test and execute effective interventions.

Next step

In view of the fact that we already have the full-featured model of RAI dynamics and the mainnet release, we will expand the scale of the existing model and combine it with real-time data to provide information for continuous monitoring. After that, we have to make a decision to learn from shocks and events to improve our understanding of the complex new dynamics around us.

in conclusion

In this article, we have summarized the engineering work of the parameter selection of the RAI stability controller, aiming to further educate and inform the Ethereum community about the importance of computer-aided design in complex systems.

By introducing the concept of the PID controller and its parameterization in the RAI ecosystem, as well as performing battery shock and sensitivity tests on the system to understand the response of the system, we have a better understanding of how RAI responds to various aspects other than system control Attacks and exogenous shocks.

Ultimately, the goal of the Reflexer team is to provide an asset with low volatility, minimal governance, and stable price for use in the Ethereum ecosystem. Despite the uncertainty, these characteristics can become reliable as long as there is a strict control theory basis.

Source link:

Let’s block ads! (Why?)

Disclaimer: does not endorse any content or product on this page. While we aim at providing you all important information that we could obtain, readers should do their own research before taking any actions related to the company and carry full responsibility for their decisions, nor can this article be considered as investment advice or recommendations. Every investment and trading move involves risk, you should conduct your own research when making a decision.