1"use strict";(self.webpackChunkcompose_documentation=self.webpackChunkcompose_documentation||[]).push([["5421"],{51272(e,t,n){n.r(t),n.d(t,{metadata:()=>s,default:()=>h,frontMatter:()=>l,contentTitle:()=>a,toc:()=>d,assets:()=>c});var s=JSON.parse('{"id":"design/banned-solidity-features","title":"Banned Solidity Features","description":"Solidity language features that are banned from Compose facets and modules.","source":"@site/docs/design/banned-solidity-features.mdx","sourceDirName":"design","slug":"/design/banned-solidity-features","permalink":"/docs/design/banned-solidity-features","draft":false,"unlisted":false,"editUrl":"https://github.com/Perfect-Abstractions/Compose/tree/main/website/docs/design/banned-solidity-features.mdx","tags":[],"version":"current","sidebarPosition":4,"frontMatter":{"sidebar_position":4,"title":"Banned Solidity Features","sidebar_label":"Banned Features","description":"Solidity language features that are banned from Compose facets and modules."},"sidebar":"mainSidebar","previous":{"title":"Composition","permalink":"/docs/design/design-for-composition"},"next":{"title":"Compatibility","permalink":"/docs/design/maintain-compatibility"}}'),i=n(62540),o=n(43023),r=n(92550);let l={sidebar_position:4,title:"Banned Solidity Features",sidebar_label:"Banned Features",description:"Solidity language features that are banned from Compose facets and modules."},a="Banned Solidity Features",c={},d=[{value:"Banned Solidity Features",id:"banned-solidity-features-1",level:4}];function u(e){let t={a:"a",br:"br",code:"code",h1:"h1",h4:"h4",header:"header",p:"p",pre:"pre",strong:"strong",...(0,o.R)(),...e.components},{Accordion:n,AccordionGroup:s}=t;return n||p("Accordion",!0),s||p("AccordionGroup",!0),(0,i.jsxs)(i.Fragment,{children:[(0,i.jsx)(t.header,{children:(0,i.jsx)(t.h1,{id:"banned-solidity-features",children:"Banned Solidity Features"})}),"\n",(0,i.jsxs)(t.p,{children:["The following Solidity language features are ",(0,i.jsx)(t.strong,{children:"banned"})," from Compose facets and modules."]}),"\n",(0,i.jsxs)(t.p,{children:["Compose restricts certain Solidity features to keep facet and library code ",(0,i.jsx)(t.strong,{children:"simpler"}),", ",(0,i.jsx)(t.strong,{children:"more consistent"}),", and ",(0,i.jsx)(t.strong,{children:"easier to reason about"}),"."]}),"\n",(0,i.jsx)(t.p,{children:"Because of Compose's architecture, many of these features are either unnecessary or less helpful."}),"\n",(0,i.jsxs)(r.A,{type:"warning",title:"Exceptions",children:[(0,i.jsxs)(t.p,{children:["These restrictions ",(0,i.jsx)(t.strong,{children:"do not"})," apply to tests."]}),(0,i.jsxs)(t.p,{children:["These restrictions ",(0,i.jsx)(t.strong,{children:"do not"})," apply to developers using Compose in their own projects."]})]}),"\n",(0,i.jsx)(t.h4,{id:"banned-solidity-features-1",children:"Banned Solidity Features"}),"\n",(0,i.jsxs)(s,{children:[(0,i.jsxs)(n,{title:"No Inheritance",children:[(0,i.jsxs)(t.p,{children:["Facets may ",(0,i.jsx)(t.strong,{children:"not inherit"})," from any contract or interface."]}),(0,i.jsx)(t.pre,{children:(0,i.jsx)(t.code,{className:"language-solidity",metastring:'title="\u{1F6AB} Not allowed"',children:"contract MyContract is OtherContract {\n ...\n}\n\n// or\n\ncontract MyContract is IMyInterface {\n ...\n}\n"})}),(0,i.jsx)(r.A,{type:"tip",children:(0,i.jsxs)(t.p,{children:["If you want inheritance, your facet is probably too large. Split it into smaller facets. Compose replaces inheritance with ",(0,i.jsx)(t.strong,{children:"on-chain facet composition"}),"."]})})]}),(0,i.jsxs)(n,{title:"No constructors",children:[(0,i.jsxs)(t.p,{children:["Facets may ",(0,i.jsx)(t.strong,{children:"not define constructors"}),"."]}),(0,i.jsx)(t.pre,{children:(0,i.jsx)(t.code,{className:"language-solidity",metastring:'title="\u{1F6AB} Not allowed"',children:"constructor() {\n owner = msg.sender;\n ...\n}\n"})})]}),(0,i.jsxs)(n,{title:"No modifiers",children:[(0,i.jsxs)(t.p,{children:["Facets may ",(0,i.jsx)(t.strong,{children:"not define or use modifiers"}),"."]}),(0,i.jsx)(t.pre,{children:(0,i.jsx)(t.code,{className:"language-solidity",metastring:'title="\u{1F6AB} Not allowed"',children:'modifier onlyOwner() {\n require(msg.sender == owner, "Caller is not the owner");\n _;\n}\n'})})]}),(0,i.jsxs)(n,{title:"No public/private/internal storage variables",children:[(0,i.jsxs)(t.p,{children:["Storage variables may ",(0,i.jsx)(t.strong,{children:"not include visibility specifiers"}),"."]}),(0,i.jsx)(t.pre,{children:(0,i.jsx)(t.code,{className:"language-solidity",metastring:'title="\u{1F6AB} Not allowed"',children:"uint256 public counter;\n"})}),(0,i.jsxs)(t.p,{children:["Visibility labels are unnecessary because Compose uses\n",(0,i.jsx)(t.a,{href:"https://eips.ethereum.org/EIPS/eip-8042",children:"ERC-8042 Diamond Storage"})," across all facets.",(0,i.jsx)(t.br,{}),"\n","This rule ",(0,i.jsx)(t.strong,{children:"does not apply"})," to ",(0,i.jsx)(t.code,{children:"constant"})," or ",(0,i.jsx)(t.code,{children:"immutable"})," variables, which may be declared ",(0,i.jsx)(t.code,{children:"internal"}),"."]})]}),(0,i.jsxs)(n,{title:"No public or private functions in facets",children:[(0,i.jsxs)(t.p,{children:["All facet functions must be declared as ",(0,i.jsx)(t.code,{children:"internal"})," or ",(0,i.jsx)(t.code,{children:"external"}),"."]}),(0,i.jsx)(t.pre,{children:(0,i.jsx)(t.code,{className:"language-solidity",metastring:'title="\u{1F6AB} Not allowed"',children:"function approve(address _spender, uint256 _value) public {\n ...\n}\n"})})]}),(0,i.jsx)(n,{title:"No Solidity libraries",children:(0,i.jsx)(t.pre,{children:(0,i.jsx)(t.code,{className:"language-solidity",metastring:'title="\u{1F6AB} Not allowed"',children:"library MyLib {\n ...\n}\n"})})}),(0,i.jsx)(n,{title:"No `using` directives in modules",children:(0,i.jsx)(t.pre,{children:(0,i.jsx)(t.code,{className:"language-solidity",metastring:'title="\u{1F6AB} Not allowed"',children:"using SomethingMod for uint256;\n"})})}),(0,i.jsxs)(n,{title:"No ternary operator",children:[(0,i.jsxs)(t.p,{children:["The ternary operator (",(0,i.jsx)(t.code,{children:"condition ? valueIfTrue : valueIfFalse"}),") may ",(0,i.jsx)(t.strong,{children:"not"})," be used."]}),(0,i.jsx)(t.pre,{children:(0,i.jsx)(t.code,{className:"language-solidity",metastring:'title="\u{1F6AB} Not allowed"',children:'string memory status = balance >= cost ? "Paid" : "Insufficient funds";\n'})})]}),(0,i.jsxs)(n,{title:"No single if statements without braces",children:[(0,i.jsxs)(t.p,{children:["Always use braces ",(0,i.jsx)(t.code,{children:"{}"})," around ",(0,i.jsx)(t.code,{children:"if"})," and ",(0,i.jsx)(t.code,{children:"else"})," bodies."]}),(0,i.jsx)(t.pre,{children:(0,i.jsx)(t.code,{className:"language-solidity",metastring:'title="\u{1F6AB} Not allowed"',children:"if (x < 10) count++;\n"})}),(0,i.jsx)(t.pre,{children:(0,i.jsx)(t.code,{className:"language-solidity",metastring:'title="\u2705 Required"',children:"if (x < 10) {\n count++;\n}\n"})})]}),(0,i.jsxs)(n,{title:"No selfdestruct",children:[(0,i.jsxs)(t.p,{children:["No contract or module may use ",(0,i.jsx)(t.code,{children:"selfdestruct"})]}),(0,i.jsx)(t.pre,{children:(0,i.jsx)(t.code,{className:"language-solidity",metastring:'title="\u{1F6AB} Not allowed"',children:"selfdestruct(owner); \n"})})]})]})]})}function h(e={}){let{wrapper:t}={...(0,o.R)(),...e.components};return t?(0,i.jsx)(t,{...e,children:(0,i.jsx)(u,{...e})}):u(e)}function p(e,t){throw Error("Expected "+(t?"component":"object")+" `"+e+"` to be defined: you likely forgot to import, pass, or provide it.")}},92550(e,t,n){n.d(t,{A:()=>l});var s=n(62540);n(63696);var i=n(11750),o=n(21737);let r={callout:"callout_aeEX",calloutHeader:"calloutHeader_fXny",calloutIcon:"calloutIcon_vX9X",calloutTitle:"calloutTitle_kaV8",calloutContent:"calloutContent_Hl52","callout--info":"callout--info_TgTd","callout--warning":"callout--warning_ioY5","callout--danger":"callout--danger_OAha","callout--success":"callout--success_rrx_","callout--tip":"callout--tip_iqbU","callout--note":"callout--note_gJ54"};function l({type:e="info",title:t,children:n,icon:a=!0}){let c={info:"lightbulb",warning:"warning",danger:"no-entry",success:"checkmark",tip:"lightbulb",note:"memo"};return(0,s.jsxs)("div",{className:(0,i.A)(r.callout,r[`callout--${e}`]),children:[(0,s.jsxs)("div",{className:r.calloutHeader,children:[a&&(0,s.jsx)("span",{className:r.calloutIcon,children:(0,s.jsx)(o.A,{name:c[e]||c.info,size:24})}),t&&(0,s.jsx)("span",{className:r.calloutTitle,children:t})]}),(0,s.jsx)("div",{className:r.calloutContent,children:n})]})}},43023(e,t,n){n.d(t,{R:()=>r,x:()=>l});var s=n(63696);let i={},o=s.createContext(i);function r(e){let t=s.useContext(o);return s.useMemo(function(){return"function"==typeof e?e(t):{...t,...e}},[t,e])}function l(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(i):e.components||i:r(e.components),s.createElement(o.Provider,{value:t},e.children)}}}]);
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.