<?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 Lucca Martins on Medium]]></title>
        <description><![CDATA[Stories by Lucca Martins on Medium]]></description>
        <link>https://medium.com/@lucca-martins?source=rss-b1a14a29a950------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*g0jhuVsYRADZDVdbvwqBMQ.png</url>
            <title>Stories by Lucca Martins on Medium</title>
            <link>https://medium.com/@lucca-martins?source=rss-b1a14a29a950------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 05 Dec 2026 11:21:50 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@lucca-martins/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[The Hidden Security Feature in Contract Wallets You Don’t Know About]]></title>
            <link>https://coinsbench.com/the-hidden-security-feature-in-contract-wallets-you-dont-know-about-4ec65342adbf?source=rss-b1a14a29a950------2</link>
            <guid isPermaLink="false">https://medium.com/p/4ec65342adbf</guid>
            <category><![CDATA[ethereum]]></category>
            <category><![CDATA[contract-wallet]]></category>
            <category><![CDATA[web3]]></category>
            <category><![CDATA[smart-contracts]]></category>
            <category><![CDATA[solidity]]></category>
            <dc:creator><![CDATA[Lucca Martins]]></dc:creator>
            <pubDate>Thu, 26 Sep 2024 15:21:58 GMT</pubDate>
            <atom:updated>2024-10-01T08:51:33.455Z</atom:updated>
            <content:encoded><![CDATA[<h3>The Hidden Feature in Contract Wallets You Don’t Know</h3><p>With all the buzz surrounding contract wallets — especially when it comes to account abstraction (<a href="https://eips.ethereum.org/EIPS/eip-4337">EIP-4337</a>) — it’s no surprise that they significantly boost security. What might not be so clear, though, is exactly how they achieve this and what features provide this protection. I can tell you that the list is quite extensive, which is why today we’re diving into one of these functionalities: the convenience of setting and resetting token approvals in a single transaction.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*byixEUphvXVuvs-C" /></figure><p>For those not familiar with the term, <a href="https://eips.ethereum.org/EIPS/eip-20">ERC-20</a> tokens provide a function called approve that allows a wallet to authorize another address to use its tokens on its behalf. The idea behind this feature is to extend the token&#39;s capabilities beyond simple transfers, enabling other contracts to combine the movement of your tokens with additional actions.</p><p>The best example I can give is decentralized exchanges (DEXs), where you authorize them to take your Token A and, in return, they give you Token B based on an agreed-upon rate in the dApp. This makes it clear that the approve operation is extremely delicate since <strong>it&#39;s a programmatic declaration that you trust another entity</strong> <strong>to have free and unrestricted access to your assets</strong>.</p><p>Even though the approve method is supposed to limit the amount of tokens the designated third party can use, in practice, it doesn&#39;t always work out that way. That&#39;s because an Externally Owned Account (EOA) needs to perform the approval in a separate transaction from the one it uses to interact with the smart contract. Ideally, with each interaction with a contract, you would:</p><ol><li>Approve the amount of tokens to be used.</li><li>Interact with the target contract.</li><li>If necessary, reset the permission on any unused remaining tokens.</li></ol><blockquote>But since each new transaction costs time and network fees, users often resort to the most insecure shortcut: granting unlimited amount on token approvals</blockquote><p>According to <a href="https://www.coinbase.com/blog/security-ps-infinite-token-approvals">Coinbase’s blog</a>, more than $405 million has been stolen through this exploit since 2020. A significant portion of these cases doesn’t happen immediately after interacting with the contract but rather at a future event where the once-trusted contract is compromised via a vulnerability. It then falls under the control of a malicious entity that has your permission to tamper with your tokens (since you gave it on the past).</p><pre>function execute(<br>      address tokenAddress,<br>      address targetContractAddress,<br>      uint256 amount<br>  ) external {<br>      IERC20 token = IERC20(tokenAddress);<br><br>      // Step 1: Approve the spender to use a specific amount of tokens<br>      require(token.approve(targetContractAddress, amount), &quot;Token approval failed&quot;);<br><br>      // Step 2: Interact with the target contract<br>      ITargetContract(targetContractAddress).methodToInteract();<br><br>      // Step 3: Reset the token approval back to zero<br>      require(token.approve(targetContractAddress, 0), &quot;Reset token approval failed&quot;);<br>}</pre><p>And this is exactly where contract wallets step in with functionalities that are often not fully appreciated. By allowing us to perform multicalls in a single transaction, we can, for example, approve the token, execute the smart contract, and reset the permission on any remaining amount — all in one go. This not only saves time and network fees but also gives us the ability to manage token approvals immediately after an interaction, even before the transaction is finalized.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4ec65342adbf" width="1" height="1" alt=""><hr><p><a href="https://coinsbench.com/the-hidden-security-feature-in-contract-wallets-you-dont-know-about-4ec65342adbf">The Hidden Security Feature in Contract Wallets You Don’t Know About</a> was originally published in <a href="https://coinsbench.com/">CoinsBench</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Mocking Addresses Without Private Keys in Hardhat Tests]]></title>
            <link>https://coinsbench.com/mocking-addresses-without-private-keys-in-hardhat-tests-de35f960090a?source=rss-b1a14a29a950------2</link>
            <guid isPermaLink="false">https://medium.com/p/de35f960090a</guid>
            <category><![CDATA[solidity]]></category>
            <category><![CDATA[unit-testing]]></category>
            <category><![CDATA[smart-contracts]]></category>
            <category><![CDATA[hard-hat]]></category>
            <category><![CDATA[typescript]]></category>
            <dc:creator><![CDATA[Lucca Martins]]></dc:creator>
            <pubDate>Sat, 20 Apr 2024 14:27:08 GMT</pubDate>
            <atom:updated>2024-04-20T14:27:08.681Z</atom:updated>
            <content:encoded><![CDATA[<p>One common testing scenario for smart contracts is verifying access control. But what if you need to test how a contract behaves with an address for which you don’t have the private key? Or perhaps you’re testing whether a deployed contract can access methods of another contract?</p><blockquote>This is where <strong>Hardhat’s impersonate account</strong> mechanism comes into play!</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Z6SmHyDhbrJbzJ9PpcInig.png" /></figure><p>The Hardhat Network is specifically designed for developers, allowing you to impersonate any address on the chain. You can easily achieve this within your Hardhat tests using the following code snippet:</p><pre>const desiredAddress = &quot;&lt;desired-address-here&gt;&quot;;<br><br>await hre.network.provider.request({<br>  method: &quot;hardhat_setBalance&quot;,<br>  params: [<br>    desiredAddress,<br>    &quot;0x16345785D8A0000&quot; // Amount in wei (e.g., 10000 Ether)<br>  ]<br>});<br>await hre.network.provider.request({<br>  method: &quot;hardhat_impersonateAccount&quot;,<br>  params: [desiredAddress],<br>});<br>const signer = await ethers.getSigner(desiredAddress);</pre><p>In this code snippet, we first set a balance for the specified address using the hardhat_setBalance method, allowing it to initiate transactions. Following this, we use the hardhat_impersonateAccount method to tell the Hardhat network to impersonate the desired address. This allows us to use this address as a signer in our tests, without needing access to its private key.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=de35f960090a" width="1" height="1" alt=""><hr><p><a href="https://coinsbench.com/mocking-addresses-without-private-keys-in-hardhat-tests-de35f960090a">Mocking Addresses Without Private Keys in Hardhat Tests</a> was originally published in <a href="https://coinsbench.com/">CoinsBench</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Solidity: How to generate CreationCode from RuntimeCode]]></title>
            <link>https://coinsbench.com/solidity-how-to-generate-creationcode-from-runtimecode-293e1c7f28b1?source=rss-b1a14a29a950------2</link>
            <guid isPermaLink="false">https://medium.com/p/293e1c7f28b1</guid>
            <category><![CDATA[solidity]]></category>
            <category><![CDATA[web3]]></category>
            <category><![CDATA[smart-contracts]]></category>
            <category><![CDATA[development]]></category>
            <dc:creator><![CDATA[Lucca Martins]]></dc:creator>
            <pubDate>Wed, 10 Apr 2024 13:24:14 GMT</pubDate>
            <atom:updated>2024-04-22T14:50:28.469Z</atom:updated>
            <content:encoded><![CDATA[<p>Recently, I encountered a tricky problem that took me a while to solve. I’m sharing my journey to solve it in this post, hoping it can save someone else the headache.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/795/1*9U4fvi_NepL6m5xKuwzf7w.png" /></figure><p>Let’s begin by understanding the difference between <strong>RuntimeCode </strong>and<strong> CreationCode</strong> in solidity:</p><ul><li><strong>RuntimeCode</strong>: The compiled code that executes on the EVM once a contract is deployed, handling contract interactions and functions.</li><li><strong>CreationCode</strong>: The code that runs during contract deployment to generate and return the contract’s runtime code to the blockchain. It is basically an initial setup bytecode (known as <strong>Initcode</strong>) + <strong>RuntimeCode<br></strong>– <strong>InitCode: </strong>Includes the constructor instructions and some other instructions to help blockchain to store the contract bytecode</li></ul><blockquote>To arrive at the solution, we aim to write <strong>InitCode</strong> with an empty constructor and include instructions to properly store the <strong>RuntimeCode </strong>on blockchain.</blockquote><p>And we can easily do it with the following code:</p><pre>// SPDX-License-Identifier: MIT<br>pragma solidity ^0.8.20;<br><br>contract CreationCodeFromRuntimeCode {<br><br>    function howToUse() public pure{<br>        creationCodeFromRuntimeCode(type(ExampleContract).runtimeCode);<br>    }<br><br>    function creationCodeFromRuntimeCode(<br>        bytes memory bytecode<br>    ) internal pure returns (bytes memory) {<br>        return abi.encodePacked(getInitCodeOfEmptyConstructor(bytecode), bytecode);<br>    }<br><br>    function getInitCodeOfEmptyConstructor(<br>        bytes memory bytecode<br>    ) internal pure returns (bytes memory) {<br>        bytes1 pushType = 0x61;<br>        bytes memory codeLength = abi.encodePacked(bytes2(uint16(bytecode.length)));<br>        if (bytecode.length &lt;= 255) {<br>            pushType = 0x60;<br>            codeLength = abi.encodePacked(bytes1(uint8(bytecode.length)));<br>        }<br>        return<br>            abi.encodePacked(<br>                bytes18(0x608060405234801561001057600080fd5b50),<br>                pushType,<br>                codeLength,<br>                bytes11(0x806100206000396000f3fe)<br>            );<br>    }<br>}<br><br>contract ExampleContract {}</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=293e1c7f28b1" width="1" height="1" alt=""><hr><p><a href="https://coinsbench.com/solidity-how-to-generate-creationcode-from-runtimecode-293e1c7f28b1">Solidity: How to generate CreationCode from RuntimeCode</a> was originally published in <a href="https://coinsbench.com/">CoinsBench</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[The Trust Challenge in Software Development]]></title>
            <link>https://lucca-martins.medium.com/the-trust-challenge-in-software-development-9fe6a03addff?source=rss-b1a14a29a950------2</link>
            <guid isPermaLink="false">https://medium.com/p/9fe6a03addff</guid>
            <category><![CDATA[digital-signatures]]></category>
            <category><![CDATA[web3]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[blockchain]]></category>
            <category><![CDATA[attestation]]></category>
            <dc:creator><![CDATA[Lucca Martins]]></dc:creator>
            <pubDate>Tue, 26 Mar 2024 12:29:21 GMT</pubDate>
            <atom:updated>2024-03-26T12:29:21.834Z</atom:updated>
            <content:encoded><![CDATA[<p>In the digital age, our interaction with software is underpinned by an implicit act of faith. Each time we enter a password, share personal data, or even execute a transaction, we’re placing trust in remote servers controlled by third parties.</p><blockquote>This trust is not trivial — but it’s foundational to the functionality and security of the digital services we rely on.</blockquote><p>So here’s the challenge for us developers: How can we demonstrate to our users that we are securely storing their data, handling it appropriately, and ensuring our systems operate exactly as intended?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*WqtkB0eNamrFq8wQ" /></figure><p>And the answer to this question is Web3. You might have heard about it, often linked with crypto. But there’s much more to it. Web3 is not just about crypto, it really addresses the issue of trust in software development. Therefore, it’s not merely new technology; it represents a new way of thinking about how we can prove to a user everything on a software is safe and does what it should do without having to rely solely on our word.</p><p>But it’s not just developers who need to embrace this change; users too have a role in this new Web3 world. Learning about Web3 can empower users, giving them the tools to understand and verify the security and functionality of the software they use. This shift towards Web3 knowledge will happen naturally, just as users today grasp the difference between local and cloud storage, for example.</p><p>Diving deeper into the Web3 ecosystem, we encounter the concept of “<strong>trustless technology</strong>”. This idea, at its core, is about creating systems where trust is embedded within the technology itself, eliminating the need for users to trust third parties. This is, in it’s essence, interesting but as you may know this is not a silver bullet.</p><p>Contrary to what many might believe, Web3 is not solely about creating trustless environments. In fact, it encompasses a range of solutions that offer <strong>varying levels of trust</strong>, from completely trustless systems to those that necessitate some level of trust in specific entities. This diversity allows for a more nuanced approach to security and trust, acknowledging that different scenarios may require different solutions. And that’s why developers must know this variety of trust to decide which ones fits better in each solution.</p><p>So let’s dive in some technical examples to understand a bit better this new way of thinking when developing a software.</p><h3>1. Signatures in place of passwords</h3><p>In traditional authentication methods, using a password means we must place our trust in a server to store this password securely. But what if we could authenticate ourselves without ever having to share our password directly, proving we know it without actually revealing it?</p><p>The solution lies in cryptographic signatures. This Web3 approach to authentication allows users to prove their identity through a digital signature — a unique piece of data created using their private key (which is the equivalent to the password) to sign a transaction or message. The server can verify this signature with the corresponding public key, ensuring the user is who they claim to be without the need to exchange or store sensitive passwords. This method not only enhances security but fundamentally shifts the trust from storing sensitive data on servers to trusting in the mathematical certainty of cryptographic algorithms.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/0*Y0JtzxrN-cjkskxu.png" /><figcaption>Web3 Authentication</figcaption></figure><p>But as we mentioned before, Web3 has different levels of trust. So, even if we use a cryptographic signature to authenticate and eliminate the need to trust password storage, we still need to trust the server to correctly validate and authenticate only the correct users.</p><h3>2. Blockchain in place of servers</h3><p>The previous section highlighted how cryptographic signatures revolutionize authentication by reducing reliance on server-stored passwords. Yet, the question of trusting server execution remains. This is where blockchain technology shines, offering a robust solution to the trust issue surrounding the correctness of software execution.</p><p>Unlike traditional server models, where a single entity controls the execution and storage of data, blockchain operates on a decentralized network. Each participant (or node) in the network holds a copy of the ledger, making it nearly impossible to alter data or execute fraudulent activities without consensus among participants. This decentralization ensures that the execution of any software or transaction on the blockchain is transparent, verifiable by anyone, and, most importantly, tamper-proof.</p><p>By integrating blockchain in place of centralized servers, we significantly enhance the trustworthiness of software execution. Users don’t have to take a leap of faith that the server is executing software correctly; they can independently verify transactions and operations on the blockchain. This shift not only elevates the security and integrity of digital interactions but also redefines the concept of trust in software development. Through blockchain, we move towards a system where trust is not just promised but provably enforced, marking a significant leap forward in our quest for secure, reliable digital solutions.</p><p>And again, as we said before, this level of trust can vary. In blockchain, there’s a trilemma between decentralization, security, and scalability. So, the more decentralized it is, the less scalable.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*kxcx6-CG4nkDc0gW.png" /><figcaption>The Blockchain Trilemma</figcaption></figure><h3>3. Proofs in place of sharing data</h3><p>In today’s digital landscape, the onboarding process for most systems requires users to share personal data to prove their identity. This approach not only puts user data at risk but also relies heavily on the assumption that the data is stored and managed securely. However, Web3 introduces a transformative alternative: cryptographic attestations and proofs.</p><p>Cryptographic attestations offer a way for users to prove their identity or qualifications without directly sharing sensitive personal information. Instead of uploading documents or entering personal details, users can present a cryptographic proof that verifies they meet the necessary criteria. For example, consider a user needing to prove their age to access a service. In the traditional system, they would have to share a copy of an ID document, exposing personal information. With Web3, they could use a digital attestation signed by a trusted authority that verifies their age without revealing their exact birth date or other details.</p><p>This method leverages blockchain technology to provide a secure, verifiable, and privacy-preserving way of sharing information. The trust is placed not in the parties storing or handling data but in the mathematical certainty of the cryptographic processes involved. As a result, attestations and proofs shift the paradigm from sharing and storing vast amounts of personal data to a model where privacy is maintained, and security is inherent.</p><p>For those interested in diving deeper into how these cryptographic attestations can be implemented, further reading and practical examples can be found at <a href="https://docs.attest.sh/docs/welcome">Attestation documentation</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9fe6a03addff" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>