<?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[Northwest NFTs - Medium]]></title>
        <description><![CDATA[The blog of Northwest NFTs, a smart contract &amp; NFT agency. https://www.northwestnfts.com/ - Medium]]></description>
        <link>https://medium.com/northwest-nfts?source=rss----dbe9ddfc79cf---4</link>
        <image>
            <url>https://cdn-images-1.medium.com/proxy/1*TGH72Nnw24QL3iV9IOm4VA.png</url>
            <title>Northwest NFTs - Medium</title>
            <link>https://medium.com/northwest-nfts?source=rss----dbe9ddfc79cf---4</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 17 Nov 2026 06:46:13 GMT</lastBuildDate>
        <atom:link href="https://medium.com/feed/northwest-nfts" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Contract Review: DAW]]></title>
            <link>https://medium.com/northwest-nfts/contract-review-daw-4bc303607d30?source=rss----dbe9ddfc79cf---4</link>
            <guid isPermaLink="false">https://medium.com/p/4bc303607d30</guid>
            <category><![CDATA[nft]]></category>
            <category><![CDATA[ethereum]]></category>
            <category><![CDATA[solidity]]></category>
            <category><![CDATA[smart-contracts]]></category>
            <dc:creator><![CDATA[Patrick Price]]></dc:creator>
            <pubDate>Tue, 23 Nov 2021 07:20:08 GMT</pubDate>
            <atom:updated>2021-11-23T20:01:10.554Z</atom:updated>
            <content:encoded><![CDATA[<h3>Contract Review: Desperate Apewives</h3><p>Bored, Desperate, and Unoriginal</p><p>Today we’re going to review the <a href="https://etherscan.io/address/0xf1268733c6fb05ef6be9cf23d24436dcd6e0b35e#code">Desperate Ape Wives smart contract</a>. We’ll cover how the authors burned $40k whitelisting their members, and we’ll take a look at an alternative solution that would have saved the DAW team all that cash.</p><p>Looking at the DAW website, I’m surprised to see this is actually a different team than the BAYC drop! Not sure what the IP laws surrounding this entails, I’m not a copyright lawyer. I would definitely be interested in the outcome of a copyright suit. These types of cases are defining in growing tech spaces, drawing the legal boundaries that will guide government response to new tools and their many uses. Some NFTs are <a href="https://medium.com/dapperlabs/nft-license-2-0-why-a-nft-can-do-what-mickey-mouse-never-could-27673d5f29aa">adopting a standard license</a> describing how the NFT may be used and how the associated art may be commercialized. The BAYC website does include a license, stating the owner of a BAYC NFT owns “the underlying Bored Ape, the Art” and may monetize it in whatever way they see fit. Does this expand to creating a sister club with its own questionably similar generative set? I leave questions such as these to the lawyers.</p><p>Instead we’re interested in the technical competency of the DAW contract. Does the contract do what it purports to do? <a href="https://medium.com/northwest-nfts/bored-ape-yacht-club-contract-review-80dce503308e">We saw a handful of issues in the BAYC contract</a> that potentially undermine the agreement put forth by its creators.</p><p>First let’s look at the public views of this contract:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/414/0*VN9E6pfUAi1Krdt0" /></figure><p>This looks familiar. Looks like the provenance hash isn’t a constant, it’s not even set yet. This means, because the provenance hash was not set before sale, the DAW team could have reorganized the images <em>after</em> the mint but <em>before </em>reveal, giving themselves the best apes.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/287/0*OYAo6LbtaM7vp_Vj" /></figure><p>The DAW team has been nice enough to tell us ahead of time how many wives they reserved for themselves. We’ve mentioned Solidity styling before, these prepended underscores would typically mean these fields are private. That is not the case here.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/752/0*ONSZQOWCn74OTg5m" /></figure><p>This is interesting, a list of accounts. I guess the team can set administrators, whitelist addresses, and set some other limits.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/301/0*gkahXDU7YsnrtmgX" /></figure><p>Here are some sale times. I’m assuming the contract implements some kind of staged sale, with the whitelist and early supporters defined in “accounts” getting access to pre-sales or free mints.</p><p>Beyond the expected ERC-721 standard fields, there are just a few more unexpected functions: “payee,” “released,” “shares,” “totalReleased,” “totalShares.” These are reminiscent of the PaymentSplitter standard contract and I’m going to assume these functions have something to do with dividing up the enormous piles of ETH that tend to accrue in these types of contracts. Functionality such as these adds bulk to NFT contracts, and we recommend moving this functionality out to its own contract. Cheap clone payment splitters are easy to make, using <a href="https://paymentsplitter.io/">paymentsplitter.io</a>.</p><p>Now let’s look at the public writable functions.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/406/0*jKkhgI2w4Hxn1hJ3" /></figure><p>This all looks straightforward. Buttons to enable or disable the sale. A couple mint functions and an airdrop function, standard for an NFT sale. “lockProvenance” suggests the aforementioned provenance hash can be frozen. This is great, exactly the kind of fix we would have liked for the BAYC contract. Ideally, though, this would have been set before the sale started, not after.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/246/0*r4lI9xiOySol5cXW" /></figure><p>“Release” is another standard PaymentSplitter function, so these likely have to do with payout of the contract.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/262/0*JfGC38jAwAcboEqt" /></figure><p>These are the last custom fields of the contract. Not just one, but two setters for early supporters! These names imply some redundancy, which is typically bad. Finally, there are setters for the provenance and sale stage times, and one more setter to whitelist addresses.</p><p>Nothing at this point is throwing any obvious red flags. There are signs of redundancy in some of the functions, not great but definitely not a showstopper. I do wonder how many early supporters there were. The setEarlySupporters function takes in a list of addresses, I’m guessing to update the accounts structure that we saw before. If there are more than a few early supporters, then logging them all on-chain could get very expensive.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/544/0*fpvMaynTVbViJ46R" /></figure><p>Here’s our first look at the Desperate Ape Wives contract. The authors have decided to forgo the Solidity Style Guide’s recommended variable naming scheme, opting instead to follow no coherent naming scheme at all. This grab bag of _underscores, camelCase, and UPPERCASE is not organized in any meaningful way, and only adds confusion.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/314/0*8IbFU7717m4qNDBI" /></figure><p>This is where that list of “accounts” is held. Interesting that the accounts have a “walletLimit,” but a “walletLimit” of 3 is set above in the contract. More redundancy?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/675/0*HStaLdQdMs-jGXhh" /></figure><p>This is the contract’s constructor, which registers a handful of administrators in the “accounts” data structure. This is a relatively short list, but it’s important to keep in mind that the data associated with these accounts is saved on-chain. Every “word” of data (256bits) costs 20000 gas to initialize, and each admin set above is using two words; one word to set the “nftsReserved” and one to set “admin” to true. False and 0 values remain uninitialized in memory and do not cost gas. 40000 gas at 100 gwei is .004 ETH, or around $20 to set each admin and doll out their reserves.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/507/0*uxUcWf_wbPVqNthN" /></figure><p>“Signs of redundancy” is an understatement. These three functions are doing the same thing, and could be reduced to one function. Additionally, these functions have the same cost as setting the administrators above, and if there were three different whitelists, how many addresses did the team need to include? More on that later.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/0*Hf1PLIlH1742FmLf" /></figure><p>Down into the business logic and we find the first of many mint functions. This one airdrops two wives to the “donation” account you might have noticed before, wife #1 and wife #2. This seems nice until you realize those two apes are supposed to be going to different charities, which means that the “donations” address must be controlled by a team member. This begs the question then, why even create this special function when you could just use the following adminMint function instead?</p><p>It’s also worth noting, because this function hard codes the ids of 1 and 2, this function will fail if those ids have been minted already. Not an issue, as long as you make sure to mint these out first.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/579/0*l8qqseTNR61RIuDi" /></figure><p>This function could definitely be used to get those “donation” NFTs. As I mentioned above, if you ran this function before claimDonations, you wouldn’t be able to run claimDonations, because you will have already minted #1 &amp; #2.</p><p>There’s more quality redundancy in this function; it’s checking whether the msg.sender is an admin both in the function modifiers, and in the function body. Whether an admin check is even necessary is debatable, admin status is implied because “nftReserved” is set for the msg.sender, and only admins are granted reserves in the constructor. That makes this function triply redundant!</p><p>Another important note, this function contains a loop that is bounded by the values set in “nftReserved.” The way the function is written, it will only mint <em>every</em> reserve wife for the given account. So if you’re the account with 90 reserved apes (see admin[7] in the constructor), you have to mint out all of those apes at once. We can find this specific 90 ape mint event in the transaction log for the contract, and see that almost 10 million gas was used at once. This is very large. The current target block size for Ethereum is 15 million gas, and the maximum is 30 million. The block size limit was only raised above 10 million around a year ago in 2020, and before then, any transaction of this size would have failed.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/676/0*OdoH-2WaU2-b4GJr" /></figure><p>I like this function. It’s minimal but can still do everything “claimDonations” did, and more.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/867/0*qWBF8EbPUsab5db_" /></figure><p>And finally, the main mint function. No obvious problems here, but it does seem like the contract writers were afraid of their users. There is a reentrancy guard in the function modifiers, which is unnecessary as the function is written in a secure way. There is also a check to make sure the minting account isn’t a smart contract. This is a good way to stop some exploits, but given the unnecessary reentrancy guard, I have to wonder: was this thoughtfully put in to prevent a specific kind of attack (for example, sniping rare tokens), or was it put in as part of a shotgun attempt to fend off unknown unknowns?</p><p>Plenty of redundancy here, and redundant functionality leads to higher deployment costs, but I have a feeling that the cost of pushing redundant bytecode up to the blockchain wasn’t the most painful the DAW team had to deal with. I’m curious how many addresses the DAW team chose to whitelist, because the solution they used does not scale well. Thanks to the public nature of the Ethereum blockchain, we can actually peruse the transaction logs for the DAW contract and find any transactions that were run to whitelist addresses. Luckily, these calls are some of the earliest transactions interacting with this contract and were easy to find.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/518/0*2OtIQ0hmjGMX4Mvx" /></figure><p>These seven transactions represent every whitelisting transaction sent by the contract controller. Ignore the “0 Ether” indicator, instead note the smaller grey number. This is the gas fee for each transaction. We can see here, the DAW team spent a shocking 10 ETH whitelisting addresses before the sale. This is crazy but it does demonstrate the confidence the DAW team had in their community.</p><p>Unfortunately for the DAW team, this bonus 10 ETH out-of-pocket was totally unnecessary. Gasless whitelisting is possible using a Merkle distributor. With a Merkle distributor, the whitelist data is hosted off-chain and only a single value, the “root” of a Merkle tree containing our whitelist, needs to be loaded on-chain. To understand how this works requires a little background in the construction of Merkle trees. To construct a Merkle tree, first you start with a list of data, in this case, a list of addresses, and you apply a hash function to all those addresses. This new list of hashes are the leaf nodes of your Merkle tree, and you collect all these hashes together into the tree by pairing them off and hashing those paired hashes. You keep pairing off and hashing until you’re left with a single final hash value, and that is the “root” of your Merkle tree.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*0EgF6rHwGIIjIzrq" /></figure><p>What’s great about this structure is it provides a smart contract an easy and cheap way to check whether any given address is on the whitelist. To prove that they are on the whitelist, the member needs a “proof” that they can present to the contract. Suppose the above image is our Merkle tree whitelist, in order to prove to the contract that they are on the list, the owner of Address A needs the values in Hash B and Hash F. They can present that information to the contract, which will hash their address, climb it’s way up the tree with the hashes provided, and then verify that the root hashes match. This method requires distributing the proofs to whitelist members, which, with good web design, can be performed directly at sale time. This structure confers the added benefit that it does not expose whitelist members addresses before they have made a purchase.</p><p>Thanks to an abundance of caution by the DAW team, this contract is very secure. It’s surprising that they haven’t yet loaded a provenance, given the sale occurred almost a month ago. Guess the DAW team just doesn’t care, and I get the impression consumers don’t really care either. Until we educate the community and create systems of enforcement, the NFT business is going to remain a wild west that, to the intelligent consumer, comes off as an expensive way to download jpegs. I’m glad to see communities like <a href="https://twitter.com/Honest_NFT">HonestNFTs</a> picking up the charge, working to educate consumers and creating tools to detect abuse by NFT projects.</p><p>While security isn’t an issue with this contract, there are some clear inefficiencies that ended up being very expensive for the DAW team. $40,000 might seem like a drop in the bucket when you just raked in $3.5 million, but upfront costs like these can be prohibitive for smaller creators, and regardless, that’s still one less Benz in your new car collection.</p><p>Are you working on an NFT project? Need smart contract or web development support? Contact us at <a href="https://northwestnfts.com/">NorthwestNFTs.com</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4bc303607d30" width="1" height="1" alt=""><hr><p><a href="https://medium.com/northwest-nfts/contract-review-daw-4bc303607d30">Contract Review: DAW</a> was originally published in <a href="https://medium.com/northwest-nfts">Northwest NFTs</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Announcing: PaymentSplitter.io]]></title>
            <link>https://medium.com/northwest-nfts/announcing-paymentsplitter-io-9b27eccfacd4?source=rss----dbe9ddfc79cf---4</link>
            <guid isPermaLink="false">https://medium.com/p/9b27eccfacd4</guid>
            <category><![CDATA[ethereum]]></category>
            <category><![CDATA[smart-contracts]]></category>
            <category><![CDATA[digital-royalties]]></category>
            <category><![CDATA[dapps]]></category>
            <category><![CDATA[nft]]></category>
            <dc:creator><![CDATA[Patrick Price]]></dc:creator>
            <pubDate>Thu, 04 Nov 2021 21:34:54 GMT</pubDate>
            <atom:updated>2021-11-04T21:34:54.064Z</atom:updated>
            <content:encoded><![CDATA[<h3>Save gas and securely divide earnings between project contributors.</h3><p>While working on a recent project with a client here at NorthwestNFTs, we ran into a problem. Our client wanted the royalties on aftermarket sales to be split between many different accounts. They had advertised that they would be donating to charity, creating a community fund, and, of course, paying themselves and the artists. That’s a lot of addresses to manage, and OpenSea only lets you select one address to send royalties to for a set of art. Of course, the project lead could just have royalties sent to their account, and then divvy them up accordingly on a month to month basis, but now those royalties have transformed into an endless accounting task for some unlucky soul. We can do better than that.</p><p>Typically, to divide funds earned by a smart contract, we can import the <a href="https://docs.openzeppelin.com/contracts/2.x/api/payment">PaymentSplitter template contract by OpenZeppelin</a>. In the NFT use case, the contract is imported by the NFT contract and its functionality is used to divy up money earned from the primary sale. This solves the problem of splitting earnings for the mint sale, but royalties are paid out by OpenSea, not the minting contract, and OpenSea only accepts one address. To fix this, we can create a PaymentSplitter contract, with no added functionality, and make that the address OpenSea sends out to. Problem solved?</p><p>Deploying a PaymentSplitter solves the accounting task of splitting up royalties, but it still leaves a painful process of pulling funds through a contract with no dedicated UI. Each user has to save the splitter address and use EtherScan to release funds. Unfortunately, checking on EtherScan whether you have funds to release in the first place is a nightmare task that requires:</p><ol><li>Looking up the address of every payee</li><li>Looking up the payout ratio of each payee</li><li>Looking up how much Eth has already been released to each payee</li><li>A bunch of very exciting math</li></ol><p>Now imagine you’re an artist that’s worked on 5 different NFT projects, are expecting royalties in this way, and you have to keep track of all that. Not a lot of fun. Realistically, you’d like a single service website that can show you all of your available royalties from the projects you’ve worked on. I, personally, love simple “send me money” buttons.</p><p>To solve this problem, we are introducing <a href="https://paymentsplitter.io/">PaymentSplitter.io</a>. This utility allows you to easily create and keep track of payment splitters. Cloning existing on-chain code dramatically reduces the cost of deploying new payment splitters, and logging all splitters in a central registry makes it quick and easy for users to find the splitters pointing to their addresses.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*GdckPckjxVFKnKdrVqxSgQ.png" /></figure><p>The current pricing for a payment splitter is 0.01 ETH, and we didn’t pull this number out of thin air. The amount of gas saved using a clone of an existing splitter implementation is roughly 300,000. At 50gwei, that’s 0.015 ETH, so using payment splitter will save you money on deployment as long as gas prices are above that threshold.</p><p>Use cases:</p><ul><li>NFT drops</li><li>OpenSea royalties</li><li>Any project with multiple independent contributors</li></ul><p>Why you should use it:</p><ul><li>Adding a copy of payment splitter into your existing contract increases contract size. This pushes you up towards the contract size limit, reduces free space for business logic, and increases gas deploy costs. Instead of paying to redeploy this simple logic, why not use an existing on-chain template?</li><li>Adding payment splitter into your existing contract is difficult for untrained operator to use to get their payout<br> Sometimes you want to securely split funds, but you can only give one address (i.e. OpenSea royalty payouts), and existing solutions (a multi sig wallet) require coordination.</li><li>If you have multiple streams of income from many different projects, each with their own payout mechanism, it can become difficult to manage</li></ul><p>The payment splitter implementation we started with comes from OpenZeppelin’s contract library. We have made it cloneable and added in a handful of view functions to help with off chain reporting, but beyond that we have not changed the functional properties of the contract. The cloneable pattern we follow comes from <a href="https://eips.ethereum.org/EIPS/eip-1167">EIP-1167</a>.</p><p>Cloneable contracts cannot use arguments in their constructors. The existing OpenZeppelin contract uses the constructor to initialize the splitter; we have moved this initialization into a separate function.</p><p>Each new splitter created through the manager is registered in the contract, which keeps a record of which payment splitters are pointed at which accounts, allowing for quick lookup of existing splitters.</p><p>In V1 of PaymentSplitterManager, there are a few limitations:</p><ul><li>Non-upgradeable. For the sake of quickly developing a version 1, we have forsaken upgradeability in both the manager and the template contract.</li><li>Cannot handle ERC20 tokens. Any ERC20 tokens sent to a splitter will be lost.</li><li>Cannot handle ERC721 tokens. If implemented properly, safeTransfer will revert, as the splitters do not implement onERC721Recieved. Otherwise, any ERC721 tokens sent to a splitter will be lost. Additionally, we ask: how does one split up a non-fungible good?</li></ul><p>We hope this tool will help artists and creators save gas on deployment, organize royalties, and route payments effectively. We can’t wait to hear your thoughts and we’re looking forward to feedback on how we can improve this tool in the future. Set up a PaymentSplitter today!</p><p>Ethereum Mainnet: <a href="https://paymentsplitter.io/">paymentsplitter.io</a></p><p>Mainnet Verified Contract: <a href="https://etherscan.io/address/0x965D0952ad0DaA235Eb0dba933A061d288EDae9a#code">0x965D0952ad0DaA235Eb0dba933A061d288EDae9a</a></p><p>Ropsten Testnet: <a href="https://ropsten.paymentsplitter.io/">rospsten.paymentsplitter.io</a></p><p>Ropsten Verified Contract: <a href="https://ropsten.etherscan.io/address/0x613b182cb560380FfeC2Ff903C8155f8502Bd006#code">0x613b182cb560380FfeC2Ff903C8155f8502Bd006</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9b27eccfacd4" width="1" height="1" alt=""><hr><p><a href="https://medium.com/northwest-nfts/announcing-paymentsplitter-io-9b27eccfacd4">Announcing: PaymentSplitter.io</a> was originally published in <a href="https://medium.com/northwest-nfts">Northwest NFTs</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to safely push payments in smart contracts: Nouns DAO and Ethernaut’s King challenge]]></title>
            <link>https://medium.com/northwest-nfts/how-to-safely-push-payments-in-smart-contracts-nouns-dao-and-ethernauts-king-challenge-584feca283d4?source=rss----dbe9ddfc79cf---4</link>
            <guid isPermaLink="false">https://medium.com/p/584feca283d4</guid>
            <category><![CDATA[dapps]]></category>
            <category><![CDATA[hacking]]></category>
            <category><![CDATA[ethereum]]></category>
            <category><![CDATA[ethereum-blockchain]]></category>
            <category><![CDATA[smart-contracts]]></category>
            <dc:creator><![CDATA[Peter Conerly]]></dc:creator>
            <pubDate>Wed, 03 Nov 2021 02:00:20 GMT</pubDate>
            <atom:updated>2021-11-03T02:00:58.934Z</atom:updated>
            <content:encoded><![CDATA[<p>While refreshing <a href="https://nouns.wtf/">Nouns DAO</a> and hoping to snipe a noun for less than 10ETH, I realized that their bidding structure reminded me of <a href="https://ethernaut.openzeppelin.com/level/0x5cECE66f3EB19f7Df3192Ae37C27D96D8396433D">Ethernaut’s King’s challenge</a>. Ethernaut is a hacking wargame on the Ethereum blockchain, and has twenty-five challenges that showcase the potential exploits in ethereum smart contracts. Before you get excited, there’s no exploit on Nouns DAO. If there was I wouldn’t be writing this post, I would be hijacking nouns through an anonymous wallet and a Russian VPN exit node.</p><p>The King challenge hands the user a “King of the hill” contract; users can bid to be the King. When a new user has outbid the previous King, the previous King has the bid sent to them, and the new King is seated. The key to the exploit is that Ethereum’s transfers of payment are not guaranteed to be successful, and King doesn’t handle that case. The King challenge is based on the <a href="http://www.kingoftheether.com/postmortem.html">real-life exploit of King of the Ether</a>.</p><p>How do these contracts work? <a href="https://etherscan.io/address/0xf15a943787014461d94da08ad4040f79cd7c124e#code">NounsAuctionHouse</a> and King follow a similar pattern. Here’s King’s code:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*r_zXn1Bj5Nw_iqWt" /><figcaption>King.sol</figcaption></figure><p>One of the first things I was told about Ethereum smart contract development is that push-payments are dangerous, and a pull-model is preferred. This is good general advice for beginners, but it’s good to understand <em>why</em> pull is favored over push.</p><p>The King challenge is attacked by making a smart contract submit the bid, and then failing on the transfer function. One way to fail the transfer is not to have a valid receive function, by omitting it entirely from the contract or not giving it the correct function interface. This is called the <a href="https://www.bookstack.cn/read/ethereumbook-en/spilt.11.c2a6b48ca6e1e33c.md">Unchecked Call attack</a>.</p><p>The second method to make an incoming transfer fail is with a <a href="https://consensys.github.io/smart-contract-best-practices/known_attacks/#gas-limit-dos-on-a-contract-via-unbounded-operations">gas limit denial of service attack</a> or “gas attack”. When an Ethereum smart contract transfers eth using `<em>call</em>`, there is no default gas limit, and before Solidity v7 the `<em>transfer</em>` and `<em>send</em>` functions also didn’t have default gas limits. A malicious receive function can burn gas with useless transactions: see my solution below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*V16IUVLFa10X_qPT" /><figcaption>KingMeForever.sol</figcaption></figure><p>Sadly, ethernaut’s King validator didn’t recognize my gas attack solution! <a href="https://github.com/OpenZeppelin/ethernaut/pull/288">I’ve submitted a fix to Ethernauts to fix the King validator.</a></p><p>How does <a href="https://etherscan.io/address/0xf15a943787014461d94da08ad4040f79cd7c124e#code">NounsAuctionHouse</a> safely push a bid back to a user?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*J5uJcPvxApmHRk4e" /><figcaption>NounsAuctionHouse.sol, lines 100–136</figcaption></figure><p>NounsAuctionHouse calls `<em>_safeTransferETHWithFallback`</em>, let’s look at that:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*FoOriEbaDZugF3sQ" /><figcaption>NounsAuctionHouse.sol, lines 243–260</figcaption></figure><p>The contract attempts to transfer eth with `<em>call</em>`, and includes a gas limit. If a receive function uses up all 30,000 gas allocated the call fails, and thus a gas limit denial of service attack is neutralized. If the transaction fails for any reason the balance is converted into wrapped ETH and then transferred as an ERC20 token. The NounsAuctionHouse contract authors know they can trust the <a href="https://etherscan.io/address/0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2#code">Wrapped ETH contract</a>. Transferring Wrapped ETH doesn’t actually move ETH, it’s simply an accounting change to a WETH data structure, which is also verified to be safe.</p><p>One remaining issue is that if a smart contract won a bid on NounsAuctionHouse, but then was out-bid, there’s a potential problem. If the smart contract’s receive function failed, NounsAuctionHouse would transfer them WETH tokens via ERC20. If the smart contract wasn’t set up to call the Wrapped ETH’s contract’s `<em>withdraw()</em>` function, their refunded bid would be unrecoverable.</p><p>OpenZeppelin’s advice to <a href="https://blog.openzeppelin.com/onward-with-ethereum-smart-contract-security-97a827e47702/?highlight=%22Favor%20pull%20over%20push%20payments%22#:~:text=via%20Function%20Modifiers-,Favor%20pull%20over%20push%C2%A0payments,-Every%20Ether%20transfer">favor pull over push</a> is still relevant today, but pushing can be done safely if needed by contract.</p><p>If you are working on an NFT project and need smart contract or web development support, contact us at <a href="https://northwestnfts.com/">NorthwestNFTs.com</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=584feca283d4" width="1" height="1" alt=""><hr><p><a href="https://medium.com/northwest-nfts/how-to-safely-push-payments-in-smart-contracts-nouns-dao-and-ethernauts-king-challenge-584feca283d4">How to safely push payments in smart contracts: Nouns DAO and Ethernaut’s King challenge</a> was originally published in <a href="https://medium.com/northwest-nfts">Northwest NFTs</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Why you should auction your NFT]]></title>
            <link>https://medium.com/northwest-nfts/why-you-should-auction-your-nft-33638e1c160d?source=rss----dbe9ddfc79cf---4</link>
            <guid isPermaLink="false">https://medium.com/p/33638e1c160d</guid>
            <category><![CDATA[smart-contracts]]></category>
            <category><![CDATA[nft]]></category>
            <category><![CDATA[economics]]></category>
            <category><![CDATA[non-fungible-tokens]]></category>
            <category><![CDATA[ethereum]]></category>
            <dc:creator><![CDATA[Peter Conerly]]></dc:creator>
            <pubDate>Fri, 15 Oct 2021 20:58:14 GMT</pubDate>
            <atom:updated>2021-10-15T20:57:59.654Z</atom:updated>
            <content:encoded><![CDATA[<p>NFT creators are leaving money on the table, and it’s in the millions.</p><figure><img alt="Auctioneer with Mekas" src="https://cdn-images-1.medium.com/max/1024/1*84nkxjgs4yVfPYz27Wx0YQ.png" /></figure><p><a href="https://themekaverse.com/">MekaVerse</a> had a free-to-enter raffle to buy Mekas on October 7th, with a mint price of 0.2 ETH. Hours after the sale opened, Mekas were selling on <a href="https://opensea.io/collection/mekaverse">OpenSea </a>with a floor price for 5 ETH. Now, five days later, the floor price is 6 ETH. The profit for flipping one Meka would be $17k. The potential profit in flipping all 8,888 Mekas at 5 ETH is 42,662 ETH, or $151 million dollars at today’s exchange rate.</p><p>Who profited from this? One tweet suggests that it’s largely botters. I know that my friend and I both failed to win the raffle with our single entries.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/601/1*T20abScc7icGfsrHgue2XQ.png" /></figure><p>What if the MekaVerse team could have captured that profit without harming their users? $100 million dollars goes far in funding a roadmap.</p><p>NFTs, or non-fungible tokens, have been exploding in popularity in the last year. Artists have a new avenue to access their fans and are selling unique digital art pieces for cryptocurrency. The most common sales of NFTs have been straight-forward sales: a set amount at a set price. After the sale is over and the NFT images have been revealed, the secondary market explodes. Flippers flip, collectors collect, but prices can go up two to ten times more than what they were sold for.</p><p>If you’re getting ready to release your NFT, and you think you’re going to sell out, you should consider an auction. If you think that your NFT won’t sell out, or you plan on selling over a long period of time, then an auction probably isn’t right for you. Let’s dive into the gritty details of auctions.</p><p><a href="https://www.nobelprize.org/prizes/economic-sciences/2020/press-release/">The 2020 Nobel Prize of Economics</a> was given to Paul Milgrom and Robert B. Wilson for their research into auctions. Milgrom created a new form of auction for simultaneously auctioning different regions of telephone providers, but they both worked on the fundamental economics of auctions.</p><p>First, there are<a href="https://www.econlib.org/library/Enc/Auctions.html"> four fundamental types of auctions</a>:</p><ul><li>English auction — Bidding starts at a price, and bidders successively raise bids until there’s only one bidder standing. This is the kind of auction used on ebay.</li><li>Dutch auctions — the price starts high, and the auctioneer lowers the price periodically. The first bidder wins.</li><li>Sealed bid auction — this auction can be done asynchronously, with the auctioneer collecting sealed bids over a period of time. The highest bid wins.</li><li>Vickery auction (or “Sealed second-price auction”) — A sealed bid auction like the previous type, but the winner pays the second-highest price. In a multi-unit auction, the winners would pay the highest loser’s price.</li></ul><p>What Milgrom and Wilson discovered is that some auction formats suffer more from <a href="https://en.wikipedia.org/wiki/Winner%27s_curse">Winner’s Curse</a>. Winner’s curse is the tendency for a winning bidder to have overpaid for the item they won. If a winning bidder paid more than what other bidders would pay, the winning bidder may question if they valued the item correctly.</p><p>In the English auction, bidders receive information from when the other bidders drop out. The winning bidder also doesn’t have to pay above the second-highest bidder much, they simply pay one more increment, as set by the auctioneer, above the second-highest.</p><p>The Dutch auction suffers harshly from winner’s curse, because bidders don’t learn when other bidders would drop out and they potentially pay far more than other bidders would have bid. Robert B. Wilson’s takeway was that the Dutch auction and Sealed bid auctions suffer equivalently from winner’s curse. In order to correct for that, cunning bidders have to intentionally bid low in order to avoid winner’s curse. Similarly, English auction and Vickery auctions have the same qualities in regards to winner’s curse: bidders can bid their true estimated value without worrying about overpaying.</p><p>We’ve seen single-item auctions being used in the NFT world already. <a href="https://nft.btmusic.com/">BT’s Metaversal album</a> was auctioned off by track, and <a href="https://nouns.wtf/">Nouns.wtf</a> is auctioning off one noun a day. But how would auctions be used for a multi-item sale of unrevealed NFTs?</p><p>First, using an auction would eliminate scalpers and short-term flippers. Since the auction price is set by the market, there is no profit to be made in the short term. Fans and long-term investors will be able to win their NFTs from the first sale.</p><p>Ideally NFTs would be bid with an English auction with Vickery rules for the selling price. Users would submit their bid over a period of time, and the selling price would be the highest losing bid. This avoids users overpaying — bidders are paying exactly the amount they would have had to bid to win — and then allows people to bid their true estimated value.</p><p>It is important to actually take the cryptocurrency being bid, otherwise the auction risks having an inflated selling price from being tampered with by false bidders.</p><p>At the close of bidding, the sale price would be set. Winning bidders would be given their NFTs and the bid amount in excess of the sale price would be refunded. Losing bidders would have their money refunded. There’s also potential for allowing winning bidders to buy multiple NFTs at the sale price.</p><p>An objection to the auction format is that users would have to pay a higher price. It’s true: the price would be increased. However, the settled auction price would closely match the immediate price on the secondary markets. With that being the case, scalpers would have nothing to gain from the arbitrage. Scalpers might try to come in early at low bids, but the winning bidders would be genuine fans and long-term investors: the people who would have bought the NFTs on the secondary markets anyway. The NFT creator will hopefully make more ETH with an auction and can give back to their NFT-holders with more content, benefits in future NFT drops, or cryptocurrency giveaways.</p><p>There are some ethereum-specific factors to consider with this auction format. Gas is expensive, and returning the crypto of losing bids and excess winning bidders could be costly for the auctioneer. I plan to lay out the smart contract of an English-Vickery multi-item auction in a future blog post.</p><p>Hopefully I’ve convinced you that using an auction format, and a fair auction format, will give you and your users the best outcome.</p><p>If you are working on an NFT project and need smart contract or web development support, contact us at <a href="https://northwestnfts.com/">NorthwestNFTs.com</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=33638e1c160d" width="1" height="1" alt=""><hr><p><a href="https://medium.com/northwest-nfts/why-you-should-auction-your-nft-33638e1c160d">Why you should auction your NFT</a> was originally published in <a href="https://medium.com/northwest-nfts">Northwest NFTs</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Bored Ape Yacht Club: Contract Review]]></title>
            <link>https://medium.com/northwest-nfts/bored-ape-yacht-club-contract-review-80dce503308e?source=rss----dbe9ddfc79cf---4</link>
            <guid isPermaLink="false">https://medium.com/p/80dce503308e</guid>
            <category><![CDATA[smart-contracts]]></category>
            <category><![CDATA[nft]]></category>
            <category><![CDATA[solidity]]></category>
            <category><![CDATA[ethereum]]></category>
            <category><![CDATA[nonfungible-tokens]]></category>
            <dc:creator><![CDATA[Patrick Price]]></dc:creator>
            <pubDate>Thu, 07 Oct 2021 00:37:49 GMT</pubDate>
            <atom:updated>2021-10-07T00:37:49.059Z</atom:updated>
            <content:encoded><![CDATA[<p>Today we’re going to review the smart contract code for the very successful virtual art drop <a href="https://boredapeyachtclub.com/">Bored Ape Yacht Club</a>. Non-fungible tokens are the hottest new thing right now, with drops of large sets of images raking in millions of dollars, selling out in minutes. One example of these large set NFTs is the Bored Ape Yacht Club. Assuming these tokens are mostly being purchased by lazy crypto millionaires, I think the name is pretty spot on. Each one of these bad monks sold for an initial 0.08 ETH, and the floor price currently on <a href="https://opensea.io/collection/boredapeyachtclub">Opensea</a> is a solid 40 ETH. That’s a pretty good ROI, and it’s obvious why people are jumping into this space in droves looking for similar returns.</p><p>When I see numbers like this, I wonder whether the BAYC team has set any aside for themselves. With all the money they earned on the initial minting of 10,000 of their tokens, they can afford to buy 20 of those spicy monks back. I’m sure the BAYC team purchased some of their own art during the sale, but are there any reserved apes in the contract? Two free apes for every member of the team would be a fat bonus (~$300,000.) Let’s take a look.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*RHnyAX_utvYFM2DG" /></figure><p>We take our first peek at the Etherscan page for the BAYC token, and thank god! The green check is there, they have verified their contract code and we don’t have to mess around with a decompiler.</p><p>Clicking on the “contract” tab, we can see the name of the contract and all of its build settings. The first thing that catches my eye is the “Optimization Enabled” section. The BAYC team decided not to optimize this contract before deployment. Non-optimized contracts build faster for developers, which creates a more seamless experience when you’re writing code, but they burn more gas. When you are deploying smart contracts to the main Ethereum network, you should always optimize your contracts.</p><p>Before reviewing the code of a smart contract, I like to take a look at the public views of a contract. These fields are easily accessible functions that tell us something about the current state of the contract. We can find all the public views of a contract under the “Read Contract” tab in the “Contract” section:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/474/0*Pcy3IPKQCniX_YNT" /></figure><p>The first three values we see are BAYC_PROVENANCE, MAX_APES, and REVEAL_TIMESTAMP. They have been assigned names in all caps with underscores, which according to the Solidity style guide, suggests they are constants. These are a good set of constants, because they suggest a fixed image set that will be revealed at a given time. One of the many problems associated with owning digital art is the problem associated with verification. How do I verify that this art is what I paid for? The provenance hash is a unique signature that can be created from any set of images, with it you can verify that the images that the artists will later reveal (presumably at REVEAL_TIMESTAMP), are the same images that you purchased. It also solves the problem of later tampering; the host of the image set cannot change the images, or else the signature will change. MAX_APES simply suggests that this image set is of a fixed size: 10,000.</p><p>Looking down the list we see the expected ERC-721 standard views and some custom views. <em>apePrice </em>and <em>saleIsActive </em>are self apparent, and <em>maxApePurchase </em>looks like either the maximum number of apes a single address can purchase, or the maximum apes you can purchase in a single transaction. <em>startingIndex </em>and <em>startingIndexBlock </em>are more mysterious, but we’ll see what they do eventually.</p><p>Now let’s look at the writeable fields of the contract:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/501/0*jg4wj89XUkKdZQ3R" /></figure><p>Woah! Emergency! Something has gone very wrong and needs to be reset in the starting index block! Now I’m very intrigued about this <em>startingIndexBlock</em>. It seems to be critically important, and very fragile!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/243/0*6-jxwSBUs5rcnqdu" /></figure><p>I guess that answers my earlier curiosity, now it comes down to how many they reserved.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/287/0*RNGHpZMn_9bPUC_l" /></figure><p>Huh, this smells fishy. I was under the impression that the provenance hash and the reveal timestamp were constant, but here are their setters. Maybe you can only set them once? Lockable fields aren’t really implemented by default in Solidity and it makes sense that you might want to set these fields after deploying the contract, so let’s give this a pass for now and we’ll see how things shake out in the code.</p><p>Over to the code, we see it’s a big ol’ flat file. I love that, because you can check all the imported standard templates as you scroll to the bottom. This contract implements IERC165, which is an interface (thus the I), that allows contracts to signal to other contracts what functions they expose. The only function required for a contract to meet the ERC165 standard is <em>supportsInterface</em>, which takes in a 4 byte interface ID, and returns a boolean yes/no answer as to whether the contract has that interface. This contract also implements the ERC721 interface, which is the standard interface for NFTs and defines a set of functions to transfer ownership of the tokens and allow verified auctions and market-houses to manage and sell products for holders. Specifically, this contract implements the ERC721Enumerable extension of the ERC721 standard which adds a powerful set of functions to track which tokens are owned by who.</p><p>After our quick trip through all those beautiful OpenZeppelin imports, it’s time to look at some monkey code.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/789/0*7zz0lP3povOclWx0" /></figure><p>I’m going to be a little nitpicky here, but it seems pretty silly to do any kind of unnecessary math in your constructor like this. They’re setting the reveal timestamp to 9 days after <em>saleStart</em>, and they’re calculating that timestamp for 9 days after <em>saleStart </em>on the blockchain. They might as well have passed in the reveal timestamp, they’re not using <em>saleStart </em>anywhere. Admittedly, if I just made $2.5 million, I wouldn’t mind giving some change to miners.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/320/0*Q8HJdSGteERhs5XW" /></figure><p>This answers the reserve question. The owner of this contract can mint 30 apes whenever they want, just pay the gas fees. I guess they probably only pushed this button once or twice, but with the apes at their current price, pushing that button creates $3.5 million.</p><p>This function does not check the current number of tokens against the MAX_APES we looked at above. That means the owner of this contract will be able to mint more apes for as long as they please. They might need to start drawing some more apes, but they can add as many tokens as they want. I for one, would pay top dollar for BAYC # 10,017. It’s not hard to add checks in that prevent the owner of a contract from breaking all the rules they set for their customers, and not adding in those checks leaves the door open for potential abuse. Even if you trust the group currently in control of this contract, do you trust them to manage their keys?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/512/0*Z80ZX46FpTK7Hkgn" /><figcaption>Hi Gargamel!</figcaption></figure><p>Unfortunately we’ve found the setters for those “constants.” The reveal timestamp and provenance hash can be set whenever by the contract owner. This is unfortunate, because it totally undermines the point of the provenance hash. Because this setter does not lock, there is no guarantee against future tampering by the owner of the contract.</p><p>Imagine you’re signing a contract, you agree to hand over 10000 pictures of monkeys, and you sign in pencil. 10000 people sign the contract in pen, give you your smooth $2.5 mil, and you walk off with the contract in your hand, and all the pictures too.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/863/0*54KBP0gr7vm5nD4t" /></figure><p>We found our mint function: this is where users can pay to create the tokens. We learn the meaning of <em>maxApePurchase</em>, it’s the number of apes a user can buy at one time. Checks like this are good in multi-mint functions because minting ERC721Enumerable tokens is expensive and minting many of them at once can quickly hit gas limits.</p><p>At the end of this mint function, we start to get a sense of what <em>startingIndexBlock </em>is. The starting index block is going to begin uninitialized, set to 0. In <em>mintApe</em>’s final if statement, the mint function will check if it’s sold out, or if the current time is after REVEAL_TIMESTAMP. If they are sold out or after the reveal, the contract is going to set the starting index block to the current block number (each block in the blockchain gets an ID number). This is about as close to a random number as you can get on the blockchain, and I wonder what they’re going to do with that value, “<em>startingIndexBlock</em>.”</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/777/0*udNAoHZSdIimL7P1" /></figure><p>Here is where <em>statingIndexBlock </em>is used. The contract is going to use it to set up <em>startingIndex</em>. The starting index is a number that must not be set for this function to be called, so the contract can only set the starting index one time. This is a great example of a locking field. There’s more in the comments here about sanity and preventing the “default sequence”, but we’re getting to the end of the contract and I can tell that none of this stuff is going to matter.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/505/0*wpnSX5uDFHCBHVMD" /><figcaption>Just in case you weren’t happy with the random number you got</figcaption></figure><p>Here it is, the last function of the code, the emergency for when someone minted at the wrong time and the random starting index block got set wrong. You really don’t want someone to set your <em>startingIndexBlock </em>wrong, because you may enter into the “default sequence”, or potentially lose your sanity.</p><p>These functions are ancillary and have no actual influence! The <em>startingIndex </em>value is never reused in the contract, and thus it has no effect on anything. Why would the BAYC team leave these pointless functions in their code? After reviewing the BAYC page on provenance, we can learn the intention behind these values.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/769/0*iWxIM7oR7i7WsM_X" /></figure><p>They are trying to randomize the tokens so that nobody knowns the order of IDs, and people with early access to the art set can’t “snipe” the rare tokens by purchasing many close to the indices of know rare tokens. This math is pretty simple, and the BAYC team failed to actualize it in their contract. At no point in time does an “Initial Sequence Index” exist. This could be implemented, by overriding the <em>tokenURI</em> function to point the tokens to the new index, but that is not implemented in this contract.</p><p>Looking around at other NFT contracts, many of them have the same copy-pasted functions. It’s evident these authors are blindly copying success, without understanding the things they use.</p><p>Lets overview the problems with this contract:</p><ul><li>Claiming tokens reserved for the contract owner needs more checks to prevent owner abuse</li><li>The provenance hash cannot be locked, which means the owner can tamper with the image set</li><li>The starting index isn’t hooked in anywhere, and so it and all the functions supporting it are useless. This means that the Bored Ape tokens were not dealt out randomly, despites the claims on the BAYC website!</li></ul><p>Realistically, I don’t think sniping is much of an issue with these NFT drops because the image sets are not usually known ahead of time. Having the <em>startingIndex </em>ancillary code only costs the BAYC team more money on deployment.</p><p>I think the key problems are the unlocked provenance hash and the open <em>reserveApes</em>. These fields should not be available and leaving them available undermines the entire agreement the contract is put in place to uphold. The safest thing to do would be to pass ownership of this contract to a shell contract that hides these fields, locking them. Alternatively, the owner could renounce ownership of the contract. At this point, most of the fields in the contract would be locked forever, and locking the <em>baseURI</em> field poses some potential problems regarding long term image hosting.</p><p>In our next blog post we will make some minor changes to the contract and see how much gas we can save. After that we will take a closer look at why the <em>startingIndex</em> logic, even if it was properly implemented, does not effectively solve the problems it claims to solve, and we will take a look at a contract with a much better implementation.</p><p>If you are working on an NFT project and need smart contract or web development support, contact us at <a href="https://northwestnfts.com/">NorthwestNFTs.com</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=80dce503308e" width="1" height="1" alt=""><hr><p><a href="https://medium.com/northwest-nfts/bored-ape-yacht-club-contract-review-80dce503308e">Bored Ape Yacht Club: Contract Review</a> was originally published in <a href="https://medium.com/northwest-nfts">Northwest NFTs</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>