{"componentChunkName":"component---src-pages-sips-sip-markdown-remark-frontmatter-sip-tsx","path":"/sips/sip-260/","result":{"data":{"markdownRemark":{"fileAbsolutePath":"/vercel/path0/content/sips/sip-260.md","frontmatter":{"sip":260,"sccp":null,"title":"Rate Limiting","network":"Ethereum","author":"Daniel Beal (@dbeal-eth)","type":"Governance","proposal":"https://snapshot.org/#/snxgov.eth/proposal/0xd371c4eb71b4e61f425e8fb885b08ac631f6ee9c1000994f2a4513e78f967189","implementor":null,"release":null,"created":"2022-07-18T00:00:00.000Z","updated":null,"status":"Rejected"},"html":"<!--You can leave these HTML comments in your merged SIP and delete the visible duplicate text guides, they will not appear and may be helpful to refer to if you edit it again. This is the suggested template for new SIPs. Note that an SIP number will be assigned by an editor. When opening a pull request to submit your SIP, please use an abbreviated title in the filename, `sip-draft_title_abbrev.md`. The title should be 44 characters or less.-->\n<h2 id=\"simple-summary\" style=\"position:relative;\"><a href=\"#simple-summary\" aria-label=\"simple summary permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Simple Summary</h2>\n<!--\"If you can't explain it simply, you don't understand it well enough.\" Simply describe the outcome the proposed changes intends to achieve. This should be non-technical and accessible to a casual community member.-->\n<p>Reduce the impact of a possible security breach in the bridge by implementing simple rate limiting functionality on all transfers processed by the bridge.</p>\n<h2 id=\"abstract\" style=\"position:relative;\"><a href=\"#abstract\" aria-label=\"abstract permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Abstract</h2>\n<!--A short (~200 word) description of the proposed change, the abstract should clearly describe the proposed change. This is what *will* be done if the SIP is implemented, not *why* it should be done or *how* it will be done. If the SIP proposes deploying a new contract, write, \"we propose to deploy a new contract that will do x\".-->\n<p>Bridges are notorious for and large profile loss of funds. To prevent from being another sorrowful statistic on this regard, this SIP proposes implementation of\na system for limiting the amount of transfers a bridge can process. This will give the CC team a chance to react if an attacker emerges and attempts to\ndrain large amounts of value from the system.</p>\n<h2 id=\"motivation\" style=\"position:relative;\"><a href=\"#motivation\" aria-label=\"motivation permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Motivation</h2>\n<!--This is the problem statement. This is the *why* of the SIP. It should clearly explain *why* the current state of the protocol is inadequate.  It is critical that you explain *why* the change is needed, if the SIP proposes changing how something is calculated, you must address *why* the current calculation is innaccurate or wrong. This is not the place to describe how the SIP will address the issue!-->\n<p>In the case of a bridge exploit (within or outside of our control), an attacker could withdraw protocol-killing levels of funds from either the sUSD or SNX\nbridges.</p>\n<p>It was previously thought that rate limiters would be very difficult to implement reliably. However, due to optimism's bridge behavior of allowing replays\non failed messages, rate limiters become a lot more practical and simple to implement.</p>\n<h2 id=\"specification\" style=\"position:relative;\"><a href=\"#specification\" aria-label=\"specification permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Specification</h2>\n<!--The specification should describe the syntax and semantics of any new feature, there are five sections\n1. Overview\n2. Rationale\n3. Technical Specification\n4. Test Cases\n5. Configurable Values\n-->\n<h3 id=\"technical-specification\" style=\"position:relative;\"><a href=\"#technical-specification\" aria-label=\"technical specification permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Technical Specification</h3>\n<!--The technical specification should outline the public API of the changes proposed. That is, changes to any of the interfaces Synthetix currently exposes or the creations of new ones.-->\n<p><code>BaseSynthetixBridge</code> will be modified to have a new field:</p>\n<ul>\n<li><code>mapping(bytes32 => RateLimitInfo) private limits</code> -- tracks rate limiting info for a particular token/direction combination transferred by the bridge</li>\n</ul>\n<p>The struct <code>RateLimitInfo</code> has the following definition:</p>\n<pre><code>struct RateLimitInfo {\n  uint128 amountUsable;          // Amount of token allowed to be received or sent per period. Configurable via SCCP\n  uint128 periodLength;          // Time in seconds between the rate limit being reset. Configurable via SCCP\n\n  uint128 limitUsed;             // tracks amount of the limit used in the current period. automatically reset when the period changes.\n  uint128 lastPeriod;            // used to determine if the `rateLimitAmountReceived` should be reset. Tracks the period that the limit is applicable to\n  \n}\n</code></pre>\n<p>Additionally, some functions will be added:</p>\n<pre><code>interface IBaseSynthetixBridge {\n  function isExceedingRateLimit(bytes32 id, uint amount);\n  function getNextLimitResetTime(bytes32 id);\n}\n</code></pre>\n<p>Additionally, the <code>BaseSynthetixBridge</code> will have a new internal function <code>probeRateLimit(uint amount)</code> for modifying the limit while increasing <code>amountUsed</code>, for use by subclasses. This call\nreverts if the limit is exceeded.</p>\n<p><code>SynthetixBridgeToOptimism</code> <code>deposit</code> (and all its variants) and <code>finalizeWithdrawal</code> will be modified to call <code>probeRateLimit</code>.</p>\n<p><code>SynthetixBridgeToBase</code> <code>withdraw</code> (and all its variants) and <code>finalizeDeposit</code> wille be modified to call <code>probeRateLimit</code>.</p>\n<p><code>BaseSynthetixBridge</code> <code>initiateSynthTransfer</code> and <code>finalizeSynthTransfer</code> will be modified similarly to call <code>probeRateLimit</code>.</p>\n<h3 id=\"user-experience-impact\" style=\"position:relative;\"><a href=\"#user-experience-impact\" aria-label=\"user experience impact permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>User Experience Impact</h3>\n<p>To prevent users from potentially being locked out of their funds because the transaction sent from the source layer is larger than the limit on the destination,\nit is recommended that the layer 1 and layer 2 layers be set to the same value. The code will then enforce the limit at the source side, preventing unnecessary amounts of\ntokens remaining in transit between the two layers.</p>\n<p>We will need to create documentation to make clear to users the behavior of the rate limit, and the UIs (3rd party or not) for sending sUSD or SNX will need to be\nupdated to understand the behavior of the rate limit and explain to the user if an error occurs due to rate limit (on either the souce or the destination side).</p>\n<p>Of particular note, whatever the SC sets as the value for <code>amountUsablePerPeriod</code> is effectively the maximum size of a single transfer which can be sent. This is because,\nif a user sends an amount larger than this, it will never be receivable on the destination becuase the limit is lower than the absolute size of the transaction.</p>\n<p>If the pdao needs to unlock a very large transaction for whatever reason, it can safely do so by creating a sandwhich transaction to temporarily raise the limit, call the optimism\nforward txn, and lower the transaction back to normal.</p>\n<h3 id=\"alerts-on-high-usage-of-the-rate-limiter\" style=\"position:relative;\"><a href=\"#alerts-on-high-usage-of-the-rate-limiter\" aria-label=\"alerts on high usage of the rate limiter permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Alerts on high usage of the rate limiter</h3>\n<p>The purpose of the rate limiters is to reduce the impact of a potential bridge attack. However, this will be much less effictive if we don't actively track brideg\nactivity and make sure that the system is suspended if unusual activity is detected. If, for example the rate limit period is set to 6 hours, we want to make sure\naction can be taken to protect the system withint that window if unusual activity is detected. At the same time, we want to set the limits as high as possible to minimize\nchances of bad UX, so risk analysis should be taken to determine what the limit and period should be.</p>\n<h3 id=\"test-cases\" style=\"position:relative;\"><a href=\"#test-cases\" aria-label=\"test cases permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Test Cases</h3>\n<p><code>BaseSynthetixBridge</code></p>\n<ul>\n<li><code>isExceedingRateLimit</code>\n<ul>\n<li>verify correct behavior when 0 used and smaller than <code>amountUsable</code> specified</li>\n<li>verify correct behavior when max used and any amount of <code>amountUsable</code> specified</li>\n<li>verify correct behavior when some used and some amount of <code>amountUsable</code> is specified</li>\n</ul>\n</li>\n<li><code>initiateSynthTransfer</code>\n<ul>\n<li>verify the probe works</li>\n</ul>\n</li>\n<li>`finalizeSynthTransfer\n<ul>\n<li>verify the probe works</li>\n</ul>\n</li>\n<li><code>setRateLimitPeriod</code>\n<ul>\n<li>verify only owner</li>\n<li>verify it sets the value</li>\n</ul>\n</li>\n<li><code>setRateLimitAmountUsable</code>\n<ul>\n<li>verify only owner</li>\n<li>verify it sets the value</li>\n</ul>\n</li>\n</ul>\n<p><code>SynthetixBridgeToOptimism</code></p>\n<ul>\n<li><code>deposit</code>\n<ul>\n<li>verify the probe works</li>\n</ul>\n</li>\n<li><code>finalizeWithdrawal</code>\n<ul>\n<li>verify the probe works</li>\n</ul>\n</li>\n</ul>\n<p><code>SynthetixBridgeToBase</code></p>\n<ul>\n<li><code>withdraw</code>\n<ul>\n<li>verify the probe works</li>\n</ul>\n</li>\n<li><code>finalizeDeposit</code>\n<ul>\n<li>verify the probe works</li>\n</ul>\n</li>\n</ul>\n<h3 id=\"configurable-values-via-sccp\" style=\"position:relative;\"><a href=\"#configurable-values-via-sccp\" aria-label=\"configurable values via sccp permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Configurable Values (Via SCCP)</h3>\n<!--Please list all values configurable via SCCP under this implementation.-->\n<p>New SCCP parameters will be implemented to allow the SC to adjust risk of the bridge as necessary for the market conditions. It is advised that these\nvalues be kept the same on both layers since a mismatch in limits could lead to bad user experience.</p>\n<ul>\n<li><code>SynthetixBridgeToOptimism.setRateLimitPeriod(bytes32 currencyKey, uint value)</code> -- number of seconds between when the amount received gets reset</li>\n<li><code>SynthetixBridgeToOptimism.setRateLimitAmountUsable(bytes32 currencyKey, uint value)</code> -- amount of token which can be received or sent every period term</li>\n</ul>\n<p>Initially, the following limits will be automatically applied as part of deployment of this SIP:</p>\n<ul>\n<li><code>period(SNX)</code>: <code>21600</code> (6 hours)</li>\n<li><code>amountUsable(SNX)</code>: <code>250000000000000000000000</code> (250000 SNX)</li>\n<li><code>period(SNX)</code>: <code>86400</code> (6 hours)</li>\n<li><code>amountUsable(SNX)</code>: <code>1000000000000000000000000</code> (1000000 sUSD)</li>\n</ul>\n<h2 id=\"copyright\" style=\"position:relative;\"><a href=\"#copyright\" aria-label=\"copyright permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Copyright</h2>\n<p>Copyright and related rights waived via <a href=\"https://creativecommons.org/publicdomain/zero/1.0/\">CC0</a>.</p>"}},"pageContext":{"id":"47e5772a-6e79-5cff-89b1-a9dd315139fb","frontmatter__sip":260,"__params":{"frontmatter__sip":"260"}}},"staticQueryHashes":[]}