Learn how reentrancy attacks like the DAO hack exploit external calls to drain smart contracts, and how to detect and prevent these vulnerabilities.
Overview
A reentrancy attack is a serious vulnerability where a function calls an external contract, allowing that contract to make repeated calls back before execution completes.
The DAO hack in 2016 exploited a reentrancy vulnerability, resulting in approximately $60 million USD in losses.
How It Works
The basic mechanism: Contract A calls Contract B. The exploit allows B to call back into A before A finishes execution.
Attack Sequence
Step-by-Step Example
User initiates withdrawal from bank contract holding 10 ETH
Bank verifies balance equals 10 ETH
Bank begins transferring 10 ETH to user
Attacker’s contract receives funds and immediately triggers another withdrawal
Balance hasn’t been updated yet, so contract allows another 10 ETH withdrawal
Cycle repeats until bank is drained
Vulnerable Code
// VULNERABLE: State updated after external callfunction withdraw(uint256 amount) public { require(balances[msg.sender] >= amount); // External call BEFORE state update (bool success, ) = msg.sender.call{value: amount}(""); require(success); // State update happens too late balances[msg.sender] -= amount;}
Attacker Contract
contract Attacker { Bank public bank; constructor(address _bankAddress) { bank = Bank(_bankAddress); } receive() external payable { if (address(bank).balance >= 10 ether) { bank.withdraw(10 ether); // Re-enter! } } function attack() public payable { bank.deposit{value: 10 ether}(); bank.withdraw(10 ether); }}
Safe Patterns
Checks-Effects-Interactions
// SAFE: State updated BEFORE external callfunction withdraw(uint256 amount) public { require(balances[msg.sender] >= amount); // Update state FIRST balances[msg.sender] -= amount; // External call LAST (bool success, ) = msg.sender.call{value: amount}(""); require(success);}
Re-entering a different function that shares state
Cross-contract
Re-entering via another contract in the same protocol
Read-only
Exploiting view functions during reentrancy
API Detection
{ "issues": [ { "tag": "reentrancy", "severity": "high", "description": "External call before state update in withdraw()", "location": "withdraw(uint256)", "variant": "single-function" } ]}
Prevention Checklist
Follow Checks-Effects-Interactions pattern
Update all state before making external calls
Use reentrancy guards (e.g., OpenZeppelin ReentrancyGuard) on sensitive functions
Use .call{value: ...}("") for ETH transfers (not transfer()/send())
Always check the boolean return value from .call and handle failures explicitly
transfer() and send() are deprecated due to their hardcoded 2300 gas limit, which can fail after gas cost changes (EIP-1884). Use .call{value: ...}("") instead.
{"docsConfig":{"theme":"mint","$schema":"https://mintlify.com/docs.json","name":"Webacy Docs","colors":{"primary":"#00d66f","light":"#33cb8b","dark":"#279b71"},"logo":{"light":"https://mintcdn.com/webacy/PZHkbk8qJrPsQSaC/logo/light.png?fit=max\u0026auto=format\u0026n=PZHkbk8qJrPsQSaC\u0026q=85\u0026s=c1933879883f6b01ff46a6e51cfd687f","dark":"https://mintcdn.com/webacy/cDgYsLUzSZsNJNEk/logo/dark.svg?fit=max\u0026auto=format\u0026n=cDgYsLUzSZsNJNEk\u0026q=85\u0026s=e8da7717da0f291d63cc90a4cb4a91af"},"favicon":"https://mintcdn.com/webacy/LaWycqKCQaZgOW1n/favicon.ico?fit=max\u0026auto=format\u0026n=LaWycqKCQaZgOW1n\u0026q=85\u0026s=2a29ac070865d3fb96939b7c595406f9","api":{},"navbar":{"primary":{"type":"button","label":"Dashboard","href":"https://dapp.webacy.com"}},"footer":{"socials":{"x":"https://x.com/mywebacy","github":"https://github.com/Webacy-Prod"}},"contextual":{"options":["copy","claude","chatgpt","cursor"],"display":"header"},"styling":{"latex":false},"navigation":{"pages":[]}},"deployment":{"deploymentMetadataValue":{"subdomain":"webacy","hasAudioNarration":false,"actualSubdomain":"webacy","customDomains":["docs.webacy.com"],"gitSource":{"type":"github","owner":"webacy-prod","repo":"mintlify-docs","deployBranch":"main","contentDirectory":"","isPrivate":true,"mountPath":"","label":""},"entitlements":{"AI_CHAT":{"status":"ENABLED"},"WEB_MCP":{"status":"ENABLED"},"NARRATION":{"status":"ENABLED"}},"buildId":"6af62704872f0a825f98c69f","clientVersion":"0.0.4143","searchFilterCounts":[{"language":"default","tag":"Build","count":61},{"language":"default","tag":"API Reference","count":49},{"language":"default","tag":"Overview","count":29},{"language":"default","tag":"Glossary","count":25},{"language":"default","tag":"Risk Intelligence","count":21},{"language":"default","tag":"Learn","count":18},{"language":"default","tag":"Integrations","count":15},{"language":"default","tag":"Stablecoins","count":11},{"language":"default","tag":"Contract Security","count":9},{"language":"default","tag":"SDK","count":8}]},"assistantConfig":{"enableAskAiButton":false,"enableStarterQuestions":false,"enableAskAiSearchBar":true},"basePath":"","hasChatPermissions":true,"hasWebMcpPermissions":true,"toggles":[{"name":"kill-isr","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"custom-rbac-roles","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"agent-mintlify-slack","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"agent-integrations-settings","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"rbac-expansion","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"automations-pr-grouping","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"custom-prefix","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"analytics-v7","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"user-flows-analytics","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"no-publish-flow","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"workos-onboarding","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"snapshot-serving-live","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"stripTemperatureMiddleware","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"support-platform-pylon-zendesk","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"snapshot-serving","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"instant-rollback","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"granular-notifications-server","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"granular-notifications","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"automations-fable","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"fixed-ai-action-pricing","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"automation-resolve-merge-conflict","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"scoped-publishing","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"mintql","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"page-level-analytics","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"editor-version-history-v2","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"billing-page-v2","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"full-page-search","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"workspace-projects","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"assistant-v5","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"fork-pr-previews","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"revalidation-jwt","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"workos-sso-scim","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"hobby-abuse-scan","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"dashboard-inbox","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"workos-signup","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"turbopuffer-dual-write","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"workos-enabled","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"approve-review-flow","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"editor-metadata","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"sso-setup-deadline-banner","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"turbopuffer-serve","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"live-agents","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"llms-txt-v2","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false}],"googleFontsInlined":false},"customCss":[{"filePath":"style.css","content":".gb{display:inline-block;min-width:2.2em;padding:2px 9px;border-radius:6px;font-weight:700;font-size:0.85em;line-height:1.35;text-align:center;letter-spacing:0.02em;white-space:nowrap}.gb-a{background:#047857;color:#ffffff}.gb-b{background:#1d4ed8;color:#ffffff}.gb-c{background:#f59e0b;color:#1f2937}.gb-d{background:#c2410c;color:#ffffff}.gb-f{background:#b91c1c;color:#ffffff}"}],"page":{"pagePath":"glossary/reentrancy","slug":"/glossary/reentrancy","pageMetadata":{"title":"Reentrancy","description":"Learn how reentrancy attacks like the DAO hack exploit external calls to drain smart contracts, and how to detect and prevent these vulnerabilities.","public":true,"href":"/glossary/reentrancy"},"description":{"compiledSource":"\"use strict\";\nconst {jsx: _jsx} = arguments[0];\nconst {useMDXComponents: _provideComponents} = arguments[0];\nfunction _createMdxContent(props) {\n const _components = {\n p: \"p\",\n ..._provideComponents(),\n ...props.components\n };\n return _jsx(_components.p, {\n children: \"Learn how reentrancy attacks like the DAO hack exploit external calls to drain smart contracts, and how to detect and prevent these vulnerabilities.\"\n });\n}\nfunction MDXContent(props = {}) {\n const {wrapper: MDXLayout} = {\n ..._provideComponents(),\n ...props.components\n };\n return MDXLayout ? _jsx(MDXLayout, {\n ...props,\n children: _jsx(_createMdxContent, {\n ...props\n })\n }) : _createMdxContent(props);\n}\nreturn {\n default: MDXContent\n};\n","frontmatter":{},"scope":{}},"pageType":"default","mdx":{"mdxSource":{"compiledSource":"\"use strict\";const{Fragment:_Fragment,jsx:_jsx,jsxs:_jsxs}=arguments[0];const{useMDXComponents:_provideComponents}=arguments[0];function _createMdxContent(props){const _components={code:`code`,input:`input`,li:`li`,ol:`ol`,p:`p`,pre:`pre`,span:`span`,strong:`strong`,tbody:`tbody`,td:`td`,th:`th`,thead:`thead`,tr:`tr`,ul:`ul`,..._provideComponents(),...props.components},{CodeBlock,Heading,Mermaid,Table,Warning}=_components;if(!CodeBlock)_missingMdxReference(`CodeBlock`,true);if(!Heading)_missingMdxReference(`Heading`,true);if(!Mermaid)_missingMdxReference(`Mermaid`,true);if(!Table)_missingMdxReference(`Table`,true);if(!Warning)_missingMdxReference(`Warning`,true);return _jsxs(_Fragment,{children:[_jsx(Heading,{level:`2`,id:`overview`,children:`Overview`}),`\n`,_jsx(_components.p,{children:`A reentrancy attack is a serious vulnerability where a function calls an external contract, allowing that contract to make repeated calls back before execution completes.`}),`\n`,_jsx(Warning,{children:_jsx(_components.p,{children:`The DAO hack in 2016 exploited a reentrancy vulnerability, resulting in approximately $60 million USD in losses.`})}),`\n`,_jsx(Heading,{level:`2`,id:`how-it-works`,children:`How It Works`}),`\n`,_jsxs(_components.p,{children:[`The basic mechanism: `,_jsx(_components.strong,{children:`Contract A calls Contract B. The exploit allows B to call back into A before A finishes execution.`})]}),`\n`,_jsx(Heading,{level:`3`,id:`attack-sequence`,children:`Attack Sequence`}),`\n`,_jsx(Mermaid,{chart:`sequenceDiagram\n participant Attacker\n participant Bank\n Attacker->>Bank: withdraw(10 ETH)\n Bank->>Bank: Check balance (10 ETH) ✓\n Bank->>Attacker: Send 10 ETH\n Attacker->>Bank: withdraw(10 ETH) [re-enter]\n Bank->>Bank: Check balance (still 10 ETH!) ✓\n Bank->>Attacker: Send 10 ETH\n Note over Attacker,Bank: Repeats until drained`}),`\n`,_jsx(Heading,{level:`3`,id:`step-by-step-example`,children:`Step-by-Step Example`}),`\n`,_jsxs(_components.ol,{children:[`\n`,_jsx(_components.li,{children:`User initiates withdrawal from bank contract holding 10 ETH`}),`\n`,_jsx(_components.li,{children:`Bank verifies balance equals 10 ETH`}),`\n`,_jsx(_components.li,{children:`Bank begins transferring 10 ETH to user`}),`\n`,_jsxs(_components.li,{children:[`Attacker’s contract receives funds and `,_jsx(_components.strong,{children:`immediately triggers another withdrawal`})]}),`\n`,_jsx(_components.li,{children:`Balance hasn’t been updated yet, so contract allows another 10 ETH withdrawal`}),`\n`,_jsx(_components.li,{children:`Cycle repeats until bank is drained`}),`\n`]}),`\n`,_jsx(Heading,{level:`2`,id:`vulnerable-code`,children:`Vulnerable Code`}),`\n`,_jsx(CodeBlock,{filename:``,numberOfLines:`11`,language:`solidity`,children:_jsx(_components.pre,{className:`shiki shiki-themes github-light-default dark-plus`,style:{backgroundColor:`#ffffff`,\"--shiki-dark-bg\":`#0B0C0E`,color:`#1f2328`,\"--shiki-dark\":`#D4D4D4`},language:`solidity`,children:_jsxs(_components.code,{language:`solidity`,numberOfLines:`11`,children:[_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#6E7781`,\"--shiki-dark\":`#6A9955`},children:`// VULNERABLE: State updated after external call`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`function`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:` withdraw`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#4EC9B0`},children:`uint256`}),_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#9CDCFE`},children:` amount`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`) `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`public`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` {`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:` require`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(balances[`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#569CD6`},children:`msg.sender`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`] `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`>=`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` amount);`})]}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#6E7781`,\"--shiki-dark\":`#6A9955`},children:` // External call BEFORE state update`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` (`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#4EC9B0`},children:`bool`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` success, ) `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#569CD6`},children:` msg.sender`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.call{value`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`:`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` amount}(`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`);`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:` require`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(success);`})]}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#6E7781`,\"--shiki-dark\":`#6A9955`},children:` // State update happens too late`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` balances[`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#569CD6`},children:`msg.sender`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`] `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`-=`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` amount;`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`}`})}),`\n`]})})}),`\n`,_jsx(Heading,{level:`2`,id:`attacker-contract`,children:`Attacker Contract`}),`\n`,_jsx(CodeBlock,{filename:``,numberOfLines:`18`,language:`solidity`,children:_jsx(_components.pre,{className:`shiki shiki-themes github-light-default dark-plus`,style:{backgroundColor:`#ffffff`,\"--shiki-dark-bg\":`#0B0C0E`,color:`#1f2328`,\"--shiki-dark\":`#D4D4D4`},language:`solidity`,children:_jsxs(_components.code,{language:`solidity`,numberOfLines:`18`,children:[_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`contract`}),_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#4EC9B0`},children:` Attacker`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` {`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` Bank `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`public`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` bank;`})]}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:` constructor`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#4EC9B0`},children:`address`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:` _bankAddress`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`) {`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` bank `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:` Bank`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(_bankAddress);`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` }`})}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:` receive`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`() `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`external`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:` payable`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` {`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:` if`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` (`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#4EC9B0`},children:`address`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(bank).balance `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`>=`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#B5CEA8`},children:` 10`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#569CD6`},children:` ether`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`) {`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` bank.`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:`withdraw`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#B5CEA8`},children:`10`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#569CD6`},children:` ether`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`); `}),_jsx(_components.span,{style:{color:`#6E7781`,\"--shiki-dark\":`#6A9955`},children:`// Re-enter!`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` }`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` }`})}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:` function`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:` attack`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`() `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`public`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:` payable`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` {`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` bank.deposit{value`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`:`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#B5CEA8`},children:` 10`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#569CD6`},children:` ether`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`}();`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` bank.`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:`withdraw`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#B5CEA8`},children:`10`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#569CD6`},children:` ether`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`);`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` }`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`}`})}),`\n`]})})}),`\n`,_jsx(Heading,{level:`2`,id:`safe-patterns`,children:`Safe Patterns`}),`\n`,_jsx(Heading,{level:`3`,id:`checks-effects-interactions`,children:`Checks-Effects-Interactions`}),`\n`,_jsx(CodeBlock,{filename:``,numberOfLines:`11`,language:`solidity`,children:_jsx(_components.pre,{className:`shiki shiki-themes github-light-default dark-plus`,style:{backgroundColor:`#ffffff`,\"--shiki-dark-bg\":`#0B0C0E`,color:`#1f2328`,\"--shiki-dark\":`#D4D4D4`},language:`solidity`,children:_jsxs(_components.code,{language:`solidity`,numberOfLines:`11`,children:[_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#6E7781`,\"--shiki-dark\":`#6A9955`},children:`// SAFE: State updated BEFORE external call`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`function`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:` withdraw`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#4EC9B0`},children:`uint256`}),_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#9CDCFE`},children:` amount`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`) `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`public`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` {`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:` require`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(balances[`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#569CD6`},children:`msg.sender`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`] `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`>=`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` amount);`})]}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#6E7781`,\"--shiki-dark\":`#6A9955`},children:` // Update state FIRST`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` balances[`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#569CD6`},children:`msg.sender`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`] `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`-=`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` amount;`})]}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#6E7781`,\"--shiki-dark\":`#6A9955`},children:` // External call LAST`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` (`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#4EC9B0`},children:`bool`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` success, ) `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#569CD6`},children:` msg.sender`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.call{value`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`:`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` amount}(`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`);`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:` require`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(success);`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`}`})}),`\n`]})})}),`\n`,_jsx(Heading,{level:`3`,id:`reentrancy-guard`,children:`Reentrancy Guard`}),`\n`,_jsx(CodeBlock,{filename:``,numberOfLines:`16`,language:`solidity`,children:_jsx(_components.pre,{className:`shiki shiki-themes github-light-default dark-plus`,style:{backgroundColor:`#ffffff`,\"--shiki-dark-bg\":`#0B0C0E`,color:`#1f2328`,\"--shiki-dark\":`#D4D4D4`},language:`solidity`,children:_jsxs(_components.code,{language:`solidity`,numberOfLines:`16`,children:[_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#6E7781`,\"--shiki-dark\":`#6A9955`},children:`// SAFE: Mutex lock prevents re-entry`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#4EC9B0`},children:`bool`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:` private`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` locked;`})]}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`modifier`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:` noReentrant`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`() {`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:` require`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`!`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`locked, `}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"Reentrant call\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`);`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` locked `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#569CD6`},children:` true`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`;`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#D4D4D4`},children:` _`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`;`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` locked `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#569CD6`},children:` false`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`;`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`}`})}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`function`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:` withdraw`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#4EC9B0`},children:`uint256`}),_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#9CDCFE`},children:` amount`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`) `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`public`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:` noReentrant`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` {`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:` require`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(balances[`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#569CD6`},children:`msg.sender`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`] `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`>=`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` amount);`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` balances[`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#569CD6`},children:`msg.sender`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`] `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`-=`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` amount;`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` (`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#4EC9B0`},children:`bool`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` success, ) `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#569CD6`},children:` msg.sender`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.call{value`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`:`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` amount}(`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`);`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:` require`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(success);`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`}`})}),`\n`]})})}),`\n`,_jsx(Heading,{level:`2`,id:`reentrancy-variants`,children:`Reentrancy Variants`}),`\n`,_jsxs(Table,{children:[_jsx(_components.thead,{children:_jsxs(_components.tr,{children:[_jsx(_components.th,{children:`Variant`}),_jsx(_components.th,{children:`Description`})]})}),_jsxs(_components.tbody,{children:[_jsxs(_components.tr,{children:[_jsx(_components.td,{children:_jsx(_components.strong,{children:`Single-function`})}),_jsx(_components.td,{children:`Re-entering the same function`})]}),_jsxs(_components.tr,{children:[_jsx(_components.td,{children:_jsx(_components.strong,{children:`Cross-function`})}),_jsx(_components.td,{children:`Re-entering a different function that shares state`})]}),_jsxs(_components.tr,{children:[_jsx(_components.td,{children:_jsx(_components.strong,{children:`Cross-contract`})}),_jsx(_components.td,{children:`Re-entering via another contract in the same protocol`})]}),_jsxs(_components.tr,{children:[_jsx(_components.td,{children:_jsx(_components.strong,{children:`Read-only`})}),_jsx(_components.td,{children:`Exploiting view functions during reentrancy`})]})]})]}),`\n`,_jsx(Heading,{level:`2`,id:`api-detection`,children:`API Detection`}),`\n`,_jsx(CodeBlock,{filename:``,numberOfLines:`11`,language:`json`,children:_jsx(_components.pre,{className:`shiki shiki-themes github-light-default dark-plus`,style:{backgroundColor:`#ffffff`,\"--shiki-dark-bg\":`#0B0C0E`,color:`#1f2328`,\"--shiki-dark\":`#D4D4D4`},language:`json`,children:_jsxs(_components.code,{language:`json`,numberOfLines:`11`,children:[_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`{`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#116329`,\"--shiki-dark\":`#9CDCFE`},children:` \"issues\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: [`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` {`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#116329`,\"--shiki-dark\":`#9CDCFE`},children:` \"tag\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: `}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"reentrancy\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`,`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#116329`,\"--shiki-dark\":`#9CDCFE`},children:` \"severity\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: `}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"high\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`,`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#116329`,\"--shiki-dark\":`#9CDCFE`},children:` \"description\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: `}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"External call before state update in withdraw()\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`,`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#116329`,\"--shiki-dark\":`#9CDCFE`},children:` \"location\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: `}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"withdraw(uint256)\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`,`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#116329`,\"--shiki-dark\":`#9CDCFE`},children:` \"variant\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: `}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"single-function\"`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` }`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` ]`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`}`})}),`\n`]})})}),`\n`,_jsx(Heading,{level:`2`,id:`prevention-checklist`,children:`Prevention Checklist`}),`\n`,_jsxs(_components.ul,{className:`contains-task-list`,children:[`\n`,_jsxs(_components.li,{className:`task-list-item`,children:[_jsx(_components.input,{type:`checkbox`,disabled:true}),` `,`Follow Checks-Effects-Interactions pattern`]}),`\n`,_jsxs(_components.li,{className:`task-list-item`,children:[_jsx(_components.input,{type:`checkbox`,disabled:true}),` `,`Update all state before making external calls`]}),`\n`,_jsxs(_components.li,{className:`task-list-item`,children:[_jsx(_components.input,{type:`checkbox`,disabled:true}),` `,`Use reentrancy guards (e.g., OpenZeppelin `,_jsx(_components.code,{children:`ReentrancyGuard`}),`) on sensitive functions`]}),`\n`,_jsxs(_components.li,{className:`task-list-item`,children:[_jsx(_components.input,{type:`checkbox`,disabled:true}),` `,`Use `,_jsx(_components.code,{children:`.call{value: ...}(\"\")`}),` for ETH transfers (not `,_jsx(_components.code,{children:`transfer()`}),`/`,_jsx(_components.code,{children:`send()`}),`)`]}),`\n`,_jsxs(_components.li,{className:`task-list-item`,children:[_jsx(_components.input,{type:`checkbox`,disabled:true}),` `,`Always check the boolean return value from `,_jsx(_components.code,{children:`.call`}),` and handle failures explicitly`]}),`\n`]}),`\n`,_jsx(Warning,{children:_jsxs(_components.p,{children:[_jsx(_components.code,{children:`transfer()`}),` and `,_jsx(_components.code,{children:`send()`}),` are `,_jsx(_components.strong,{children:`deprecated`}),` due to their hardcoded 2300 gas limit, which can fail after gas cost changes (EIP-1884). Use `,_jsx(_components.code,{children:`.call{value: ...}(\"\")`}),` instead.`]})})]})}function MDXContent(props={}){const{wrapper:MDXLayout}={..._provideComponents(),...props.components};return MDXLayout?_jsx(MDXLayout,{...props,children:_jsx(_createMdxContent,{...props})}):_createMdxContent(props)}return{default:MDXContent};function _missingMdxReference(id,component){throw new Error(`Expected `+(component?`component`:`object`)+\" `\"+id+\"` to be defined: you likely forgot to import, pass, or provide it.\")}","frontmatter":{},"scope":{"config":{},"pageMetadata":{"title":"Reentrancy","description":"Learn how reentrancy attacks like the DAO hack exploit external calls to drain smart contracts, and how to detect and prevent these vulnerabilities.","public":true,"href":"/glossary/reentrancy"}}},"mdxSourceWithNoJs":null},"mdxExtracts":{"tableOfContents":[{"title":"Overview","slug":"overview","depth":2,"children":[]},{"title":"How It Works","slug":"how-it-works","depth":2,"children":[{"title":"Attack Sequence","slug":"attack-sequence","depth":3,"children":[]},{"title":"Step-by-Step Example","slug":"step-by-step-example","depth":3,"children":[]}]},{"title":"Vulnerable Code","slug":"vulnerable-code","depth":2,"children":[]},{"title":"Attacker Contract","slug":"attacker-contract","depth":2,"children":[]},{"title":"Safe Patterns","slug":"safe-patterns","depth":2,"children":[{"title":"Checks-Effects-Interactions","slug":"checks-effects-interactions","depth":3,"children":[]},{"title":"Reentrancy Guard","slug":"reentrancy-guard","depth":3,"children":[]}]},{"title":"Reentrancy Variants","slug":"reentrancy-variants","depth":2,"children":[]},{"title":"API Detection","slug":"api-detection","depth":2,"children":[]},{"title":"Prevention Checklist","slug":"prevention-checklist","depth":2,"children":[]}],"codeExamples":{}},"jsLinks":[],"subdomain":"webacy","siteName":"Webacy Docs","title":"Reentrancy - Webacy Docs","navMaps":{"firstHrefInVersion":{},"firstHrefInLanguage":{}},"lastModified":"2026-11-12T17:16:09.031Z","originalFileLocation":"glossary/reentrancy.mdx"},"headHtml":"\u003cscript data-mint-head>(function(){var d=document.documentElement,p=null;if(!p){try{p=localStorage.getItem(\"isDarkMode\")}catch(e){}if(p==='true')p='dark';else if(p==='false')p='light';if(p!=='light'\u0026\u0026p!=='dark'\u0026\u0026p!=='system')p=\"system\"}var r=p==='system'?(matchMedia(\"(prefers-color-scheme: dark)\").matches?'dark':'light'):p;d.classList.remove(r==='dark'?'light':'dark');d.classList.add(r);d.setAttribute(\"data-theme-preference\",p)})();\u003c/script>\u003cmeta data-mint-head name=\"description\" content=\"Learn how reentrancy attacks like the DAO hack exploit external calls to drain smart contracts, and how to detect and prevent these vulnerabilities.\">\u003cmeta data-mint-head name=\"application-name\" content=\"Webacy Docs\">\u003cmeta data-mint-head name=\"generator\" content=\"Mintlify\">\u003clink data-mint-head rel=\"icon\" type=\"image/png\" sizes=\"192x192\" href=\"/mintlify-assets/_mintlify/favicons/webacy/BDwg8pUd_cx6RnJh/_generated/favicon/android-chrome-192x192.png\" media=\"(prefers-color-scheme: light)\">\u003clink data-mint-head rel=\"apple-touch-icon\" type=\"image/png\" sizes=\"180x180\" href=\"/mintlify-assets/_mintlify/favicons/webacy/BDwg8pUd_cx6RnJh/_generated/favicon/apple-touch-icon.png\">\u003clink data-mint-head rel=\"icon\" type=\"image/png\" sizes=\"16x16\" href=\"/mintlify-assets/_mintlify/favicons/webacy/BDwg8pUd_cx6RnJh/_generated/favicon/favicon-16x16.png\" media=\"(prefers-color-scheme: light)\">\u003clink data-mint-head rel=\"icon\" type=\"image/png\" sizes=\"32x32\" href=\"/mintlify-assets/_mintlify/favicons/webacy/BDwg8pUd_cx6RnJh/_generated/favicon/favicon-32x32.png\" media=\"(prefers-color-scheme: light)\">\u003clink data-mint-head rel=\"shortcut icon\" type=\"image/x-icon\" href=\"/mintlify-assets/_mintlify/favicons/webacy/BDwg8pUd_cx6RnJh/_generated/favicon/favicon.ico\" media=\"(prefers-color-scheme: light)\">\u003clink data-mint-head rel=\"icon\" type=\"image/png\" sizes=\"192x192\" href=\"/mintlify-assets/_mintlify/favicons/webacy/BDwg8pUd_cx6RnJh/_generated/favicon-dark/android-chrome-192x192.png\" media=\"(prefers-color-scheme: dark)\">\u003clink data-mint-head rel=\"icon\" type=\"image/png\" sizes=\"16x16\" href=\"/mintlify-assets/_mintlify/favicons/webacy/BDwg8pUd_cx6RnJh/_generated/favicon-dark/favicon-16x16.png\" media=\"(prefers-color-scheme: dark)\">\u003clink data-mint-head rel=\"icon\" type=\"image/png\" sizes=\"32x32\" href=\"/mintlify-assets/_mintlify/favicons/webacy/BDwg8pUd_cx6RnJh/_generated/favicon-dark/favicon-32x32.png\" media=\"(prefers-color-scheme: dark)\">\u003clink data-mint-head rel=\"shortcut icon\" type=\"image/x-icon\" href=\"/mintlify-assets/_mintlify/favicons/webacy/BDwg8pUd_cx6RnJh/_generated/favicon-dark/favicon.ico\" media=\"(prefers-color-scheme: dark)\">\u003cmeta data-mint-head property=\"og:title\" content=\"Reentrancy - Webacy Docs\">\u003cmeta data-mint-head property=\"og:description\" content=\"Learn how reentrancy attacks like the DAO hack exploit external calls to drain smart contracts, and how to detect and prevent these vulnerabilities.\">\u003cmeta data-mint-head property=\"og:site_name\" content=\"Webacy Docs\">\u003cmeta data-mint-head property=\"og:url\" content=\"https://docs.webacy.com/glossary/reentrancy\">\u003cmeta data-mint-head property=\"og:type\" content=\"website\">\u003cmeta data-mint-head property=\"og:image\" content=\"https://webacy.mintlify.site/_mintlify/api/og/v2?division=Contract+Security\u0026amp;title=Reentrancy\u0026amp;description=Learn+how+reentrancy+attacks+like+the+DAO+hack+exploit+external+calls+to+drain+smart+contracts%2C+and+how+to+detect+and+prevent+these+vulnerabilities.\u0026amp;theme=256fd323fde43a5eeef07bf6\u0026amp;signature=a23d399929896e944615d1827fa58f528825ff6910de3ebe264dc79ecb0bb112\">\u003cmeta data-mint-head property=\"og:image:width\" content=\"1200\">\u003cmeta data-mint-head property=\"og:image:height\" content=\"630\">\u003cmeta data-mint-head name=\"twitter:card\" content=\"summary_large_image\">\u003cmeta data-mint-head name=\"twitter:title\" content=\"Reentrancy - Webacy Docs\">\u003cmeta data-mint-head name=\"twitter:description\" content=\"Learn how reentrancy attacks like the DAO hack exploit external calls to drain smart contracts, and how to detect and prevent these vulnerabilities.\">\u003cmeta data-mint-head name=\"twitter:image\" content=\"https://webacy.mintlify.site/_mintlify/api/og/v2?division=Contract+Security\u0026amp;title=Reentrancy\u0026amp;description=Learn+how+reentrancy+attacks+like+the+DAO+hack+exploit+external+calls+to+drain+smart+contracts%2C+and+how+to+detect+and+prevent+these+vulnerabilities.\u0026amp;theme=256fd323fde43a5eeef07bf6\u0026amp;signature=a23d399929896e944615d1827fa58f528825ff6910de3ebe264dc79ecb0bb112\">\u003cmeta data-mint-head name=\"twitter:image:width\" content=\"1200\">\u003cmeta data-mint-head name=\"twitter:image:height\" content=\"630\">\u003cmeta data-mint-head name=\"msapplication-config\" content=\"/mintlify-assets/_mintlify/favicons/webacy/BDwg8pUd_cx6RnJh/_generated/favicon/browserconfig.xml\">\u003cmeta data-mint-head name=\"apple-mobile-web-app-title\" content=\"Webacy Docs\">\u003cmeta data-mint-head name=\"msapplication-TileColor\" content=\"#00d66f\">\u003clink data-mint-head rel=\"canonical\" href=\"https://docs.webacy.com/glossary/reentrancy\">\u003clink data-mint-head rel=\"alternate\" type=\"application/xml\" href=\"/sitemap.xml\">\u003clink data-mint-head rel=\"alternate\" type=\"text/markdown\" href=\"/glossary/reentrancy.md\">\u003cscript data-mint-head type=\"application/ld+json\">{\"@context\":\"https://schema.org\",\"@graph\":[{\"@type\":\"Organization\",\"@id\":\"https://docs.webacy.com/#organization\",\"name\":\"Webacy Docs\",\"url\":\"https://docs.webacy.com\",\"logo\":{\"@type\":\"ImageObject\",\"url\":\"https://mintcdn.com/webacy/PZHkbk8qJrPsQSaC/logo/light.png?fit=max\u0026auto=format\u0026n=PZHkbk8qJrPsQSaC\u0026q=85\u0026s=c1933879883f6b01ff46a6e51cfd687f\"}},{\"@type\":\"WebSite\",\"@id\":\"https://docs.webacy.com#website\",\"name\":\"Webacy Docs\",\"url\":\"https://docs.webacy.com\",\"publisher\":{\"@id\":\"https://docs.webacy.com/#organization\"}},{\"@type\":\"WebPage\",\"@id\":\"https://docs.webacy.com/glossary/reentrancy#webpage\",\"url\":\"https://docs.webacy.com/glossary/reentrancy\",\"name\":\"Reentrancy\",\"description\":\"Learn how reentrancy attacks like the DAO hack exploit external calls to drain smart contracts, and how to detect and prevent these vulnerabilities.\",\"dateModified\":\"2026-11-12T17:16:09.031Z\",\"isPartOf\":{\"@id\":\"https://docs.webacy.com#website\"},\"breadcrumb\":{\"@id\":\"https://docs.webacy.com/glossary/reentrancy#breadcrumb\"}},{\"@type\":\"BreadcrumbList\",\"@id\":\"https://docs.webacy.com/glossary/reentrancy#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Glossary\",\"item\":\"https://docs.webacy.com/glossary/definitions\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Contract Security\",\"item\":\"https://docs.webacy.com/glossary/threats-and-labels\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Reentrancy\",\"item\":\"https://docs.webacy.com/glossary/reentrancy\"}]},{\"@type\":[\"Article\",\"TechArticle\"],\"@id\":\"https://docs.webacy.com/glossary/reentrancy#article\",\"headline\":\"Reentrancy\",\"name\":\"Reentrancy\",\"description\":\"Learn how reentrancy attacks like the DAO hack exploit external calls to drain smart contracts, and how to detect and prevent these vulnerabilities.\",\"url\":\"https://docs.webacy.com/glossary/reentrancy\",\"mainEntityOfPage\":{\"@id\":\"https://docs.webacy.com/glossary/reentrancy#webpage\"},\"dateModified\":\"2026-11-12T17:16:09.031Z\",\"publisher\":{\"@id\":\"https://docs.webacy.com/#organization\"},\"isPartOf\":{\"@id\":\"https://docs.webacy.com#website\"}}]}\u003c/script>\u003cscript data-mint-head type=\"application/ld+json\">{\"@context\":\"https://schema.org\",\"@type\":\"WebSite\",\"name\":\"Webacy Docs\",\"publisher\":{\"@type\":\"Organization\",\"name\":\"Webacy Docs\"},\"provider\":{\"@type\":\"Organization\",\"name\":\"Mintlify\",\"url\":\"https://mintlify.com\"}}\u003c/script>","agentPointerHref":"/glossary/reentrancy.md","siteName":"Webacy Docs","nav":{"global":null,"tabs":[{"tab":"Overview","pages":[{"title":"Overview","href":"/introduction"}]},{"tab":"Build","groups":[{"group":"👋 Start Here","pages":[{"title":"Getting Started","href":"/getting-started"},{"title":"Get an API Key","href":"/get-an-api-key"},{"title":"Authentication","href":"/authentication"},{"title":"Rate Limits","href":"/rate-limits"},{"title":"Errors","href":"/errors"},{"title":"Example Addresses","href":"/example-addresses"}]},{"group":"Integrations","pages":[{"title":"API Considerations","href":"/essentials/considerations"},{"title":"x402 Payments","href":"/x402-payments"},{"group":"AI","pages":[{"title":"Build with AI","href":"/integrations/build-with-ai"},{"title":"Webacy API reference for AI coding agents","href":"/integrations/agent-reference"},{"title":"Webacy MCP Server for AI Coding Agents","href":"/integrations/mcp-server"}]},{"group":"SDK","pages":[{"title":"SDK Introduction","href":"/sdk/introduction"},{"title":"Webacy SDK Use Cases","href":"/sdk/use-cases"},{"title":"Installation","href":"/sdk/installation"},{"title":"Webacy SDK CLI Reference","href":"/sdk/cli"},{"title":"ThreatClient","href":"/sdk/threat-client"},{"title":"TradingClient","href":"/sdk/trading-client"},{"title":"Supported Chains in the Webacy SDK","href":"/sdk/chains"},{"title":"Error Handling","href":"/sdk/error-handling"}]},{"group":"Webhooks","pages":[{"title":"Webhook Alerts: real-time depeg and risk event delivery","href":"/essentials/webhooks"},{"title":"Webhook Alerts integration tutorial","href":"/essentials/webhooks-tutorial"}]}]},{"group":"Vaults","pages":[{"title":"Vault Risk Integration Guide","href":"/digital-assets/vault-risk"},{"title":"Vault Risk Intelligence","href":"/vault-risk-intelligence"},{"title":"Vault Yield \u0026 Fees","href":"/vault-yield-and-fees"},{"title":"On-Chain Dollar Rate","href":"/dollar-rate"},{"title":"Vault Ratings","href":"/vault-ratings"},{"title":"Screen and Monitor Vault Risk","href":"/digital-assets/vault-risk-screening"},{"title":"Vault Incidents","href":"/vault-incidents"}]},{"group":"Stablecoin \u0026 RWA","pages":[{"title":"Supply Flows","href":"/supply-flows"},{"title":"Backing Map","href":"/backing-map"},{"title":"Yield Scores: Safety-Weighted Ranking of Stablecoin Pools","href":"/yield-scores"},{"title":"Holder Concentration Index (HCI) Methodology","href":"/holder-concentration"},{"title":"Stablecoin Graveyard: Defunct and Depegged Tokens","href":"/graveyard"}]},{"group":"Depeg Monitor","pages":[{"title":"Depeg Monitor Scoring Methodology and Signals","href":"/scoring-methodology"},{"title":"Risk Rating","href":"/safety-grade"},{"title":"Peg Canary Score (PCS)","href":"/pcs"},{"title":"Depeg Monitor data dictionary","href":"/data-dictionary"},{"title":"Scoring Model \u0026 Methodology","href":"/scoring-model-and-methodology"}]},{"group":"Glossary","pages":[{"title":"Definitions","href":"/glossary/definitions"},{"title":"Label Types","href":"/glossary/label-types"},{"title":"Risk Assessment Modules","href":"/glossary/modules"},{"group":"FAQs","pages":[{"title":"Webacy Data Sources for Risk Ratings and Intelligence","href":"/data-sources"},{"title":"What Technology Does Webacy Build In-House?","href":"/what-technology-does-webacy-build-in-house"}]},{"group":"Contract Security","pages":[{"title":"Threats and Labels","href":"/glossary/threats-and-labels"},{"title":"Hidden Mint","href":"/glossary/hidden-mint"},{"title":"Hidden Balance Update","description":"Detect hidden balance update vulnerabilities that let malicious smart contracts secretly alter ERC-20 token balances without authorization or events.","href":"/glossary/hidden-balance-update"},{"title":"Reentrancy","public":true,"href":"/glossary/reentrancy"},{"title":"Unchecked Low Level Calls","description":"Detect unchecked low-level call vulnerabilities in Solidity where ignored return values cause silent failures, lost funds, and corrupted contract state.","href":"/glossary/unchecked-calls"},{"title":"Malicious Bool Checks","href":"/glossary/malicious-bool-checks"},{"title":"Malicious Burn","href":"/glossary/malicious-burn"},{"title":"Malicious External Call","href":"/glossary/malicious-external-call"},{"title":"Digital Signature Module","href":"/glossary/digital-signature-module"}]},{"group":"Asset Security","pages":[{"title":"Honeypots","href":"/glossary/honeypots"},{"title":"Rug Pulls","href":"/glossary/rug-pulls"},{"title":"Fake Tokens","href":"/glossary/fake-tokens"},{"title":"Tax Tokens","href":"/glossary/tax-tokens"},{"title":"Liquidity Risks","href":"/glossary/liquidity-risks"}]},{"group":"Wallet Behavior","pages":[{"title":"Wash Trading","href":"/glossary/wash-trading"},{"title":"Mixers \u0026 Tumblers","href":"/glossary/mixers"},{"title":"Drainers","href":"/glossary/drainers"},{"title":"Phishing","href":"/glossary/phishing"},{"title":"Address Poisoning","href":"/glossary/address-poisoning"},{"title":"Snipers \u0026 Bundlers","href":"/glossary/snipers-bundlers"}]}]}]},{"tab":"Learn","pages":[{"title":"Learn","href":"/use-cases-guides-walkthroughs"}]},{"tab":"API Reference","pages":[{"title":"API Reference","href":"/api-reference/introduction"}]}]},"basePath":"","title":"Reentrancy - Webacy Docs","buildId":"dpl_Fyv1NbzwP68g2bEH2Roy98uY1zmE","deploymentId":"dpl_Fyv1NbzwP68g2bEH2Roy98uY1zmE","dynamics":[],"chunks":[]}