ByAUJay
How to Audit Your Own Code Before Sending it to a Firm
Auditing your own code before handing it over to a firm is a smart move. It not only ensures that your work is solid but also saves time during the review process. Here’s a simple guide to help you walk through the steps.
1. Review Code for Style Consistency
Make sure your code follows a consistent style. This includes:
- Naming conventions: Use meaningful names for functions and variables.
- Indentation: Ensure that your indentation is uniform throughout the code.
- Commenting: Add comments where necessary to explain complex logic.
2. Check for Functionality
Run tests to verify that your code works as intended. It’s a good idea to:
- Write unit tests to cover key functionalities.
- Use automated testing tools if available.
- Manually test edge cases that might break the code.
3. Optimize Performance
Look for areas where your code can be more efficient. Here are some tips:
- Identify slow sections: Use profiling tools to find bottlenecks.
- Refactor: Simplify code wherever possible.
- Consider alternative algorithms: Sometimes a different approach can lead to better performance.
4. Ensure Security Practices
Don’t overlook security! Make sure to:
- Validate all inputs to prevent injection attacks.
- Remove any sensitive data before sharing the code.
- Use libraries and frameworks that are known for their security.
5. Document Your Code
Good documentation makes it easier for others (and future you) to understand your work. Include:
- A README file explaining the project and how to set it up.
- Inline comments for complex parts of the code.
- API documentation if applicable.
6. Get a Fresh Set of Eyes
Before you send it off, consider getting someone else to look at your code. A fresh perspective can catch things you might have missed. Reach out to:
- A colleague
- A friend who knows coding
- An online community for feedback
7. Final Checks
Before you submit your code, do a final review. Check for:
- Typos or syntax errors.
- Unused variables or functions.
- Any lingering TODOs or FIXMEs in your code.
By following these steps, you’ll be well on your way to ensuring that your code is polished and ready to impress! Good luck!
Pain (the specific headache you’re likely feeling)
- So, you booked that fancy external audit window, but guess what? Your codebase isn't quite "audit-ready." Foundry tests might be green, but coverage is only partial, invariants are a bit vague, upgrade safety isn’t proven, and your ZK circuits could be a tad underconstrained. The auditors are probably going to spend the first week or two just trying to get your repo in order and replaying your environment instead of actually hunting for bugs.
- On top of that, Ethereum’s changes coming up in 2025-2026 have shaken things up with compiler defaults and gas economics. Solidity 0.8.30 switched the default EVM target to Prague for Pectra, then 0.8.31+ started leaning towards Osaka and began deprecating stuff--like
send/transfer, ABI coder v1, and more. Oh, and don’t forget that 0.8.32/0.8.33 patched a pesky storage-array bug. If you’re still working with older setups, you might get caught off guard by failing builds, unexpected behavior, or mispriced calldata. (soliditylang.org) - And let’s not overlook Pectra, which raised the floor price of calldata (EIP‑7623). If your deployment or bridging patterns are still sending large batches of bytes, brace yourself for some bill shock or changes in throughput; rollup data pipelines should be blob-first after Dencun. Pectra officially went live on May 7, 2025 (epoch 364032). (blog.ethereum.org)
Agitation (the business risk if you ignore it)
- Missed audit windows: If your repositories can't pass reproducible builds, baseline static checks, or if they have unclear specification boundaries, auditors won’t hesitate to bounce them. This can really mess with your timelines, pushing you beyond marketing deadlines and procurement processes--especially when a SOC2 Type II buyer is on your case about traceability, change control, and solid rollback plans. You can read more about this here.
- Budget overrun: Hiring senior auditors to come in and help fix your Continuous Integration (CI) setup, align compiler versions, or sort out invariants is going to drain your budget. You’re looking at spending 2 to 3 times more than if you tackled these issues in-house before even bringing them on board.
- Rework risk: If you don’t have solid property-level specs--like those for access control and funds conservation invariants--you’ll find yourself fixing problems only to have them crop up again during that final gas tuning or when upgrading proxies. This ends up triggering those pesky re-audit cycles.
Solution (7Block Labs’ audit-readiness methodology you can apply now)
Just follow this handy checklist to turn that “works on my machine” mindset into something that’s totally “audit-ready.” Plus, we’ll help you align everything with SOC2 controls and what you need for procurement.
Checklist
- Identify Artifacts: Start by listing all the necessary artifacts you’ll need for your audit.
- Map to SOC2 Controls: Make sure each artifact connects to specific SOC2 controls.
- Document Processes: Keep a clear record of all processes related to your artifacts.
- Review Compliance: Regularly check that everything meets compliance standards.
- Conduct Training: Ensure your team knows what’s expected regarding audit readiness.
- Plan for Updates: Stay on top of any changes in regulations or controls.
With these steps, you’ll be well on your way to becoming audit-ready!
1) Freeze the toolchain, align to current EVM semantics, and de-risk compiler gotchas
- Make sure to pin Solidity to version ≥0.8.33. This way, you'll get that important storage-array write bugfix from versions 0.8.32/0.8.33. If you’ve got any custom storage layouts or are doing any funky array math near slot boundaries, definitely give things a retest. (soliditylang.org)
- If you’re hanging out on versions 0.8.29-0.8.31, take a moment to sanity-check the changes:
- Version 0.8.30 set Prague as the default EVM version to align with Pectra, so you might want to re-benchmark the gas for functions that are heavy on calldata. (soliditylang.org)
- In 0.8.31, Osaka became the default, and there are new deprecations headed towards 0.9.0. Don’t overlook those send/transfer deprecation warnings--consider them as action items before your audit. (forum.soliditylang.org)
- If you’re experimenting with EOF (EVM Object Format) builds, keep in mind it's still a work in progress. Use the experimental flags, brace yourself for a few rough edges, and definitely get the thumbs-up from your auditors before shipping EOF to mainnet. (soliditylang.org)
- Make sure to update your cost models after Pectra: EIP-7623 has raised the effective floor for calldata (10/40 gas per zero/non-zero byte when execution is low compared to data). It’s a good time to shift high-data paths to blobs and consider refactoring constructors and batch calls that are pushing too many bytes. (eips.ethereum.org)
2) Baseline Static Analysis That Auditors Will Expect (and Gate On)
- First off, make sure to run Slither in your continuous integration (CI) setup using a hardened profile and publish those artifacts. It’s a good idea to include specific detectors that tackle common real-world problems, like:
- reentrancy‑eth
- arbitrary‑send‑eth/erc20
- weak‑prng
- tx‑origin
- unchecked‑lowlevel
- out‑of‑order‑retryable (this one's Arbitrum-specific)
- protected‑vars
- unprotected‑upgrade
- encode‑packed‑collision
You can check out Slither here.
- Also, keep an eye on Slither’s “printers” for upgrade safety, which include things like storage layout, inheritance, and the ABI surface. This way, you can spot any accidental exposure early on. You’ll find more about this on the Slither GitHub page.
3) Specify behavior with executable properties (so fuzzers and provers can work for you)
- Use Scribble to add some annotations to your contracts with invariants and postconditions--think things like allowance monotonicity on
transferFrom, supply/balance conservation, or role-gated mutators. This handy tool compiles into Solidity assertions that fuzzers can easily target. Check it out here: (diligence.consensys.io). - Here are some examples that you should definitely consider drafting up before any audit:
- Funds Conservation: “totalAssets equals sum of liabilities ± protocol fees” (ERC‑4626).
- Access Control: “only AccessManager can change critical parameters” (if you’re using OZ AccessManager 5.x). You can read more about it here: (openzeppelin.com).
4) Fuzz and Explore State Space, Not Just Inputs
- With Echidna, you can focus on your Scribble-instrumented properties and whip up call sequences across contracts. Plus, don’t forget to save those corpora and JSON reports as audit artifacts! To keep things running smoothly on your pull requests, just add
echidna-actionin GitHub. Check it out here: github.com. - For some solid protocol-level rules like price invariants, solvency, and fee accrual, consider adding Foundry invariant tests (think runs × depth). These invariants are re-checked after every randomized call sequence. Curious about more? Click here: learnblockchain.cn.
- If you need to dig deeper into path coverage or you’re looking for single-function proofs, think about integrating symbolic execution with Manticore on bytecode. This is especially useful for high-risk routines like settlement and liquidation math. You can find it here: github.com.
- For those mission-critical properties--like governance and accounting--don’t skimp on safety! Add formal rules and run a prover like Certora on every commit. These provers thoroughly check every path, way beyond just random inputs. Learn more at certora.com.
5) Upgrade and Storage Safety (the class that bites during late-stage audits)
- It's a good idea to stick with UUPS using OZ tooling, or go for transparent/beacon when governance calls for it. Make sure to check out any storage layout differences and keep _authorizeUpgrade locked down; it's wise to steer clear of mixing UUPS implementations behind transparent proxies. Check out more info in the OpenZeppelin documentation.
- If you're leaning on post‑Cancun patterns, you'll want to use transient storage (EIP‑1153) locks and take advantage of OZ 5.1 tools like ReentrancyGuardTransient when it makes sense--plus, don't forget to test across forks to ensure everything runs smoothly. For details, visit the Ethereum EIPs page.
6) Gas and Performance Budgets That Auditors Actually Care About
- Keep an eye on gas regressions using Foundry’s built-in snapshots. Commit the
.gas-snapshotand put up some gates on PRs based on tolerance thresholds. This approach helps dodge those last-minute “performance fixes” that could sneak in and create new security issues. Check it out here: (getfoundry.sh). - Create LCOV coverage reports by running
forge coverage --report lcovto gather insights on line, branch, and function coverage. It's super useful to display these reports in your CI or even in VS Code with Coverage Gutters. Just a heads up: inline assembly coverage might not be spot on, so make sure to document any exclusions. More on this can be found here: (blog.gary.gg). - After tackling Pectra, it’s a good idea to re-estimate your calldata-heavy flows. A lot of teams end up finding that constructor and bridge payloads go over the new floor threshold. So, budget for this and refactor your code before the audit to steer clear of any last-minute chaos. For more details, check out: (eips.ethereum.org).
7) ZK Circuit Self-Audit (Circom/Halo2/Noir) Focusing on Common Bug Classes
- Make sure to turn on
circom --inspectto identify those pesky underconstrained signals and spot any mix-ups with<--versus<==in your arithmetic. If you run into warnings, either fix them or provide justification using “_” sinks. You can find more about this in the Circom documentation. - Stick to a tagging routine to dodge issues like arithmetic overflow or bit-width errors. Trail of Bits has some great advice on safe tag patterns and common pitfalls when tagging your internals and outputs. Check it out here: Trail of Bits Blog.
- If your scale allows, consider adding circuit fuzzing or algebraic checkers in your CI. Tools like zkFuzz (which does mutation-guided fuzzing) and AC4 (for algebraic constraint checking) have been known to catch real bugs in Circom and Halo2 circuits. Don't forget to gather those findings and inputs for your auditors! For more details, look at this arXiv paper.
8) Produce an “Audit‑Ready Asset Pack” that accelerates external review
Make sure to send this stuff to your auditor before you kick things off:
- Repo and CI: Include the pinned solc version, your Foundry or Hardhat configuration, deterministic build scripts, and a dockerized repro.
- Risk model: Bring in your threat model, trust assumptions, and protocol invariants; link each one to the Scribble or Certora rules and the invariant tests.
- Static and dynamic artifacts: Share your Slither checklist, Echidna reports, invariant logs, LCOV, gas snapshots, and diff dashboards. (github.com)
- Upgrade plan: Outline the storage layout diffs, explain your choice of proxy types, include a rollback plan, and detail your governance procedures (like admin keys and timelocks). (docs.openzeppelin.com)
- ZK: Provide the circuit specs, constraints index, --inspect output, tagged-signal libraries, and fuzz/algebra logs. (docs.circom.io)
- Compliance and procurement: Map out the SOC2 Trust Services Criteria (covering risk assessment, change control, access reviews, and logging), along with change tickets and approvals tied to each security-relevant PR. (aicpa-cima.com)
- Slither CI job (high-signal detectors):
- Run this command:
slither . --checklist --exclude-low --print human-summary --detect reentrancy-eth,arbitrary-send-eth,arbitrary-send-erc20,weak-prng,tx-origin,unchecked-lowlevel,unprotected-upgrade,encode-packed-collision,out-of-order-retryable - Remember to upload
checklist.mdand the JSON to the CI. - Why auditors care: It basically shrinks a week of “what’s the surface area?” down to just an hour. Check it out on GitHub.
- Run this command:
- Foundry invariant test for ERC‑4626 vault:
- Here’s the function:
function invariant_totalAssetsConserved() public { assertEq(vault.totalAssets(), vault.asset().balanceOf(address(vault)) + accountedLiabilities()); } - In your
foundry.toml, bump upinvariant.runs=256anddepth=64for some more realistic sequences. You can find more info here.
- Here’s the function:
- Scribble access control postcondition:
- Use this line:
/// if_succeeds {:msg "only manager can change fee"} old(feeBps) != feeBps => hasRole(MANAGER, msg.sender) - To run it, just do:
eth‑scribble --compileand fuzz it with Echidna. More details can be found in this guide.
- Use this line:
- Circom underconstraint guard:
- Swap out the risky “i <-- ab; out <== ic” with direct constraints. Make sure to check that
--inspectcomes out clean, and don’t forget to add those tag-based bit-width templates for arithmetic! For reference, visit Circom's docs.
- Swap out the risky “i <-- ab; out <== ic” with direct constraints. Make sure to check that
- Pectra calldata budget regression:
- Calculate
tokens_in_calldata = zeros + 4*nonzeros. Ifexecution_gas_used < 6*tokens, you might be headed down the 10/40 path. To fix this, consider compressing parameters, using storage hydration, or opting for Blob DA. You can explore more on this EIP page.
- Calculate
How This Translates to Business Outcomes (Proof via GTM Metrics You Can Publish)
Set up a pre-audit scorecard that both procurement teams and executives can easily understand without needing to sift through Solidity code:
Security/Quality KPIs
- Severity Density: We’re aiming for a maximum of 0.2 critical and high findings per 1,000 SLOC during our internal reviews.
- Property Coverage: We want to capture at least 90% of critical requirements as Scribble/Certora properties.
- Invariant Health: Our goal is to maintain 100% green invariants across the last 50 CI runs.
- Code Coverage: We need to hit at least 90% line coverage and 75% branch coverage. If there are any exclusions (like inline assembly or revert paths), we need to justify those. Check out this blog post for more insights!
- Gas Regression Budget: We've got a ±3% tolerance on our .gas-snapshot, which is gated in CI. Take a look at the details here: getfoundry.sh.
Delivery/ROI KPIs
- Audit latency saved: External auditors dive into “findings” right from day 1 or 2, instead of waiting until week 2, thanks to our pre-produced assets.
- Re-audit churn: We’re keeping it to ≤1 hotfix round after the final report, all thanks to solid property/invariant coverage.
- Procurement readiness: We’ve got SOC2 mapping attached to PRs that cover change management, access control, and incident logging, which helps cut down the questionnaire cycles by 1-2 rounds. (Check it out here)
Our Internal Benchmarks
- In our 2025-2026 enterprise pilots (n=4), we found that this checklist helped slice down “audit normalization” time by about 35-55% and dropped post-audit rework by roughly 30%, based on reopened issues. Of course, results may differ for you, but one thing stands out: when you combine executable specs, fuzzing, and storage/upgrade diffs, you’re looking at fewer unexpected surprises.
Where 7Block Labs Fits (And How We Make Your Journey Safer)
- Design and Implementation: We’ve got everything covered, from Pectra-aware contract patterns to zk circuit hardening. Check out our smart contract development and web3 development services for the full scoop.
- Security Engineering: Our audit-readiness sprints, along with integrations like Slither, Scribble, Echidna, and Certora, are designed to keep you secure. We’ll help you fortify your upgrade and runbook processes via our security audit services.
- Cross-Chain and DA Modernization: Want to migrate data-heavy pipelines? We can help you move off calldata to blobs and refactor bridges and messaging. Dive into our cross-chain solutions development and blockchain bridge development for more info.
- Tokenized Assets and Enterprise Orchestration: We provide the architecture, governance, and compliance boilerplate you need through our asset tokenization and blockchain integration.
- Capital Planning: We help you sequence security and launch milestones smoothly with our fundraising advisory. This way, you can align your audit windows and go-to-market strategies effectively.
Appendix: 2025-2026 changes you should bake into your pre‑audit checklist
- With Pectra launching on the mainnet on May 7, 2025, and those Solidity defaults getting a shake-up in Prague and Osaka, it’s time to get your ducks in a row:
- Make sure to re-pin your solc and run those gas and coverage checks again.
- Don’t forget about the upcoming calldata repricing (thanks to EIP‑7623) and the blob scheduling increases; it looks like blob-first DA is going to be the way to go moving forward. Check it out here: (blog.ethereum.org).
- The recent updates in Solidity 0.8.32 and 0.8.33 have finally fixed that pesky storage-array bug that only pops up under rare boundary layouts. So, don’t fall into the trap of thinking “it will never happen to us.” If you're using custom layouts or slot math, you definitely want to add some storage boundary tests. More on that here: (soliditylang.org).
- If you're diving into EOF (think EIP‑3540 family, EOFCREATE, etc.), get on the same page with your auditor sooner rather than later. The tools and specs are really coming together, but the feature set is still evolving. Here’s a helpful link: (soliditylang.org).
- When it comes to circuits, treat those --inspect warnings as red flags--don’t ignore them! Use tag libraries and consider implementing circuit fuzzers or algebraic checkers for those non-trivial gadgets. You can find more info here: (docs.circom.io).
The bottom line
- Audit firms are all about testing behavior, not just tinkering with your repo. If you show up with stuff like executable specifications, fuzzing corpora, invariant logs, upgrade diffs, ZK constraint evidence, and SOC2-mapped workflows, you'll give your auditors the chance to focus entirely on adversarial analysis--the real work you’re paying them for.
CTA for Enterprise
Schedule Your 90-Day Pilot Strategy Call
Like what you're reading? Let's build together.
Get a free 30-minute consultation with our engineering team.
Related Posts
ByAUJay
Revamping Old Solidity Code for Today's Standards
Refactoring old Solidity contracts from versions 0.5-0.7 to the latest 0.8.x isn’t just a luxury anymore; it’s a must-have for Enterprise teams looking to save on Layer 2 costs, achieve SOC2 compliance, and reduce risks when upgrading. By using ERC-7201 namespaced storage, EIP-1153 transient storage, and OZ 5.x libraries, teams can streamline their processes and enhance their contracts significantly.
ByAUJay
Why Your dApp Frontend is Slow (and How to Fix RPC Bottlenecks)
**Summary:** A lot of the “slow dApps” you hear about aren't just issues with the front-end; they’re actually tied to RPC bottlenecks. In this post, we’ll dive into where latency sneaks in (think methods, limits, and clients), what it’s costing your DeFi product in terms of failed sessions and RPC expenses, and how 7Block Labs can help you tackle these challenges.
ByAUJay
Testing Strategies: Foundry vs. Hardhat in DeFi Protocols
**Summary:** DeFi teams can get things done quicker and more securely when they break down testing by what they want to achieve. Foundry is great for high-quality Solidity unit, fuzz, and invariant testing, while Hardhat shines for TypeScript/viem end-to-end workflows and making processes easier to manage. Check out the practical guide below!

