<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Yamen Merhi on Medium]]></title>
        <description><![CDATA[Stories by Yamen Merhi on Medium]]></description>
        <link>https://medium.com/@yamenmerhi?source=rss-77db016b9bb1------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*SfPbTqwf458GT-gh5tl8wg.jpeg</url>
            <title>Stories by Yamen Merhi on Medium</title>
            <link>https://medium.com/@yamenmerhi?source=rss-77db016b9bb1------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 28 Nov 2026 03:06:35 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@yamenmerhi/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[How .base.eth Names Work ?]]></title>
            <link>https://medium.com/patronum-labs/how-base-eth-names-work-a9578724520a?source=rss-77db016b9bb1------2</link>
            <guid isPermaLink="false">https://medium.com/p/a9578724520a</guid>
            <category><![CDATA[ethereum]]></category>
            <category><![CDATA[base]]></category>
            <category><![CDATA[eth]]></category>
            <category><![CDATA[layer-2-solution]]></category>
            <category><![CDATA[name-service]]></category>
            <dc:creator><![CDATA[Yamen Merhi]]></dc:creator>
            <pubDate>Tue, 03 Sep 2024 10:21:42 GMT</pubDate>
            <atom:updated>2024-09-03T10:21:42.624Z</atom:updated>
            <content:encoded><![CDATA[<h3>How .base.eth Names Work ?</h3><figure><img alt="Wondering how .base.eth names work ?" src="https://cdn-images-1.medium.com/max/1024/1*QtZ4a3V7-GITOFWSo19JNg.png" /></figure><p>This article provides a detailed explanation of “<em>.base.eth” </em>names, powered by the ENS protocol, which enables anyone to register and use a name like “<em>name.base.eth”</em>, as their main human readable identification on the blockchain.</p><p>We’ll cover their structure, how they function, the differences between “<em>.base.eth”</em> and “<em>.eth”</em> names, how Ethereum and Base are connected, and tackle important questions around decentralization, ownership, and effectiveness of these names.</p><h3>Table Of Content</h3><p>· <a href="#59c4"><strong>What are .base.eth names ?</strong></a><br>· <a href="#2e65"><strong>How .base.eth names work ?</strong></a><br> ∘ <a href="#e0d0">How <em>.eth</em> names work ?</a><br> ∘ <a href="#a6c6">Resolution of <em>.base.eth</em> names</a> <br> ∘ <a href="#0306">ENSIP-10: Wildcard Resolution</a><br> ∘ <a href="#e6e0">EIP-3668: Offchain Resolvers</a><br> ∘ <a href="#b532">Structure on Base</a><br> ∘ <a href="#9550">Architecture Summary</a><br>· <a href="#31b1"><strong>Potential Risks</strong></a><br> ∘ <a href="#f75a">Ownership of <em>base.eth</em></a><br> ∘ <a href="#397e">Offchain Gateway Control</a><br> ∘ <a href="#79f0">Implications</a><br> ∘ <a href="#c051">Mitigations</a><br><strong>· </strong><a href="#25a7"><strong>How is it different from <em>.eth</em> Names ?</strong></a><br><strong>· </strong><a href="#d6cd"><strong>Similar Cases: Uniswap <em>uni.eth</em> names</strong></a><br><strong>· </strong><a href="#aeb0"><strong>Are <em>.base.eth</em> and <em>.uni.eth</em> Names Beneficial for the Ecosystem ?</strong></a><br><strong>· </strong><a href="#7b0f"><strong>Summary</strong></a></p><h3>What are .base.eth names ?</h3><p>Last week, Base launched “<em>.base.eth”</em> names, designed to function as human-readable identifiers on the blockchain, similar to “<em>.eth”</em> names. For example, instead of sending 1 ETH to the address <em>“0x849151d…8CC2308bf1”</em>, it can be sent to <em>“jesse.base.eth”.</em></p><p>They were launched via a Dutch auction with prices starting at 100 ETH and decreasing over 36 hours to reach standard rates between 0.1 ETH and 0.0001 ETH. This pricing mechanism was used to prevent name squatting by bots, who might buy high-profile names at low prices and resell them at a premium.</p><iframe src="https://cdn.embedly.com/widgets/media.html?type=text%2Fhtml&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;schema=twitter&amp;url=https%3A//x.com/base/status/1825990553244258665&amp;image=" width="500" height="281" frameborder="0" scrolling="no"><a href="https://medium.com/media/d9292ba0975f9051ee07d2ee27906a82/href">https://medium.com/media/d9292ba0975f9051ee07d2ee27906a82/href</a></iframe><h3>How .base.eth names work ?</h3><p>To understand how “<em>.base.eth”</em> names work, it is important to have at least a high-level understanding of how “<em>.eth”</em> names work.</p><h4>How .eth names work ?</h4><p><em>“.eth”</em> names are formed from many components, the simplest way to understand the architecture of these names is the following:</p><p>The records of a “<em>.eth”</em> name are recorded in the main ENS Registry, where each name has the following information recorded:</p><ul><li>Address of the Owner</li><li>Address of the Resolver</li><li>TTL (not relevant in our article)</li></ul><p>The resolver, stores relevant information for each name, for example, the address that it wants to resolve to, a content hash to parse links, etc.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*nAefI5HxNeotRooQ.png" /></figure><p>For example, for the name “<em>ens.eth”:</em></p><ul><li><em>0xb6E040C9ECAaE172a89bD561c5F73e1C48d28cd9 </em>is the owner.</li><li><em>0xFe89cc7aBB2C4183683ab71653C4cdc9B02D44b7 </em>is the resolved address.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/564/1*W2icC86LW9W-7MipX00-yQ.png" /></figure><p>The owner of a name has defined abilities:</p><ul><li>Ability to transfer the ownership of the name.</li><li>Ability to create subnames and change their ownership seamlessly. (Owner of “<em>ens.eth”</em> can create and change ownership of “<em>nick.ens.eth”</em>)</li></ul><p>The resolved address is the address returned in a query of the name<em> </em>on any interface or library.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/690/1*Pu1ZeU3ZXK-gfKwd9gxQXA.png" /></figure><p>This diagram summarizes the entire flow of a query from a client.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/692/0*xd6ApP7AAYhZLRKR.PNG" /></figure><h4>Resolution of .base.eth names</h4><p>With a solid understanding of how “<em>.eth”</em> names work, it is now possible to explore “<em>.base.eth”</em> names.</p><p>The first assumption when examining the subdomains section on “<em>base.eth” </em>is to see all the “<em>.base.eth”</em> names registered. However, there are only 9 subdomains that exist. Only 9 !!!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*D4G1P8na4KGDi8mlAdlgjQ.png" /></figure><p>Yet, when navigating to <a href="https://app.ens.domains/jesse.base.eth">ens.domains</a> and querying “<em>jesse.base.eth”</em>, records information is returned, indicating that the name exists.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*yJ1cnGT37W_arNoMxJOTTg.png" /><figcaption><a href="https://app.ens.domains/jesse.base.eth">https://app.ens.domains/jesse.base.eth</a></figcaption></figure><p>A deeper investigation of the ENS Registry reveals that “<em>jesse.base.eth”</em> does not exist in the ENS Registry — there is no owner, no resolver, and no TTL set, and the record doesn’t exist.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*MMf0HbVfGeOUvvLIhWTIpg.png" /><figcaption>“jesse.base.eth” is equal to 0x286c3ecf9d29c1d2cc5b4606d9f2164c4a6f069f8edcc0bb406b838b69856509 Generated from <a href="https://www.evmrobot.com/evm-namehash">https://www.evmrobot.com/evm-namehash</a></figcaption></figure><p>This raises several questions:</p><ul><li>Could this be a bug ? Why is the “<em>jesse.base.eth”</em> name not showing up among the subnames of “<em>base.eth” </em>?</li><li>Why does “<em>jesse.base.eth”</em> resolve even though it does not appear in the main registry ?</li><li>Why are transactions being processed on Base to register a “<em>.base.eth</em>” name, even though the ENS Registry exists on Ethereum ?</li><li>How is data recorded and shared between Base and Ethereum ?</li></ul><p>The answers to these questions lie in ENSIP-10 and EIP-3668.</p><h4>ENSIP-10: Wildcard Resolution</h4><p><strong>ENSIP-10</strong> defines a method for resolving subnames through their owner. For example, in resolving “<em>jesse.base.eth”</em>, the process is as follows:</p><ol><li>Query the ENS Registry on Ethereum for “<em>jesse.base.eth” </em>name.</li><li>Since the name does not exist and is a subname, perform a wildcard resolution by querying the resolver of “<em>base.eth”.</em></li><li>Use the records information of “<em>jesse.base.eth”</em> but to be extracted from “<em>base.eth” </em>resolver<em>.</em></li></ol><h4>EIP-3668: Offchain Resolvers</h4><p>The records information from “<em>base.eth”</em> is used, but even this information is not tracked on Ethereum. The resolver for “<em>base.eth”</em> directs the query to an off-chain URL. This URL serves as an endpoint that returns the required data about subnames.</p><p>This mechanism is defined by <a href="https://eips.ethereum.org/EIPS/eip-3668">EIP-3668</a>, which allows resolvers to point to an external URL for data retrieval.</p><h4>Structure on Base</h4><p>On Base, the “<em>.base.eth”</em> name is recorded within a registry, using an architecture similar to that of ENS, where the same type of information is recorded in the registry, and the owner can modify records in the resolver. For example, “j<em>esse.base.eth”</em> is recorded on-chain on Base with a resolver holding the records information, such as the resolved address, content hash, etc ..</p><p>Thus, the actual name “<em>jesse.base.eth”</em> is owned on the Base Registry on Base, not on the ENS Registry on Ethereum.</p><p>The off-chain URL retrieved from Ethereum reads the data from the Base Registry through an off-chain lookup.</p><h4>Architecture Summary</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*ON2-XDVo0WqZ94PD" /><figcaption><a href="https://github.com/base-org/basenames/tree/main">https://github.com/base-org/basenames/tree/main</a></figcaption></figure><p>1- “<em>jesse”</em> registers “<em>jesse.base.eth”</em> on Base in the BaseRegistry.<br>2- The resolved address is set in the L2Resolver.<br>3- The client wants to send x ETH to “<em>jesse.base.eth”</em>.<br>4- The client queries “j<em>esse.base.eth”.</em><br>5- The name does not exist on Ethereum, so the parent, “<em>base.eth”</em>, is queried.<br>6- “<em>base.eth”</em> resolves to an off-chain gateway.<br>7- The off-chain gateway reads from the L2Resolver on Base.</p><h3>Potential Risks</h3><p>There are important implications to consider with the current structure of “<em>.base.eth”</em> names, and there are two main issues.</p><h4>Ownership of base.eth</h4><p>When querying a name like “<em>name.base.eth”</em>, the query will always start with checking if the name exists on Ethereum. If the name does exist on Ethereum, no wildcard resolution will occur, meaning that any information from Base will not be used. For example, going back to the example of the actual 9 “<em>.base.eth”</em> subnames, “<em>mint.base.eth”</em> will be resolved on Ethereum and won’t be checked against Base, as it already exists on Ethereum. (Check WildCard Resolution section)</p><p>This raises the question of how a name gets registered on Ethereum. As mentioned earlier, the owner of “<em>base.eth”</em> — which is a smart contract — can seamlessly assign subdomains according to its logic.</p><p>The owner of “<em>base.eth”</em> is a Gnosis Safe, managed by 3 out of 11 executors. This setup means that it requires at least 3 signers to agree to assign “<em>name.base.eth”</em> to an address and to set its resolver to a different address than the one available on Base.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*UOnOlIJUaO4pAVIUXaWvvA.png" /><figcaption>The Gnosis Safe owning base.eth, allowed to register subnames. 3/11 multisig</figcaption></figure><h4>Offchain Gateway Control</h4><p>Another point of concern is that, according to ERC-3668, the resolver on Ethereum uses a URL to trigger the resolution. This URL, which is embedded in the smart contract, is changeable.</p><p>This means the URL could potentially be changed to another one that does not point to the Base Registry on Base but instead to an internal database managed by the Base team. Additionally, even if the URL remains unchanged, the backend logic could be modified to point to this internal database. For example, all names could be made to resolve to the same address, without any transaction occurring on the blockchain.</p><p>Due to the use of a gateway service to generate responses, there is additional risk of unavailability: the gateway could be out of operation, or could choose to selectively refuse to answer (censor) certain queries.</p><h4>Implications</h4><p>Assuming the trust in the Base team, there still exists a potential threat if control over 3 of the 11 Gnosis Safe signers is compromised. In such a scenario, a malicious actor could wait for scheduled transactions based on “<em>.base.eth”</em> names and change the resolved address of the target “<em>.base.eth”</em> name to intercept funds, effectively redirecting them to an attacker-controlled address.</p><p>Moreover, in a scenario where the attacker changes the URL to point to a malicious database, the attacker could manipulate the resolution of multiple “<em>.base.eth”</em> names simultaneously.</p><p>Any insider with access could reproduce this scenario without needing to trigger an on-chain transaction. This raises several questions.</p><ul><li>What is to prevent someone from momentarily changing what the URL points to — switching it to an internal database that maps names to a specific address and then quickly switching it back ?</li><li>How would users know if such an event occurred, especially if they were led to believe that any issues were due to their own actions rather than the manipulated URL ?</li><li>What can be done to prevent such cases ?</li><li>What if the gateway was out of service ?</li></ul><h4>Mitigations</h4><p>There are no options to mitigate the possibilities of changes to the resolution based on the architecture used. Even if control over the “<em>.base.eth”</em> name is locked, the wildcard resolution using the URL owned by the Base team means that this URL can still be altered. The resolution process could be redirected offline from querying the registry to an internal database.</p><h3>How is it different from .eth Names ?</h3><p>Unlike the case of “<em>.base.eth”</em> names, the ownership of “<em>.eth”</em> names is managed by a smart contract known as the EthRegistrar, which has specific rules for assigning subnames (e.g., “<em>name.eth”</em>).</p><p>The owner of the RootRegistry has revoked access to the “<em>.eth”</em> name, meaning that even the Gnosis Safe of the ENS team cannot change ownership of “<em>.eth</em>” name, or seize ownership of “<em>name.eth”</em> from anyone. The most they can do is modify the logic for assigning and renewing names in the future.</p><h3>Similar Cases: Uniswap uni.eth names</h3><p>Before Base, Uniswap adopted a similar approach with “<em>name.uni.eth”</em> names. However, Uniswap decided to make these names completely free for users to claim in their app, and they are registered in an off-chain database not on the blockchain. The resolution is handled via a URL: <a href="https://gateway.uniswap.org/v2/unitags/ccip-read/%7Bsender%7D/%7Bdata%7D.json.">https://gateway.uniswap.org/v2/unitags/ccip-read/{sender}/{data}.json</a></p><h3>Are .base.eth and .uni.eth Names Beneficial for the Ecosystem ?</h3><p>Whether “<em>.base.eth”</em> and “<em>.uni.eth”</em> names are beneficial for the ecosystem largely depends on individual perspectives. Each user has their own opinion on the trade-off between decentralization and ease of use when it comes to onboarding more people into the blockchain space.</p><p>Did this enhance the user experience (UX) ? Did it help onboard more people to the blockchain ? Certainly, yes. But do users truly own their names in the same way they would with “<em>.eth”</em> names ? The answer is no.</p><p>This brings up the core debate: sacrificing ownership to simplify onboarding is a complex issue and opinions vary widely among users. Some may value the convenience and accessibility, while others might be concerned about the lack of true decentralization and control. Ultimately, it is up to each user to decide whether this approach aligns with their values and expectations for the blockchain ecosystem.</p><h3>Summary</h3><p>The ownership of a “<em>.base.eth”</em> name on the Base registry on Base is secure, and there is no ability for this ownership to be seized. Users can set their own data, similar to how “<em>.eth”</em> names work on Ethereum, which is a valuable aspect of ownership.</p><p>However, the resolution that always happens on Ethereum — the critical factor in determining how names are mapped and used — is ultimately controlled by the Base team. This control can be exerted either on-chain by changing subdomain ownership or through the URL that facilitates the wildcard resolution pointing to names on Base.</p><p>In short:</p><ul><li><strong>Do you own your <em>.base.eth</em> name ?</strong> Yes.</li><li><strong>Do you control the resolution ?</strong> No.</li><li><strong>Should you worry about it ?</strong> That depends on your level of trust in the security that the Base team implements.</li></ul><p>This article aims to present a neutral perspective on <em>.base.eth</em> names, highlighting both their potential benefits and risks without casting aspersions on any entity.</p><blockquote>End of the article.<br><strong>Connect with me on </strong><a href="https://twitter.com/0xYamen"><strong>Twitter</strong></a><strong>, </strong><a href="https://github.com/YamenMerhi"><strong>Github</strong></a>,<strong> and </strong><a href="https://www.linkedin.com/in/yamenmerhi/"><strong>LinkedIn</strong></a><strong>.</strong></blockquote><h3>References :</h3><ul><li><a href="https://app.ens.domains/jesse.base.eth">https://app.ens.domains/jesse.base.eth</a></li><li><a href="https://www.evmrobot.com/evm-namehash">https://www.evmrobot.com/evm-namehash</a></li><li><a href="https://github.com/base-org/basenames/tree/main">https://github.com/base-org/basenames/tree/main</a></li><li><a href="https://github.com/ensdomains/ens-contracts">https://github.com/ensdomains/ens-contracts</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a9578724520a" width="1" height="1" alt=""><hr><p><a href="https://medium.com/patronum-labs/how-base-eth-names-work-a9578724520a">How .base.eth Names Work ?</a> was originally published in <a href="https://medium.com/patronum-labs">Patronum Labs</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Nick’s method — Ethereum Keyless Execution]]></title>
            <link>https://medium.com/patronum-labs/nicks-method-ethereum-keyless-execution-168a6659479c?source=rss-77db016b9bb1------2</link>
            <guid isPermaLink="false">https://medium.com/p/168a6659479c</guid>
            <category><![CDATA[solidity]]></category>
            <category><![CDATA[multichain]]></category>
            <category><![CDATA[evm]]></category>
            <category><![CDATA[ethereum]]></category>
            <dc:creator><![CDATA[Yamen Merhi]]></dc:creator>
            <pubDate>Sun, 22 Jan 2023 21:01:12 GMT</pubDate>
            <atom:updated>2024-09-02T10:58:52.741Z</atom:updated>
            <content:encoded><![CDATA[<h3>Nick’s method — Ethereum Keyless Execution</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/612/1*KxTEVDs7kHCQW0ZzMAX3CQ.jpeg" /></figure><p>This article will provide a detailed explanation of “<em>Nick’s method”</em>, a Keyless execution/deployment method widely referenced in various Ethereum Improvement Proposals but not often fully explained.</p><p>We’ll cover its origin, how it functions, and the benefits it offers such as reduced trust requirements and the ability for multi-chain deployment on the same address.</p><h3>Table Of Content</h3><ul><li><a href="#66f5"><strong>Who is Nick ?</strong></a></li><li><a href="#fb58"><strong>How does it work ?</strong></a><br>- <a href="#8a98">How a Transaction is Constructed ?</a><br>- <a href="#0925">Messing Up with the Transaction</a><br>- <a href="#a86f">Executing from the address recovered</a></li><li><a href="#5b84"><strong>Real-World Usecases</strong></a><br>- <a href="#0601">Minimizing Trust</a><br>- <a href="#153f">Multi-chain Deployment on the same address</a></li><li><a href="#0c39"><strong>EIP-155 and ChainId</strong></a></li><li><a href="#dcb3"><strong>Edge Cases</strong></a></li><li><a href="#f431"><strong>NPM Package</strong></a></li></ul><h3>Who is Nick ?</h3><p>Nick’s Method was named after <a href="https://medium.com/@weka">Nick Johnson</a>, a Lead developer of ENS and an alum of Ethereum Foundation, due to his work in creating the first <a href="https://github.com/Arachnid/extrabalance">script</a> for this technique.</p><p>The method was inspired by an idea proposed by <a href="https://twitter.com/VitalikButerin">Vitalik Buterin</a>, the founder of Ethereum, that a transaction can be valid even if it is not signed by a private key.</p><p>This is what led to the use of the term <em>“Keyless”</em>, where no private key was associated with the transaction to be valid.</p><h3>How does it work ?</h3><p>Before starting with how it works, it is essential to know in a high-level way, how an Ethereum Transaction is constructed.</p><h4>How a Transaction is Constructed ?</h4><p>The code below shows a simple Ethereum Tx of type 0 (Legacy)</p><pre>{<br>  nonce: &quot;0x00&quot;,<br>  gasPrice: &quot;0x09184e72a000&quot;,<br>  gasLimit: &quot;0x27100&quot;,<br>  to: &quot;0x0000000000000000000000000000000000000000&quot;,<br>  value: &quot;0x01&quot;,<br>  data: &quot;0x7f7465737432000000000000000000000000000000000000000000000000000000600057,<br>}</pre><p>The JSON fields state the address being interacted with, the amount of value, the data, the gasPrice, and gasLimit.</p><p>After signing the Tx with a private key, we will have 3 more fields related to the transaction’s signature (v, r, s):</p><pre>{<br>  nonce: &quot;0x00&quot;,<br>  gasPrice: &quot;0x09184e72a000&quot;,<br>  gasLimit: &quot;0x27100&quot;,<br>  to: &quot;0x0000000000000000000000000000000000000000&quot;,<br>  value: &quot;0x01&quot;,<br>  data: &quot;0x7f7465737432000000000000000000000000000000000000000000000000000000600057&quot;,<br>  v: &quot;0x26&quot;,<br>  r: &quot;0x223a7c9bcf5531c99be5ea7082183816eb20cfe0bbc322e97cc5c7f71ab8b20e&quot;,<br>  s: &quot;0x2aadee6b34b45bb15bc42d9c09de4a6754e7000908da72d48cc7704971491663,<br>}</pre><blockquote>When signing, any change in one of the main Transaction fields, such as nonce, gasPrice, gasLimit, to, value and data will result in a different signature value.</blockquote><p>As you can see, there is no <em>“from”</em> field in the transaction, so how would the network know who is executing the transaction ? From whom the gasFees and value being sent will be deducted ?</p><p>The network will use the <em>“</em><a href="https://soliditydeveloper.com/ecrecover"><em>ecrecover</em></a><em>”</em> function that takes a message and a signature as parameters and will recover the public key =&gt; address of the signer from it.</p><p>In this context, the main transaction acts as the message, with v,r, and s serving as the corresponding signature.</p><pre>// Pseudo-code :)<br><br>// When Signing<br><br>const addressA = &#39;0x067024faa81ACBF984EEA0E4E75Fcc3F44558AfD&#39;;<br>const addressAPrvtKey = &#39;b37ff986840fc14c956d74a7a3375488cce495d7fe36cfa5e8201df1f1a03aaf&#39;;<br><br>const {v,r,s} = sign(Transaction, addressAPrvtKey);<br><br>&gt; v: 0x25<br>&gt; r: 0x79855f28bdc327adbcbf85d32cb76b9aeef67dc5b9c4dafbd0a94ad3757ec501<br>&gt; s: 0x3a51556f88edc2e218c5b6c540662bf289a09f16e3a0f505fcfe435dfb490a22<br><br>// When Recovering<br><br>const addressRecovered = ecrecover(Transaction, v, r, s);<br><br>&gt; addressRecovered: 0x067024faa81ACBF984EEA0E4E75Fcc3F44558AfD</pre><p>As shown in the code above, address A is signing the transaction. When the transaction is passed to the network, it will utilize the <em>“ecrecover”</em> function on the transaction and the associated signature parameters to identify address A as the sender of the transaction, responsible for paying the gas fees, etc.</p><blockquote>It doesn’t matter who forward the transaction to the network because as stated before, the address executing the transaction is the one recovered from the transaction and the signature not necessarly the person forwarding (broadcasting) the transaction to the network.</blockquote><h4>Messing Up with the Transaction</h4><p>Since the address originating the transaction is recovered from the Transaction itself and the signature fields, what happens if we mess up with one of the signature parameters ?</p><p>It turns out that <em>“ecrecover”</em> will work fine with ~most~ of the randomly generated <em>v, r, s </em>values, and will return a valid Ethereum address corresponding to the message and the signature.</p><pre>// Pseudo-code :)<br><br>If v, r, s were changed to: <br><br>&gt; v: 0x25<br>&gt; r: 0x1212121212121212121212121212121212121212121212121212121212121212 // Human generated &amp; Random<br>&gt; s: 0x0000000000000000000000000000000001000000000000000000000000000000 // Human generated &amp; Random<br><br>// When Recovering<br><br>const addressRecovered = ecrecover(Transaction, v, r, s);<br><br><br>// Return a random ethereum address<br><br>&gt; addressRecovered: 0xe2140bdbe71cdf1d1df3a6b5d85939d1ad313722</pre><p>Usually, the v, r, and s values are generated whenever an address signs a message with the private key associated.</p><p>Although the address recovered didn’t sign the Transaction himself, the Transaction (Message) with these randomly generated signature values will return its address (address recovered).</p><h4>Executing from the address recovered</h4><p>Even with the alteration of v, r, and s values to randomly generated values, the transaction will not be considered as <em>“invalid”</em>. It will still be executed successfully from the recovered address, given that the address recovered from the transaction and the signature has sufficient funds to cover the gas fees.</p><p>In this case, the solution would be to manually fund the address recovered with some ether so the gasFees can be deducted from its balance.</p><p>After funding the address recovered, and broadcasting the transaction to the network, the transaction will be successfully executed from the address recovered.</p><blockquote>The probability of having the address recovered used by someone else (controlled by a known private key) is <strong>extremly low</strong>, which make funding it and assuming the nonce for it safe.</blockquote><h4>Summary</h4><p>In summary, this method allows the execution of a transaction without being signed by a private key (<em>Keyless</em>), thus generating a <em>“single-use uncontrollable address”</em> just for the purpose of executing a transaction from it.</p><h3>Real-World Usecases</h3><p>At first, it’s hard to predict how this method can be used. Why would someone execute a transaction from an uncontrolled address ? Why not from his main address ?</p><h4>Minimizing Trust</h4><p>As described in Nick’s article, <a href="https://weka.medium.com/how-to-send-ether-to-11-440-people-187e332566b7">How to send Ether to 11,440 people</a>, this method was used to send Ether to 11,440 addresses on the blockchain following the DAO Hack.</p><p>Given that the funds were controlled by a multi-sig, it was really hard and resource-consuming to require multiple signatures each time they need to send the funds from the multi-sig to an address. That could take forever, and will consume a lot of gas.</p><p>Also sending the funds to one controlled address and <strong>putting trust in this address</strong> to send the ether to all of the other 11,440 <strong>was not an option.</strong></p><blockquote>Are they going to spend a week painstakingly signing 11,440 individual transactions? Are they going to send the whole amount to an account controlled by a single individual so they can make the payments ?</blockquote><blockquote>It’s possible to make all the transfers <strong>trustlessly</strong>, in a manner that requires only a single transfer by the trustees— Nick Johnson</blockquote><p>In short, the solution was to create a <a href="https://github.com/Arachnid/extrabalance/blob/master/multisend.py#L11">MultiSend</a> contract that sends an array of values (ethers) to an array of recipients:</p><ul><li>To reach 11,140 addresses, the total tx needed is 104 different tx.<br>Generate 104 transactions that interact with MultiSend and send Ether to ~110 addresses each (because of the gas limit).</li><li>Mess up with the signature of the txs generated.</li><li>Recover with <em>“ecrecover”</em> 104 uncontrolled addresses.</li><li>Generate a tx that interacts with MultiSend again to fund ether to the 104 addresses.</li><li>Modify the signature then recover an uncontrolled address.</li><li>Send all the needed funds from the multi-sig to the last recovered uncontrolled address.</li><li>Broadcast the transaction that funds the 104 addresses from the last recovered uncontrolled address to the network.</li><li>Broadcast the transactions that fund 110 individual addresses from the 104 addresses to the network.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/0*m3m8SbtcKxcL-jXS.jpeg" /><figcaption>How to send Ether to 11,440 people — <a href="https://weka.medium.com/?source=post_page-----187e332566b7--------------------------------">Nick Johnson</a></figcaption></figure><blockquote>.. starting the whole process that will result in sending ether to everyone on the list — all with only a single signature required, and <strong>without needing to trust an individual with the funds.</strong></blockquote><h4>Multi-chain Deployment on the same address</h4><p>A contract address is generated based on two factors: the sender&#39;s address and his nonce.</p><p>Therefore, it is technically possible to deploy contracts at the same address by broadcasting the contract deployment transaction from the same address with the same nonce on different networks, even without using Nick’s method. However, what benefits does Nick’s method offer that this method doesn’t ?</p><p>First, the problem with this type of deployment is that:</p><ul><li>It requires maintenance and manual work, so someone needs to preserve the private key that controls the address safely.</li><li>There is a possible probability of messing with the nonces and having a nonce higher than the nonce used to deploy and losing the possibility to deploy the contract at the same address.</li></ul><p>Registries and factories are typically the types of contracts that need to be deployed at the same address on multiple chains. This requires preserving the private key securely to ensure that the registry or factory has the same address on different chains that may be created in the future.</p><p>With the growing popularity of smart contract accounts and wallets, it’s becoming increasingly common to see accounts and wallets deployed at the same address across multiple networks. To make this possible, a CREATE2 Factory contract needs to be deployed on different chains with the same address.</p><p>Nick’s method offers a simple solution to deploy contracts at the same address on multiple chains, by creating a transaction that is sent to the network from an uncontrolled address.</p><p>The Steps would be:</p><ul><li>Generate a tx of type 0 — Legacy.</li></ul><pre>{<br>  nonce: &quot;0x00&quot;,<br>  gasPrice: &quot;0x09184e72a000&quot;,<br>  gasLimit: &quot;0x27100&quot;,<br>  value: &quot;0x00&quot;,<br>  data: &quot;0x&lt;bytecode of the contract&gt;,<br>}</pre><ul><li>Add a v field with a value of “0x1b” (27). (You’ll see why later 👀)</li><li>Add random values for r, s.</li></ul><pre>{<br>  nonce: &quot;0x00&quot;,<br>  gasPrice: &quot;0x09184e72a000&quot;,<br>  gasLimit: &quot;0x27100&quot;,<br>  value: &quot;0x00&quot;,<br>  data: &quot;0x&lt;bytecode of the contract&gt;&quot;,<br>  v: &quot;0x1b&quot;,<br>  r: &quot;0x0000000001000000000000000000000001000000000000000000000000100000&quot;,<br>  s: &quot;0x1212121212121212121212121212121212121212121212121212121212121212&quot;,<br>  <br>}</pre><ul><li>Recover the address of the deployer using <em>“ecrecover”.</em></li><li>Serialize the transaction to generate the raw transaction ready for broadcasting on the Ethereum network.</li></ul><p>You’ll have the rawTx, the deployer address, also you can get the address of the contract that will be created.</p><ul><li>You fund the deployer address with gasPrice * gasLimit.</li><li>Connect to different networks and Broadcast the rawTx.</li></ul><pre>const Web3 = require(&quot;web3&quot;);<br>const web3 = new Web3(/** Connect to different networks*/);<br><br>const rawTx = &#39;0xf9074b808506400000008307a1208080b906f8600560005560c0604052601460809081527f53696d706c6520436f6e7472616374204e616d6500000000000000000000000060a05260019061004190826100f3565b5034801561004e57600080fd5b506101b2565b634e487b7160e01b600052604160045260246000fd5b600181811c9082168061007e57607f821691505b60208210810361009e57634e487b7160e01b600052602260045260246000fd5b50919050565b601f8211156100ee57600081815260208120601f850160051c810160208610156100cb5750805b601f850160051c820191505b818110156100ea578281556001016100d7565b5050505b505050565b81516001600160401b0381111561010c5761010c610054565b6101208161011a845461006a565b846100a4565b602080601f831160018114610155576000841561013d5750858301515b600019600386901b1c1916600185901b1785556100ea565b600085815260208120601f198616915b8281101561018457888601518255948401946001909101908401610165565b50858210156101a25787850151600019600388901b60f8161c191681555b5050505050600190811b01905550565b610537806101c16000396000f3fe6080604052600436106100655760003560e01c8063c47f002711610043578063c47f0027146100ca578063f2c9ecd8146100ea578063f38fb65b1461010857600080fd5b806317d7de7c1461006a5780633fb5c1cb14610095578063568a1c69146100b7575b600080fd5b34801561007657600080fd5b5061007f61011d565b60405161008c9190610283565b60405180910390f35b3480156100a157600080fd5b506100b56100b03660046102d8565b600055565b005b6100b56100c5366004610307565b6101af565b3480156100d657600080fd5b506100b56100e5366004610307565b610205565b3480156100f657600080fd5b5060005460405190815260200161008c565b34801561011457600080fd5b506100b5610215565b60606001805461012c906103b8565b80601f0160208091040260200160405190810160405280929190818152602001828054610158906103b8565b80156101a55780601f1061017a576101008083540402835291602001916101a5565b820191906000526020600020905b81548152906001019060200180831161018857829003601f168201915b5050505050905090565b60323410156102055760405162461bcd60e51b815260206004820152601960248201527f4e6f7420656e6f7567682076616c75652070726f76696465640000000000000060448201526064015b60405180910390fd5b60016102118282610441565b5050565b60405162461bcd60e51b815260206004820152603660248201527f546172676574436f6e74726163743a72657665727443616c6c3a20746869732060448201527f66756e6374696f6e20686173207265766572746564210000000000000000000060648201526084016101fc565b600060208083528351808285015260005b818110156102b057858101830151858201604001528201610294565b818111156102c2576000604083870101525b50601f01601f1916929092016040019392505050565b6000602082840312156102ea57600080fd5b5035919050565b634e487b7160e01b600052604160045260246000fd5b60006020828403121561031957600080fd5b813567ffffffffffffffff8082111561033157600080fd5b818401915084601f83011261034557600080fd5b813581811115610357576103576102f1565b604051601f8201601f19908116603f0116810190838211818310171561037f5761037f6102f1565b8160405282815287602084870101111561039857600080fd5b826020860160208301376000928101602001929092525095945050505050565b600181811c908216806103cc57607f821691505b6020821081036103ec57634e487b7160e01b600052602260045260246000fd5b50919050565b601f82111561043c57600081815260208120601f850160051c810160208610156104195750805b601f850160051c820191505b8181101561043857828155600101610425565b5050505b505050565b815167ffffffffffffffff81111561045b5761045b6102f1565b61046f8161046984546103b8565b846103f2565b602080601f8311600181146104a4576000841561048c5750858301515b600019600386901b1c1916600185901b178555610438565b600085815260208120601f198616915b828110156104d3578886015182559484019460019091019084016104b4565b50858210156104f15787850151600019600388901b60f8161c191681555b5050505050600190811b0190555056fea2646970667358221220e33436a76b28a7ded5996fad916166dc8b63f86b65336f728d944e1b9252427b64736f6c634300080f00331ba0b0506c61293520454796fae142b4e173251fa5d91a7d6506cc0ca0669708065da00cd51f3367e8d81c6afa79ea89521b6b8dd777d23d26535bad37bc8d83f39c70&#39;<br><br>async function sendRawTx() {<br>    await web3.eth.sendSignedTransaction(rawTx)<br>    .on(&#39;receipt&#39;, console.log);<br>}<br><br>sendRawTx();</pre><p>So why we are getting the same address with this method ? Mainly because the address recovered is uncontrolled, meaning that the nonce is currently 0 on all chains. When this address deploys a contract, the address of the contract deployed is depending on the deployer nonce (0, same on all chains) and the address of the deployer (same on all chains). In this way, we can ensure that the contract to create will be deployed on the same address on all chains.</p><p>With this method, there is no need to safeguard a private key or need to be concerned about nonce being a specific value because it&#39;s going to be always zero for an uncontrolled address. The raw transaction can be made public and anyone who wants to deploy the contract can simply fund the address of the deployer with the required fees and broadcast the raw transaction to the network.</p><p>It is also possible to try different combinations of <em>r</em> and <em>s</em> values so the address of the contract that will be created would be a vanity address with special characters, like <a href="https://etherscan.io/address/0xfac100450af66d838250ea25a389d8cd09062629#code"><em>0xFaC100450Af66d838250EA25a389D8Cd09062629</em></a><em> </em>starting with<em> 0xFaC10 </em>≈ <em>Factory</em>.</p><h3>EIP-155 and ChainId</h3><p><a href="https://eips.ethereum.org/EIPS/eip-155">EIP-155</a> introduced the <em>chainId</em> as a measure to prevent transactions replay attacks by ensuring that transactions are only executed on the intended blockchain network, similar to how <em>nonces</em> prevent a transaction from being repeated multiple times on the same chain.</p><blockquote>Example: Bob has 10 Ether on Ethereum and 10 LYX on LUKSO, and wants to send Alice 3 Ethers. If he constructs the transaction without replay protection (chainId), it is possible for Alice to re-broadcast the same transaction on LUKSO and receive 3 LYX from Bob’s address.</blockquote><p>The <em>chainId</em> is included in the <em>v</em> value of the signature with the following formulas:</p><pre>v = CHAIN_ID * 2 + 35 || v = CHAIN_ID * 2 + 36</pre><p>This is problematic for applying specific usecases for nick’s method (Multi-chain deployment on the same address), where the transaction needs to be broadcasted on multiple chains without any modifications, including the <em>v</em> value. If the <em>v</em> value is changed, it will alter the signature and subsequently the deployer address recovered from the transaction and the signature, leading to different addresses for the contract on each chain, thereby defeating the purpose of deploying on the same address across different chains.</p><p>To resolve this problem and not having a <em>v</em> value related to a specific chain and to enable multi-chain transactions without the effect of the <em>chainId</em>, transactions can be executed without including the <em>chainId</em> and with a <em>v</em> value of 27 (0x1b in hex). This <em>v</em> value of 27 is the value used for transactions prior to the implementation of EIP-155.</p><h3>Edge Cases</h3><p>When using Nick’s method for the purpose of <a href="#153f"><strong>Multi-chain Deployment on the same address</strong></a>, it’s important to keep in mind that the raw transaction generated cannot be altered afterward. This is because any changes made to the transaction will affect the resultant contract and deployer address.</p><p>Therefore, it’s crucial to consider future gas prices when specifying the gasPrice value in the transaction. It’s recommended to set the gasPrice to a higher value in order to support potential increases in gas prices on other chains. So if you set the gasPrice in the transaction as 100 gwei, and in the future in chain B the gasPrice was 150, sending the rawTx generated in chain B will cause a revert.</p><p>Additionally, it is important to note that some networks nodes may block transactions that do not use the EIP155 protection, which could also be a limitation to consider. Therefore, more work need to be done on the node level to allow this kind of transactions with <em>— rpc.allow-unprotected-txs </em>flag.</p><blockquote>The term unprotected transaction is used to emphasize on the point where if v didn’t include the chainId, it’s possible to replay this transaction on other network. For our usecase, it’s an intended behavior, but for other scenarios it could be harmful. Like Alice and Bob scenario above.</blockquote><h3>NPM Package</h3><p>Given the limited documentation and tools available for using <em>Nick’s method</em>, I have created this article and an npm package that facilitates generating these kinds of transactions.</p><p><a href="https://www.npmjs.com/package/@patronumlabs/nick-method">@patronumlabs/nick-method</a></p><blockquote>End of the article.<br><strong>Connect with me on </strong><a href="https://twitter.com/0xYamen"><strong>Twitter</strong></a><strong>, </strong><a href="https://github.com/YamenMerhi"><strong>Github</strong></a>,<strong> and </strong><a href="https://www.linkedin.com/in/yamenmerhi/"><strong>LinkedIn</strong></a><strong>.</strong></blockquote><h4>References :</h4><ul><li><a href="https://ethereum.stackexchange.com/questions/43586/safely-deploying-a-contract-with-the-same-address-in-different-chains">https://ethereum.stackexchange.com/questions/43586/safely-deploying-a-contract-with-the-same-address-in-different-chains</a></li><li><a href="https://weka.medium.com/how-to-send-ether-to-11-440-people-187e332566b7">https://weka.medium.com/how-to-send-ether-to-11-440-people-187e332566b7</a></li><li><a href="https://github.com/Arachnid/extrabalance">https://github.com/Arachnid/extrabalance</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=168a6659479c" width="1" height="1" alt=""><hr><p><a href="https://medium.com/patronum-labs/nicks-method-ethereum-keyless-execution-168a6659479c">Nick’s method — Ethereum Keyless Execution</a> was originally published in <a href="https://medium.com/patronum-labs">Patronum Labs</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Gas Optimization in Solidity]]></title>
            <link>https://yamenmerhi.medium.com/gas-optimization-in-solidity-75945e12322f?source=rss-77db016b9bb1------2</link>
            <guid isPermaLink="false">https://medium.com/p/75945e12322f</guid>
            <category><![CDATA[blockchain]]></category>
            <category><![CDATA[solidity]]></category>
            <category><![CDATA[smart-contracts]]></category>
            <category><![CDATA[ethereum]]></category>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[Yamen Merhi]]></dc:creator>
            <pubDate>Fri, 25 Jun 2021 00:34:34 GMT</pubDate>
            <atom:updated>2021-12-30T13:21:49.123Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*g-hL7TVIGf9E3c4E7qQ94w.jpeg" /><figcaption>BTCMANAGER Copyrights</figcaption></figure><p>This article is going to give you a couple of tips to reduce <strong>gas consumption</strong> in your smart contracts.</p><p>It’s very important to understand how to do this because if it costs too much money to execute a function in your smart contract, fewer users will be willing to run your Dapp.</p><blockquote>It’s important to know that some information were taken from several resources that will be mentioned in the end.</blockquote><h3><strong>Tip #1: </strong>Pack your variables</h3><p>Solidity stores data in 256-bit memory slots. Variables less than 256 bits will be stored in a single slot, Data that does not fit in a single slot is spread over several slots.<br>Each storage slot costs gas, packing the variables helps you optimize your gas usage by reducing the number of slots our contract requires.</p><h4><em>Example :</em></h4><p>The Solidity compiler is only able to put 2 uint128 in the same 256-bit memory slots when they are declared next to each other. Otherwise, uint128 variables each occupies a separate uint256 just for themselves, wasting 128 bits for each slot (Like the first contract):</p><figure><img alt="Difference Between Variable Packing" src="https://cdn-images-1.medium.com/max/668/1*HFEUzto5w8b3SKtV0U5WAA.png" /></figure><h3>Tip #2: Turn On Solidity Optimizer</h3><p>When you compile Solidity smart contracts, you can specify an optimization flag to tell the Solidity compiler to produce highly optimized bytecode. This bytecode will consume less gas than if you don’t use the optimization flag.</p><p>You can enable optimization with this setting in your truffle-config.js file:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/250/1*trIVtHrxUNUeU-fbl1KrNg.png" /><figcaption>Truffle-config.js</figcaption></figure><h3>Tip #3: Delete variables that you don’t need</h3><p>In Ethereum, you get a gas refund for freeing up storage space.<br>Deleting a variable refund 15,000 gas up to a maximum of half the gas cost of the transaction. Deleting with the delete keyword is equivalent to assigning the initial value for the data type, such as 0 for integers.</p><h3>Tip #4: Compute known value off-chain</h3><p>If You know what data to hash, there is no need to consume more computational power to hash it using keccak256 , you’ll end up consuming <br>2x amount of gas.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/602/1*ITNGucexP9hRA6dauoPOTg.png" /></figure><h3>Tip #5: Do not shrink Variables</h3><p>This means that if you use uint8, EVM has to first convert it uint256 to work on it and the conversion costs extra gas! You may wonder, What were the devs thinking? Why did they create smaller variables then? The answer lies in packing. In solidity, you can pack multiple small variables into one slot, but if you are defining a lone variable and can’t pack it, it’s optimal to use a uint256 rather than uint8.</p><h3>Tip #6: Use Events</h3><p>Data that does not need to be accessed on-chain can be stored in events to save gas.</p><h3>Tip #7: Use Assembly</h3><p>When you compile a Solidity smart contract, it is transformed into a series of EVM (Ethereum virtual machine) opcodes.<br>With assembly, you write code very close to the opcode level. It’s not very easy to write code at such a low level, but the benefit is that you can manually optimize the opcode and outperform Solidity bytecode in some cases.</p><h3>Tip #8: Use Libraries</h3><p>If you have several contracts that use the same functionalities, you can extract these common functions into a single library, and then you’re gonna deploy this library just once and all your contracts will point to this library to execute the shared functionalities.</p><h3>Tip #9: Minimize on-chain data</h3><p>The less you put on-chain, the less your gas costs.<br>When you design a Dapp you don’t have to put 100% of your data on the blockchain, usually, you have part of the system (Unnecessary data (metadata, etc .. ) ) on a centralized server.</p><h3>Tip #10: Avoid manipulating storage data</h3><p>Performing operations on memory or call data, which is similar to memory is always cheaper than storage.</p><p>The following solidity code will help you understand the difference between a poor code and a better-optimized code</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/1*in0vzFVUOTxW2nbPpyCkwA.png" /></figure><p>In the Second contract, before running the for loop we’re assigning the value of a storage data d to _d to avoid accessing the storage each time we iterate.</p><h3>Tip #11: Use eth-gas-reporter</h3><p>This reporter displays gas consumption changes to each function in your smart contract.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ThLZD6H1rw28GWaBwNKCnw.png" /></figure><h3>Tip #12: Use Short-Circuiting rules to your advantage</h3><p>When using logical disjunction (||), logical conjunction (&amp;&amp;), make sure to order your functions correctly for optimal gas usage. In logical disjunction (OR), if the first function resolves to true, the second one won’t be executed and hence save you gas. In logical disjunction (AND), if the first function evaluates to false, the next function won’t be evaluated. Therefore, you should order your functions accordingly in your solidity code to reduce the probability of needing to evaluate the second function.</p><h3>Tip #13: Use ERC1167 To Deploy the same Contract many time</h3><p>EIP1167 minimal proxy contract is a standardized, gas-efficient way to deploy a bunch of contract clones from a factory.EIP1167 not only minimizes length, but it is also literally a “minimal” proxy that does nothing but proxying. <strong>It minimizes trust</strong>. Unlike other upgradable proxy contracts that rely on the honesty of their administrator (who can change the implementation), the address in EIP1167 is hardcoded in bytecode and remain unchangeable.</p><h3>Tip #14: Avoid assigning values that You’ll never use</h3><p>Every variable assignment in Solidity costs gas. When initializing variables, we often waste gas by assigning default values that will never be used.</p><p>uint256 value; is cheaper than uint256 value = 0;.</p><h3>Tip #15: Use Mappings instead of Arrays</h3><p>Solidity is the first language in which mappings are less expensive than arrays.<br>Most of the time it will be better to use a mapping instead of an array because of its cheaper operations.</p><h3>Tip #16: Limit the string length in the Require Statements</h3><p>If we are adding message strings to require statements, we can make them cheaper by limiting the string length to 32 bytes.</p><h3>Tip #17: Fixed-size Arrays are cheaper than dynamic ones</h3><p>If we know how long an array should be, we specify a fixed size:</p><pre>uint256[12] monthlyTransfers;</pre><p>This same rule applies to strings. A string or bytes variable is dynamically sized; we should use a byte32 if our string is short enough to fit.</p><p>If we absolutely need a dynamic array, it is best to structure our functions to be additive instead of subtractive. Extending an array costs constant gas whereas truncating an array costs linear gas.</p><p><strong>Connect with me on </strong><a href="https://www.linkedin.com/in/yamenmerhi/"><strong>LinkedIn</strong></a><strong> , </strong><a href="https://github.com/YamenMerhi"><strong>Github</strong></a>,<strong> and </strong><a href="https://twitter.com/YamenMerhii"><strong>Twitter</strong></a><strong>.</strong></p><blockquote>End of the article</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qH4N6Vp6bc_PuajD4z2Gyw.png" /></figure><h3>References :</h3><ul><li><a href="https://medium.com/coinmonks/gas-optimization-in-solidity-part-i-variables-9d5775e43dde">https://medium.com/coinmonks/gas-optimization-in-solidity-part-i-variables-9d5775e43dde</a></li><li><a href="https://mudit.blog/solidity-gas-optimization-tips/">https://mudit.blog/solidity-gas-optimization-tips/</a></li><li><a href="https://www.youtube.com/channel/UCZM8XQjNOyG2ElPpEUtNasA">https://www.youtube.com/channel/UCZM8XQjNOyG2ElPpEUtNasA</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=75945e12322f" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>