{"id":492,"date":"2023-03-17T17:39:49","date_gmt":"2023-03-17T15:39:49","guid":{"rendered":"https:\/\/ackeeblockchain.com\/blog\/?p=492"},"modified":"2024-05-16T13:16:57","modified_gmt":"2024-05-16T11:16:57","slug":"how-to-prepare-for-a-smart-contract-audit-2","status":"publish","type":"post","link":"https:\/\/ackee.xyz\/blog\/how-to-prepare-for-a-smart-contract-audit-2\/","title":{"rendered":"How to prepare for a smart contract audit"},"content":{"rendered":"<p><em>At first sight, auditors are here to help developers create safer smart contracts. However, more cooperation between both sides can help reduce audit costs and increase the chance of discovering more severe issues. The pre-audit part is essential for a smooth audit, and we will now guide you through it.\u00a0<\/em><\/p>\n<h4><b>Preparing for an audit<\/b><\/h4>\n<p><span style=\"font-weight: 400;\">First, a correctly scheduled <strong>time pipeline<\/strong> will help to avoid many difficulties. Suppose you are still building and considering an audit in the future. In that case, you\u2019d better <strong>discuss it in advance<\/strong>, as during the audit, the <strong>codebase needs to be frozen<\/strong> and be almost <strong>production ready<\/strong> at a specific commit. The reason is: after the audit, fixes can only be made to ensure maximum safety.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">In addition, take into account the importance of the audit scope. If it is not a full-repository audit, the scope should be clearly specified: enumerate all the contracts that should be audited and those that should be taken as a black box<\/span><span style=\"font-weight: 400;\">.<\/span><\/p>\n<p><b><img loading=\"lazy\" decoding=\"async\" class=\"size-medium wp-image-485 aligncenter\" src=\"https:\/\/abchprod.wpengine.com\/wp-content\/uploads\/2023\/03\/Picture-1-222x300.png\" alt=\"\" width=\"222\" height=\"300\" srcset=\"https:\/\/ackee.xyz\/blog\/wp-content\/uploads\/2023\/03\/Picture-1-222x300.png 222w, https:\/\/ackee.xyz\/blog\/wp-content\/uploads\/2023\/03\/Picture-1-370x500.png 370w, https:\/\/ackee.xyz\/blog\/wp-content\/uploads\/2023\/03\/Picture-1.png 644w\" sizes=\"auto, (max-width: 222px) 100vw, 222px\" \/><\/b><\/p>\n<p><span style=\"font-weight: 400;\">Another important part is the <strong>project&#8217;s readability<\/strong>. Ideally, the code should be continuously documented during the development process resulting in <strong>comprehensive documentation<\/strong>. Complex code parts should be <strong>documented inline<\/strong>, and it is recommended to use <\/span><a href=\"https:\/\/docs.soliditylang.org\/en\/v0.8.17\/natspec-format.html\" target=\"_blank\" rel=\"noopener\"><span style=\"font-weight: 400;\">NatSpec<\/span><\/a><span style=\"font-weight: 400;\"> format across the codebase in its full range (params, return values, \u2026). Architecture <strong>graphs<\/strong>, project <strong>flows<\/strong>, and functional <strong>requirements<\/strong> alongside low-level <strong>documentation<\/strong> are also extremely useful. A <strong>whitepaper<\/strong> and video <strong>walkthrough<\/strong> through the codebase are vital for auditors. The last but not the least is compliance with<\/span> <a href=\"https:\/\/docs.soliditylang.org\/en\/v0.8.17\/style-guide.html\" target=\"_blank\" rel=\"noopener\"><span style=\"font-weight: 400;\">Solidity Style Guide<\/span><\/a><span style=\"font-weight: 400;\"> and Solidity linters usage. These steps will help to significantly speed up the onboarding process for third-party auditors.<\/span><\/p>\n<h4>Maximizing<b>\u00a0the audit output<\/b><\/h4>\n<p><span style=\"font-weight: 400;\">It is important that the project you want to be audited <strong>can be compiled<\/strong>. Auditors are deploying projects on <strong>local development chains<\/strong> to ensure correct <strong>functionality<\/strong> and to <strong>test<\/strong> various <strong>exploits<\/strong>. That\u2019s why extensive <strong>test suite<\/strong> with various <strong>mocks<\/strong> are also very helpful. Moreover, these tests can discover <strong>bugs<\/strong>; <strong>more bug<\/strong>s in the report result in <strong>more overhead<\/strong>. Thus, the audit <strong>output<\/strong> can be l<strong>ess confident<\/strong> because there is <strong>less time<\/strong> to check the rest of the project. Therefore, <strong>writing<\/strong> <strong>as many tests as possible<\/strong> to ensure the full coverage <strong>is strongly recommended.<\/strong>\u00a0<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Extending the <strong>unit<\/strong> and <strong>integration tests<\/strong> with <strong>property-based fuzz tests<\/strong> is a master move and will help you a lot. If you think that fuzz tests writing is challenging, let us tell you this: it is not.<\/span><\/p>\n<h4><b><img loading=\"lazy\" decoding=\"async\" class=\"size-medium wp-image-486 aligncenter\" src=\"https:\/\/abchprod.wpengine.com\/wp-content\/uploads\/2023\/03\/Picture-2-300x297.png\" alt=\"\" width=\"300\" height=\"297\" srcset=\"https:\/\/ackee.xyz\/blog\/wp-content\/uploads\/2023\/03\/Picture-2-300x297.png 300w, https:\/\/ackee.xyz\/blog\/wp-content\/uploads\/2023\/03\/Picture-2-1024x1013.png 1024w, https:\/\/ackee.xyz\/blog\/wp-content\/uploads\/2023\/03\/Picture-2-150x150.png 150w, https:\/\/ackee.xyz\/blog\/wp-content\/uploads\/2023\/03\/Picture-2-768x760.png 768w, https:\/\/ackee.xyz\/blog\/wp-content\/uploads\/2023\/03\/Picture-2-370x366.png 370w, https:\/\/ackee.xyz\/blog\/wp-content\/uploads\/2023\/03\/Picture-2-90x90.png 90w, https:\/\/ackee.xyz\/blog\/wp-content\/uploads\/2023\/03\/Picture-2-760x752.png 760w, https:\/\/ackee.xyz\/blog\/wp-content\/uploads\/2023\/03\/Picture-2.png 1092w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/b><\/h4>\n<h4><b>May the tooling be with you<\/b><\/h4>\n<p><span style=\"font-weight: 400;\">It is 2023, and testing frameworks like <strong>Foundry<\/strong> and <a title=\"Woke, development &amp; testing framework for Solidity\" href=\"https:\/\/ackeeblockchain.com\/blog\/woke-our-development-and-testing-framework-for-solidity\/\"><strong>Wake<\/strong><\/a> are at your service. <\/span><a href=\"https:\/\/github.com\/foundry-rs\/foundry\" target=\"_blank\" rel=\"noopener\"><span style=\"font-weight: 400;\">Foundry<\/span><\/a><span style=\"font-weight: 400;\"> is for Solidity fans; <\/span><a href=\"https:\/\/ackeeblockchain.com\/woke\/docs\/latest\/testing-framework\/fuzzing\"><span style=\"font-weight: 400;\">Wake<\/span><\/a><span style=\"font-weight: 400;\"> is written in <strong>Python<\/strong>, so it is more practical in some ways, like <strong>differential fuzzing<\/strong> of math libraries\/operations, it has plenty of helpful Python packages, easy-to-write tests for anyone, and much more.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">The following discipline is a <strong>static analysis<\/strong>. Easy to run, and outputs are easy to understand and fix. We would single out two possibilities: <\/span><a href=\"https:\/\/github.com\/crytic\/slither\" target=\"_blank\" rel=\"noopener\"><span style=\"font-weight: 400;\">Slither<\/span><\/a><span style=\"font-weight: 400;\"> and <\/span><a href=\"https:\/\/ackeeblockchain.com\/woke\/docs\/latest\/detectors\/\"><span style=\"font-weight: 400;\">Wake<\/span><\/a><span style=\"font-weight: 400;\">. Slither has a <strong>wide range<\/strong> of detectors with many <strong>false positives<\/strong>; on the other hand, Woke has f<strong>ewer detectors<\/strong>, but they are usually <strong>more relevant<\/strong>. Both tools are <strong>configurable<\/strong>, for example, to suppress some detections to make it more convenient for reviews. Each audit starts with a <strong>static analysis<\/strong>, so if you perform it before the audit, it <strong>can save you some time<\/strong>.<\/span><\/p>\n<h4><b>Final remarks<\/b><\/h4>\n<p><span style=\"font-weight: 400;\">If you followed the recommendations from the previous paragraphs, your project should now be <strong>ready for an audit.<\/strong> Remember to give the auditors <strong>previous audit reports<\/strong> (if any). It will be really helpful.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">For your convenience, check the <strong>pre-audit checklist below:<\/strong>\u00a0<\/span><\/p>\n<h4><b>Pre-audit checklist<\/b><\/h4>\n<p><span style=\"font-weight: 400;\">The more points from the following list you accomplish, the more valuable audit you will get.<\/span><\/p>\n<p><strong>Your project:<\/strong><\/p>\n<ul>\n<li><span style=\"font-weight: 400;\">is ready to be frozen for the auditing period<\/span><\/li>\n<li><span style=\"font-weight: 400;\">is compilable<\/span><\/li>\n<li><span style=\"font-weight: 400;\">is accessible for the auditors from day 1<\/span><\/li>\n<li><span style=\"font-weight: 400;\">contains full NatSpec documentation<\/span><\/li>\n<li><span style=\"font-weight: 400;\">has comprehensive technical documentation<\/span><\/li>\n<li><span style=\"font-weight: 400;\">has a walkthrough video for auditors<\/span><\/li>\n<li><span style=\"font-weight: 400;\">follows Solidity Style Guide<\/span><\/li>\n<li><span style=\"font-weight: 400;\">contains an extensive test suite<\/span><\/li>\n<li><span style=\"font-weight: 400;\">passed a static analysis<\/span><\/li>\n<li><span style=\"font-weight: 400;\">has past audit reports<\/span><\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>At first sight, auditors are here to help developers create safer smart contracts. However, more cooperation between both sides can help reduce audit costs and increase the chance of discovering more severe issues. The pre-audit part is essential for a smooth audit, and we will now guide you through it.\u00a0 Preparing for an audit First, a correctly scheduled time pipeline will help&hellip;<\/p>\n","protected":false},"author":6,"featured_media":488,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[61,10,80,103],"tags":[87,24,88],"class_list":["post-492","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-education","category-ethereum","category-solidity","category-wake","tag-education","tag-ethereum","tag-how-to"],"aioseo_notices":[],"featured_image_src":"https:\/\/ackee.xyz\/blog\/wp-content\/uploads\/2023\/03\/Prepare-for-audits-600x400.png","featured_image_src_square":"https:\/\/ackee.xyz\/blog\/wp-content\/uploads\/2023\/03\/Prepare-for-audits-600x600.png","author_info":{"display_name":"Jan Kalivoda","author_link":"https:\/\/ackee.xyz\/blog\/author\/jan-kalivoda\/"},"_links":{"self":[{"href":"https:\/\/ackee.xyz\/blog\/wp-json\/wp\/v2\/posts\/492","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ackee.xyz\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ackee.xyz\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ackee.xyz\/blog\/wp-json\/wp\/v2\/users\/6"}],"replies":[{"embeddable":true,"href":"https:\/\/ackee.xyz\/blog\/wp-json\/wp\/v2\/comments?post=492"}],"version-history":[{"count":0,"href":"https:\/\/ackee.xyz\/blog\/wp-json\/wp\/v2\/posts\/492\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/ackee.xyz\/blog\/wp-json\/wp\/v2\/media\/488"}],"wp:attachment":[{"href":"https:\/\/ackee.xyz\/blog\/wp-json\/wp\/v2\/media?parent=492"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ackee.xyz\/blog\/wp-json\/wp\/v2\/categories?post=492"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ackee.xyz\/blog\/wp-json\/wp\/v2\/tags?post=492"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}