{"componentChunkName":"component---src-pages-sips-sip-markdown-remark-frontmatter-sip-tsx","path":"/sips/sip-46/","result":{"data":{"markdownRemark":{"fileAbsolutePath":"/vercel/path0/content/sips/sip-46.md","frontmatter":{"sip":46,"sccp":null,"title":"Address Resolver Gas Improvements","network":"Ethereum","author":"Justin J Moses (@justinjmoses)","type":"Governance","proposal":null,"implementor":null,"release":null,"created":"2020-03-02T00:00:00.000Z","updated":null,"status":"Implemented"},"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.\" Provide a simplified and layman-accessible explanation of the SIP.-->\n<p>Cache addresses from resolver inside contracts to reduce gas usage.</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 technical issue being addressed.-->\n<p>Ensure that each contract relying on addresses from the <code>AddressResolver</code> caches its own copy of these addresses, thereby reducing the gas usage for users when executing regular transactions like <code>issue</code>, <code>burn</code>, <code>claim</code> and <code>exchange</code>. The cache however must be refreshed on each and every deployment.</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<!--The motivation is critical for SIPs that want to change Synthetix. It should clearly explain why the existing protocol specification is inadequate to address the problem that the SIP solves. SIP submissions without sufficient motivation may be rejected outright.-->\n<p>In our Achernar release (v2.19.8), we introduced <a href=\"/46df4b4db8ea4c8c5e7e088cc3253b1d/sip-43.md\">SIP-43</a> - an address lookup contract into the <code>FeePool</code>, <code>Synthetix</code>, <code>Exchanger</code>, <code>Issuer</code> and all <code>Synth</code> contracts, among others. The impact to gas on common user functions like <code>FeePool.claim</code>, <code>Synthetix.exchange</code> and <code>Synthetix.issueSynths</code> was signficant.</p>\n<p>Prior to Achernar</p>\n<table>\n<thead>\n<tr>\n<th>Contract</th>\n<th>Function</th>\n<th>Gas Used</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td>FeePool</td>\n<td>claimFees</td>\n<td>322,641</td>\n</tr>\n<tr>\n<td>Synthetix</td>\n<td>burnSynths</td>\n<td>352,748</td>\n</tr>\n<tr>\n<td>Synthetix</td>\n<td>exchange</td>\n<td>226,041</td>\n</tr>\n<tr>\n<td>Synthetix</td>\n<td>issueMaxSynths</td>\n<td>342,547</td>\n</tr>\n<tr>\n<td>Synthetix</td>\n<td>issueSynths</td>\n<td>361,070</td>\n</tr>\n</tbody>\n</table>\n<blockquote>\n<p>from <a href=\"https://github.com/Synthetixio/synthetix/runs/353850454\">https://github.com/Synthetixio/synthetix/runs/353850454</a></p>\n</blockquote>\n<p>After Achernar</p>\n<table>\n<thead>\n<tr>\n<th>Contract</th>\n<th>Function</th>\n<th>Gas Used</th>\n<th>Diff</th>\n<th>%</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td>FeePool</td>\n<td>claimFees</td>\n<td>497,550</td>\n<td>+174,909</td>\n<td>+54%</td>\n</tr>\n<tr>\n<td>Synthetix</td>\n<td>burnSynths</td>\n<td>547,257</td>\n<td>+193,145</td>\n<td>+55%</td>\n</tr>\n<tr>\n<td>Synthetix</td>\n<td>exchange</td>\n<td>565,260</td>\n<td>+339,218</td>\n<td>+150%</td>\n</tr>\n<tr>\n<td>Synthetix</td>\n<td>issueMaxSynths</td>\n<td>503,953</td>\n<td>+161,406</td>\n<td>+47%</td>\n</tr>\n<tr>\n<td>Synthetix</td>\n<td>issueSynths</td>\n<td>531,401</td>\n<td>+168,223</td>\n<td>+46%</td>\n</tr>\n</tbody>\n</table>\n<blockquote>\n<p>from <a href=\"https://github.com/Synthetixio/synthetix/runs/457383033\">https://github.com/Synthetixio/synthetix/runs/457383033</a></p>\n</blockquote>\n<p>The biggest impact is to <code>exchange()</code> however that was primarily due to <a href=\"/d79d8a4a9c16298633efde4eb4935f86/sip-37.md\">SIP-37</a> (Fee Reclamation) that was also released in Achernar.</p>\n<p>By caching the various required addresses, we can reduce these down and not worry about having to write code in each function to limit how often we lookup the addresses required.</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 technical specification should describe the syntax and semantics of any new feature.-->\n<ol>\n<li>Introduce a local <code>mapping(bytes32 => address)</code> cache into <code>MixinResolver</code> - the functionality included in all contracts that need to communicate via the address resolver</li>\n<li>Ensure <code>MixinResolver</code> is instantiated with a list of <code>bytes32</code> addresses that the contract needs to know about</li>\n<li>Expose a function in <code>MixinResolver.setResolverAndSyncCache()</code> to sync the cache. This is to be called each deployment whenever any new contracts are added.</li>\n</ol>\n<p>Preliminary investigations after Caching and other improvements (such as SIP-41):</p>\n<table>\n<thead>\n<tr>\n<th>Contract</th>\n<th>Function</th>\n<th>Gas Used</th>\n<th>Diff from pre-Achenar</th>\n<th>%</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td>FeePool</td>\n<td>claimFees</td>\n<td>422,852</td>\n<td>+100,211</td>\n<td>+24%</td>\n</tr>\n<tr>\n<td>Synthetix</td>\n<td>burnSynths</td>\n<td>329,877</td>\n<td>-22,871</td>\n<td>-7%</td>\n</tr>\n<tr>\n<td>Synthetix</td>\n<td>exchange</td>\n<td>473,954</td>\n<td>+247,913</td>\n<td>+110%</td>\n</tr>\n<tr>\n<td>Synthetix</td>\n<td>issueMaxSynths</td>\n<td>437,013</td>\n<td>+94,466</td>\n<td>+28%</td>\n</tr>\n<tr>\n<td>Synthetix</td>\n<td>issueSynths</td>\n<td>394,636</td>\n<td>+33,566</td>\n<td>+9%</td>\n</tr>\n</tbody>\n</table>\n<blockquote>\n<p>from <a href=\"https://github.com/Synthetixio/synthetix/pull/434/checks?check_run_id=480906529\">https://github.com/Synthetixio/synthetix/pull/434/checks?check_run_id=480906529</a></p>\n</blockquote>\n<h2 id=\"rationale\" style=\"position:relative;\"><a href=\"#rationale\" aria-label=\"rationale 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>Rationale</h2>\n<!--The rationale fleshes out the specification by describing what motivated the design and why particular design decisions were made. It should describe alternate designs that were considered and related work, e.g. how the feature is supported in other languages. The rationale may also provide evidence of consensus within the community, and should discuss important objections or concerns raised during discussion.-->\n<ol>\n<li>A local mapping in each <code>MixinResolver</code> will prevent unnecssary CALL opcodes from being used (approximately 1518 gas)</li>\n<li>Having the list of required address names in each <code>MixinResolver</code> will allow automated checks each deployment to know what needs updating in the AddressResolver</li>\n<li>After each deployment, determine which <code>MixinResolver</code> contracts need to be resynced based on the list in #2 above</li>\n</ol>\n<h2 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</h2>\n<!--Test cases for an implementation are mandatory for SIPs but can be included with the implementation..-->\n<p><a href=\"https://github.com/Synthetixio/synthetix/blob/resolver-gas-improvements/test/contracts/MixinResolver.js\">https://github.com/Synthetixio/synthetix/blob/resolver-gas-improvements/test/contracts/MixinResolver.js</a></p>\n<p><a href=\"https://github.com/Synthetixio/synthetix/blob/resolver-gas-improvements/test/publish/index.js#L944-L1073\">https://github.com/Synthetixio/synthetix/blob/resolver-gas-improvements/test/publish/index.js#L944-L1073</a></p>\n<h2 id=\"implementation\" style=\"position:relative;\"><a href=\"#implementation\" aria-label=\"implementation 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>Implementation</h2>\n<!--The implementations must be completed before any SIP is given status \"Implemented\", but it need not be completed before the SIP is \"Approved\". While there is merit to the approach of reaching consensus on the specification and rationale before writing code, the principle of \"rough consensus and running code\" is still useful when it comes to resolving many discussions of API details.-->\n<p><a href=\"https://github.com/Synthetixio/synthetix/pull/434\">@Synthetixio/synthetix#434</a></p>\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":"8875a479-6854-5bd7-a07f-373b407af542","frontmatter__sip":46,"__params":{"frontmatter__sip":"46"}}},"staticQueryHashes":[]}