(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[3471],{1841:function(e,t,n){(window.__NEXT_P=window.__NEXT_P||[]).push(["/world/account-delegation",function(){return n(684)}])},3307:function(e,t,n){"use strict";n.d(t,{Z:function(){return o}});var a=n(7505),r=n(1689);let i={logo:function(){return(0,a.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:"0.25em",fontSize:"32px",fontFamily:"PP Supply Mono",textTransform:"uppercase"},children:[(0,a.jsx)("img",{src:"/images/logos/mud-white.svg",style:{height:"calc(var(--nextra-navbar-height) - 35px)"},alt:"MUD logo"}),"MUD"]})},useNextSeoProps(){let{asPath:e}=(0,r.useRouter)();return{titleTemplate:"/"===e?"MUD – a framework for ambitious Ethereum applications":"%s – MUD"}},project:{link:"https://github.com/latticexyz/mud"},docsRepositoryBase:"https://github.com/latticexyz/mud/tree/main/docs",head:(0,a.jsx)(a.Fragment,{children:(0,a.jsx)("meta",{property:"title",content:"MUD documentation"})}),darkMode:!1,nextThemes:{defaultTheme:"dark"},footer:{text:"MIT 2023 \xa9 MUD"},primaryHue:28,sidebar:{defaultMenuCollapseLevel:1}};var o=i},684:function(e,t,n){"use strict";n.r(t);var a=n(7505),r=n(2585),i=n(8288),o=n(3307);n(4693);var d=n(6736);n(8823),n(4738);let s={MDXContent:function(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},{wrapper:t}=Object.assign({},(0,d.ah)(),e.components);return t?(0,a.jsx)(t,{...e,children:(0,a.jsx)(l,{...e})}):l(e)},pageOpts:{filePath:"pages/world/account-delegation.mdx",route:"/world/account-delegation",headings:[{depth:1,value:"Account delegation",id:"account-delegation"},{depth:2,value:"User delegation",id:"user-delegation"},{depth:3,value:"Creating a user delegation",id:"creating-a-user-delegation"},{depth:3,value:"Using a user delegation",id:"using-a-user-delegation"},{depth:3,value:"Removing a user delegation",id:"removing-a-user-delegation"},{depth:2,value:"Namespace delegation",id:"namespace-delegation"},{depth:2,value:"Order of delegation checks",id:"order-of-delegation-checks"}],pageMap:[{kind:"Meta",data:{introduction:{title:"What is MUD?",theme:{breadcrumb:!1}},quickstart:{title:"Get started",theme:{breadcrumb:!1}},protocol:{title:"Protocol",type:"separator"},store:"Store",world:"World",framework:{title:"Framework",type:"separator"},config:"Config",cli:"CLI","state-query":"State Query",services:"Services","---":{title:"",type:"separator"},guides:"Guides",templates:"Templates",contribute:{title:"Contribute",theme:{breadcrumb:!1}},changelog:"Changelog",retrospectives:"Retrospectives",audits:"Audits",version:{title:"2.0.9",type:"menu",items:{changelog:{title:"Changelog",href:"/changelog"},contribute:{title:"Contribute",href:"/contribute"}}},status:{title:"Status",type:"page",href:"https://status.mud.dev",newWindow:!0},community:{title:"Community",type:"page",href:"https://community.mud.dev",newWindow:!0},twitter:{title:"Twitter",type:"page",href:"https://twitter.com/latticexyz",newWindow:!0},discord:{title:"Discord",type:"page",href:"https://lattice.xyz/discord",newWindow:!0}}},{kind:"Folder",name:"audits",route:"/audits",children:[{kind:"MdxPage",name:"2024-02-11-open-zeppelin",route:"/audits/2024-02-11-open-zeppelin"},{kind:"Meta",data:{"2024-02-11-open-zeppelin":"2024-02-11 OpenZeppelin",pdf:{display:"hidden"},icons:{display:"hidden"}}}]},{kind:"MdxPage",name:"changelog",route:"/changelog"},{kind:"Folder",name:"cli",route:"/cli",children:[{kind:"Meta",data:{tablegen:"mud tablegen",worldgen:"mud worldgen",test:"mud test",deploy:"mud deploy",verify:"mud verify","dev-contracts":"mud dev-contracts","abi-ts":"mud abi-ts",faucet:"mud faucet","set-version":"mud set-version"}},{kind:"MdxPage",name:"abi-ts",route:"/cli/abi-ts"},{kind:"MdxPage",name:"deploy",route:"/cli/deploy"},{kind:"MdxPage",name:"dev-contracts",route:"/cli/dev-contracts"},{kind:"MdxPage",name:"faucet",route:"/cli/faucet"},{kind:"MdxPage",name:"set-version",route:"/cli/set-version"},{kind:"MdxPage",name:"tablegen",route:"/cli/tablegen"},{kind:"MdxPage",name:"test",route:"/cli/test"},{kind:"MdxPage",name:"verify",route:"/cli/verify"},{kind:"MdxPage",name:"worldgen",route:"/cli/worldgen"}]},{kind:"MdxPage",name:"config",route:"/config"},{kind:"MdxPage",name:"contribute",route:"/contribute"},{kind:"Folder",name:"guides",route:"/guides",children:[{kind:"Meta",data:{"replicating-onchain-state":"Replicating onchain state","hello-world":"Hello World","extending-a-world":"Extending a World","adding-delegation":"Adding Delegation",emojimon:"Emojimon","best-practices":"Best Practices"}},{kind:"MdxPage",name:"adding-delegation",route:"/guides/adding-delegation"},{kind:"Folder",name:"best-practices",route:"/guides/best-practices",children:[{kind:"Meta",data:{"system-best-practices":"System Best Practices"}},{kind:"MdxPage",name:"system-best-practices",route:"/guides/best-practices/system-best-practices"}]},{kind:"Folder",name:"emojimon",route:"/guides/emojimon",children:[{kind:"MdxPage",name:"1-preface-the-ecs-model",route:"/guides/emojimon/1-preface-the-ecs-model"},{kind:"MdxPage",name:"2-getting-started",route:"/guides/emojimon/2-getting-started"},{kind:"MdxPage",name:"3-players-and-movement",route:"/guides/emojimon/3-players-and-movement"},{kind:"MdxPage",name:"4-map-and-terrain",route:"/guides/emojimon/4-map-and-terrain"},{kind:"MdxPage",name:"5-a-wild-emojimon-appears",route:"/guides/emojimon/5-a-wild-emojimon-appears"},{kind:"MdxPage",name:"6-advanced",route:"/guides/emojimon/6-advanced"},{kind:"Meta",data:{"1-preface-the-ecs-model":"Preface: the ECS model","2-getting-started":"Getting started","3-players-and-movement":"Players and movement","4-map-and-terrain":"Map and terrain","5-a-wild-emojimon-appears":"A wild Emojimon appears","6-advanced":"Advanced features"}}]},{kind:"MdxPage",name:"emojimon",route:"/guides/emojimon"},{kind:"Folder",name:"extending-a-world",route:"/guides/extending-a-world",children:[{kind:"Meta",data:{index:"Extending a World Permissionlessly"}},{kind:"MdxPage",name:"index",route:"/guides/extending-a-world"}]},{kind:"Folder",name:"hello-world",route:"/guides/hello-world",children:[{kind:"Meta",data:{"add-table":"Add a table","filter-sync":"Filter data synchronization","add-system":"Add a system",deploy:{title:"Deploy to a blockchain",href:"/cli/deploy"}}},{kind:"MdxPage",name:"add-system",route:"/guides/hello-world/add-system"},{kind:"MdxPage",name:"add-table",route:"/guides/hello-world/add-table"},{kind:"MdxPage",name:"filter-sync",route:"/guides/hello-world/filter-sync"}]},{kind:"MdxPage",name:"hello-world",route:"/guides/hello-world"},{kind:"MdxPage",name:"replicating-onchain-state",route:"/guides/replicating-onchain-state"}]},{kind:"MdxPage",name:"introduction",route:"/introduction"},{kind:"MdxPage",name:"quickstart",route:"/quickstart"},{kind:"Folder",name:"retrospectives",route:"/retrospectives",children:[{kind:"MdxPage",name:"2023-09-12-register-system-vulnerability",route:"/retrospectives/2023-09-12-register-system-vulnerability"},{kind:"MdxPage",name:"2024-04-17-storeread-getdynamicfieldlength-bug",route:"/retrospectives/2024-04-17-storeread-getdynamicfieldlength-bug"},{kind:"Meta",data:{"2024-04-17-storeread-getdynamicfieldlength-bug":"2024-04-17 StoreRead.getDynamicFieldLength bug","2023-09-12-register-system-vulnerability":"2023-09-12 registerSystem vulnerability"}}]},{kind:"Folder",name:"services",route:"/services",children:[{kind:"Meta",data:{indexer:"Indexer",faucet:"Faucet"}},{kind:"MdxPage",name:"faucet",route:"/services/faucet"},{kind:"MdxPage",name:"indexer",route:"/services/indexer"}]},{kind:"Folder",name:"state-query",route:"/state-query",children:[{kind:"Meta",data:{typescript:"TypeScript"}},{kind:"Folder",name:"typescript",route:"/state-query/typescript",children:[{kind:"Meta",data:{recs:"RECS",zustand:"Zustand"}},{kind:"MdxPage",name:"recs",route:"/state-query/typescript/recs"},{kind:"MdxPage",name:"zustand",route:"/state-query/typescript/zustand"}]}]},{kind:"Folder",name:"store",route:"/store",children:[{kind:"Meta",data:{introduction:"Introduction","data-model":"Data model",tables:"Tables","table-libraries":"Table libraries",encoding:"Encoding","store-hooks":"Store hooks",reference:"Reference"}},{kind:"MdxPage",name:"data-model",route:"/store/data-model"},{kind:"MdxPage",name:"encoding",route:"/store/encoding"},{kind:"MdxPage",name:"introduction",route:"/store/introduction"},{kind:"Folder",name:"reference",route:"/store/reference",children:[{kind:"Meta",data:{"store-core":"StoreCore (internal)",store:"IStore (external)","store-hook":"StoreHook",misc:"Miscellaneous"}},{kind:"MdxPage",name:"misc",route:"/store/reference/misc"},{kind:"MdxPage",name:"store-core",route:"/store/reference/store-core"},{kind:"MdxPage",name:"store-hook",route:"/store/reference/store-hook"},{kind:"MdxPage",name:"store",route:"/store/reference/store"}]},{kind:"MdxPage",name:"store-hooks",route:"/store/store-hooks"},{kind:"MdxPage",name:"table-libraries",route:"/store/table-libraries"},{kind:"MdxPage",name:"tables",route:"/store/tables"}]},{kind:"Folder",name:"templates",route:"/templates",children:[{kind:"Meta",data:{typescript:"TypeScript",godot:"Godot",pwa:"Progressive Web App (for mobile)",swift:"Swift",svelte:"Svelte",unity:"Unity"}},{kind:"MdxPage",name:"godot",route:"/templates/godot"},{kind:"MdxPage",name:"pwa",route:"/templates/pwa"},{kind:"MdxPage",name:"svelte",route:"/templates/svelte"},{kind:"MdxPage",name:"swift",route:"/templates/swift"},{kind:"Folder",name:"typescript",route:"/templates/typescript",children:[{kind:"Meta",data:{contracts:"Contracts",vanilla:"Vanilla","react-ecs":"React-ECS",threejs:"Three.js",vue:"Vue"}},{kind:"MdxPage",name:"contracts",route:"/templates/typescript/contracts"},{kind:"MdxPage",name:"react-ecs",route:"/templates/typescript/react-ecs"},{kind:"MdxPage",name:"threejs",route:"/templates/typescript/threejs"},{kind:"MdxPage",name:"vanilla",route:"/templates/typescript/vanilla"},{kind:"MdxPage",name:"vue",route:"/templates/typescript/vue"}]},{kind:"MdxPage",name:"unity",route:"/templates/unity"}]},{kind:"Folder",name:"world",route:"/world",children:[{kind:"Meta",data:{introduction:"Introduction","resource-ids":"Resource Identifiers","namespaces-access-control":"Namespaces & Access Control",tables:"Tables",systems:"Systems","system-hooks":"System Hooks","function-selectors":"Function Selectors",balance:"Balance","account-delegation":"Account Delegation","batch-calls":"Batch Calls",upgrades:"Upgrading",modules:"Modules",reference:"Reference"}},{kind:"MdxPage",name:"account-delegation",route:"/world/account-delegation"},{kind:"MdxPage",name:"balance",route:"/world/balance"},{kind:"MdxPage",name:"batch-calls",route:"/world/batch-calls"},{kind:"MdxPage",name:"function-selectors",route:"/world/function-selectors"},{kind:"MdxPage",name:"introduction",route:"/world/introduction"},{kind:"Folder",name:"modules",route:"/world/modules",children:[{kind:"Meta",data:{keyswithvalue:"Keys with Value"}},{kind:"MdxPage",name:"keyswithvalue",route:"/world/modules/keyswithvalue"}]},{kind:"MdxPage",name:"modules",route:"/world/modules"},{kind:"MdxPage",name:"namespaces-access-control",route:"/world/namespaces-access-control"},{kind:"Folder",name:"reference",route:"/world/reference",children:[{kind:"Meta",data:{"delegation-external":"Delegation (interface)",module:"Modules","module-external":"Modules (interface)",system:"Systems","system-external":"Systems (interface)",world:"World","world-external":"World (interfaces)","world-context":"World context","world-context-external":"World context (interface)","resource-ids":"Resource IDs",misc:"Miscellaneous",internal:"Internals"}},{kind:"MdxPage",name:"delegation-external",route:"/world/reference/delegation-external"},{kind:"Folder",name:"internal",route:"/world/reference/internal",children:[{kind:"Meta",data:{"access-control":"Access Control",create:"Create2",delegation:"Delegation",erc165:"ERC165","erc165-external":"ERC165 (interface)","init-module":"Init Module","init-module-implementation":"Init Module Implementation",systemcall:"SystemCall"}},{kind:"MdxPage",name:"access-control",route:"/world/reference/internal/access-control"},{kind:"MdxPage",name:"create",route:"/world/reference/internal/create"},{kind:"MdxPage",name:"delegation",route:"/world/reference/internal/delegation"},{kind:"MdxPage",name:"erc165-external",route:"/world/reference/internal/erc165-external"},{kind:"MdxPage",name:"erc165",route:"/world/reference/internal/erc165"},{kind:"MdxPage",name:"init-module-implementation",route:"/world/reference/internal/init-module-implementation"},{kind:"MdxPage",name:"init-module",route:"/world/reference/internal/init-module"},{kind:"MdxPage",name:"systemcall",route:"/world/reference/internal/systemcall"}]},{kind:"MdxPage",name:"misc",route:"/world/reference/misc"},{kind:"MdxPage",name:"module-external",route:"/world/reference/module-external"},{kind:"MdxPage",name:"module",route:"/world/reference/module"},{kind:"MdxPage",name:"resource-ids",route:"/world/reference/resource-ids"},{kind:"MdxPage",name:"system-external",route:"/world/reference/system-external"},{kind:"MdxPage",name:"system",route:"/world/reference/system"},{kind:"MdxPage",name:"world-context-external",route:"/world/reference/world-context-external"},{kind:"MdxPage",name:"world-context",route:"/world/reference/world-context"},{kind:"MdxPage",name:"world-external",route:"/world/reference/world-external"},{kind:"MdxPage",name:"world",route:"/world/reference/world"}]},{kind:"MdxPage",name:"resource-ids",route:"/world/resource-ids"},{kind:"MdxPage",name:"system-hooks",route:"/world/system-hooks"},{kind:"MdxPage",name:"systems",route:"/world/systems"},{kind:"MdxPage",name:"tables",route:"/world/tables"},{kind:"MdxPage",name:"upgrades",route:"/world/upgrades"}]}],flexsearch:{codeblocks:!0},title:"Account delegation"},pageNextRoute:"/world/account-delegation",nextraLayout:i.ZP,themeConfig:o.Z};function l(e){let t=Object.assign({h1:"h1",p:"p",em:"em",code:"code",ul:"ul",li:"li",strong:"strong",a:"a",details:"details",summary:"summary",h2:"h2",h3:"h3",ol:"ol"},(0,d.ah)(),e.components);return(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)(t.h1,{children:"Account delegation"}),"\n",(0,a.jsxs)(t.p,{children:[(0,a.jsx)(t.em,{children:"Account delegation"})," allows a ",(0,a.jsx)(t.em,{children:"delegator"})," address to permit a ",(0,a.jsx)(t.em,{children:"delegatee"})," address to call a ",(0,a.jsx)(t.code,{children:"System"})," on its behalf.\nAlternatively, the namespace owner can register a delegation that applies to all calls to all ",(0,a.jsx)(t.code,{children:"System"}),"s in the namespace."]}),"\n",(0,a.jsx)(t.p,{children:"This feature enables multiple use cases."}),"\n",(0,a.jsxs)(t.ul,{children:["\n",(0,a.jsxs)(t.li,{children:["\n",(0,a.jsxs)(t.p,{children:[(0,a.jsx)(t.strong,{children:"Session wallets"}),".\nNormally a wallet requires the user to authorize each transaction separately.\nIn the case of a blockchain game, this means having to authorize every move, which is excessive.\nUsing account delegation players can authorize a different wallet, one whose private key is stored on the client, to act on their behalf.\nBecause this wallet's private key is stored in the client, rather than a browser extension, the client can decide when asking for authorization is warranted and when it isn't.\nBy making sure this is a ",(0,a.jsx)(t.em,{children:"separate"})," wallet, we protect the player's main account in the case of vulnerable or malicious game clients."]}),"\n"]}),"\n",(0,a.jsxs)(t.li,{children:["\n",(0,a.jsxs)(t.p,{children:[(0,a.jsx)(t.strong,{children:"Approvals"}),".\nUsers can approve contracts to perform actions in a MUD world on their behalf.\nThis is conceptually similar to how ERC20's ",(0,a.jsxs)(t.a,{href:"https://eips.ethereum.org/EIPS/eip-20#transferfrom",children:[(0,a.jsx)(t.code,{children:"approve"}),"/",(0,a.jsx)(t.code,{children:"transferFrom"})]})," enables atomic swaps by allowing contracts to withdraw from a user's balance and then deposit a different asset in a single transaction.\nFor example, an agent could exchange two in-game assets atomically if the two sides of the trade give it the necessary permission."]}),"\n"]}),"\n"]}),"\n",(0,a.jsxs)(t.details,{children:[(0,a.jsx)(t.summary,{children:"Delegation and Account Abstraction"}),(0,a.jsxs)(t.p,{children:["While there are some overlaps in use cases between ",(0,a.jsx)(t.a,{href:"https://www.erc4337.io/",children:"ERC-4337"})," and MUD's account delegation, they are different things.\nIn ERC-4337, a smart contract wallet becomes your main onchain identity.\nWith MUD delegation, you keep your existing account, but (temporarily) approve other accounts to act on its behalf."]})]}),"\n",(0,a.jsx)(t.h2,{id:"user-delegation",children:"User delegation"}),"\n",(0,a.jsx)(t.p,{children:"The most common type of delegation is when a delegator address allows a specific delegatee address to act on its behalf."}),"\n",(0,a.jsx)(t.h3,{id:"creating-a-user-delegation",children:"Creating a user delegation"}),"\n",(0,a.jsxs)(t.p,{children:["First, the delegator has to call ",(0,a.jsx)(t.a,{href:"https://github.com/latticexyz/mud/blob/main/packages/world/src/modules/init/implementations/WorldRegistrationSystem.sol#L251-L284",children:(0,a.jsx)(t.code,{children:"registerDelegation"})}),".\nThis function takes three parameters:"]}),"\n",(0,a.jsxs)(t.ul,{children:["\n",(0,a.jsxs)(t.li,{children:["\n",(0,a.jsxs)(t.p,{children:[(0,a.jsx)(t.code,{children:"delegatee"}),", the address given the privileges.\nThis can be ",(0,a.jsx)(t.code,{children:"address(0)"})," to let this delegation apply to all callers. Note that combining ",(0,a.jsx)(t.code,{children:"address(0)"})," with an unlimited delegation is discouraged, as it would allow anyone to perform any action on behalf of the delegator."]}),"\n"]}),"\n",(0,a.jsxs)(t.li,{children:["\n",(0,a.jsxs)(t.p,{children:[(0,a.jsx)(t.code,{children:"delegationControlId"}),", this is usually the ",(0,a.jsx)(t.code,{children:"ResourceId"})," for a ",(0,a.jsx)(t.code,{children:"System"})," that decides whether an attempt to do something by the delegatee on behalf of the delegator is authorized or not.\nAlternatively, this value can be ",(0,a.jsx)(t.a,{href:"https://github.com/latticexyz/mud/blob/main/packages/world/src/constants.sol#L23-L25",children:(0,a.jsx)(t.code,{children:"UNLIMITED_DELEGATION"})}),", in which case the delegatee has unlimited authority."]}),"\n",(0,a.jsxs)(t.p,{children:["We have an example of a delegation control ",(0,a.jsx)(t.code,{children:"System"})," in ",(0,a.jsxs)(t.a,{href:"https://github.com/latticexyz/mud/tree/main/packages/world-modules/src/modules/std-delegations",children:["the ",(0,a.jsx)(t.code,{children:"std-delegations"})," module"]}),"."]}),"\n"]}),"\n",(0,a.jsxs)(t.li,{children:["\n",(0,a.jsxs)(t.p,{children:[(0,a.jsx)(t.code,{children:"initCallData"}),", call data for a function that is called on the ",(0,a.jsx)(t.code,{children:"delegationControlId"})," to inform it of the new delegation.\nThis ",(0,a.jsx)(t.a,{href:"https://docs.soliditylang.org/en/latest/abi-spec.html",children:"call data"})," includes both the function selector of the function to call and arguments to pass to the function (the result of ",(0,a.jsx)(t.code,{children:"abi.encodeCall"}),")."]}),"\n"]}),"\n"]}),"\n",(0,a.jsx)(t.h3,{id:"using-a-user-delegation",children:"Using a user delegation"}),"\n",(0,a.jsxs)(t.p,{children:["The delegatee can use ",(0,a.jsx)(t.a,{href:"https://github.com/latticexyz/mud/blob/main/packages/world/src/World.sol#L353-L394",children:(0,a.jsx)(t.code,{children:"callFrom"})}),".\nThis function takes three parameters:"]}),"\n",(0,a.jsxs)(t.ul,{children:["\n",(0,a.jsxs)(t.li,{children:[(0,a.jsx)(t.code,{children:"delegator"}),", the address on whose behalf the call is happening."]}),"\n",(0,a.jsxs)(t.li,{children:[(0,a.jsx)(t.code,{children:"systemId"}),", the ",(0,a.jsx)(t.code,{children:"System"})," to call."]}),"\n",(0,a.jsxs)(t.li,{children:[(0,a.jsx)(t.code,{children:"callData"}),", the ",(0,a.jsx)(t.a,{href:"https://docs.soliditylang.org/en/latest/abi-spec.html",children:"call data"})," to send the ",(0,a.jsx)(t.code,{children:"System"}),", which includes both the function selector and arguments (the result of ",(0,a.jsx)(t.code,{children:"abi.encodeCall"}),")."]}),"\n"]}),"\n",(0,a.jsxs)(t.p,{children:["Note that between a specific delegator and a specific delegatee there can only be one user delegation at a time.\nThis means that if you need in a ",(0,a.jsx)(t.code,{children:"World"})," to implement multiple delegation algorithms you might need to create a dispatcher delegation that calls different verification functions based on the ",(0,a.jsx)(t.code,{children:"systemId"})," and ",(0,a.jsx)(t.code,{children:"callData"})," it receives."]}),"\n",(0,a.jsx)(t.h3,{id:"removing-a-user-delegation",children:"Removing a user delegation"}),"\n",(0,a.jsxs)(t.p,{children:["You can use ",(0,a.jsx)(t.a,{href:"https://github.com/latticexyz/mud/blob/main/packages/world/src/modules/init/implementations/WorldRegistrationSystem.sol#L286-L294",children:(0,a.jsx)(t.code,{children:"unregisterDelegation"})})," to remove a delegation."]}),"\n",(0,a.jsxs)(t.p,{children:["Because of ",(0,a.jsx)(t.code,{children:"unregisterDelegation"})," delegations cannot be used for a delegator to commit to allow something to be done in the future.\nIf you need a ",(0,a.jsx)(t.em,{children:"commitment"}),", create a table with a ",(0,a.jsx)(t.code,{children:"System"})," that lets the address that commits write the commitment and have an action that other addresses can call only if the proper commitment is there - without giving the committed address an option to delete the entry."]}),"\n",(0,a.jsx)(t.h2,{id:"namespace-delegation",children:"Namespace delegation"}),"\n",(0,a.jsxs)(t.p,{children:["The owner of a namespace can use ",(0,a.jsx)(t.a,{href:"https://github.com/latticexyz/mud/blob/main/packages/world/src/modules/init/implementations/WorldRegistrationSystem.sol#L296-L335",children:(0,a.jsx)(t.code,{children:"registerNamespaceDelegation"})})," to register a delegation that applies to all callers of systems in this namespace.\nThis functionality is useful, for example, to implement a trusted forwarder for the namespace.\nThis is not a security concern because the namespace owner already has full control over any table or ",(0,a.jsx)(t.code,{children:"System"})," in the namespace."]}),"\n",(0,a.jsx)(t.h2,{id:"order-of-delegation-checks",children:"Order of delegation checks"}),"\n",(0,a.jsxs)(t.p,{children:["As you can see in ",(0,a.jsx)(t.a,{href:"https://github.com/latticexyz/mud/blob/main/packages/world/src/World.sol#L353-L394",children:(0,a.jsx)(t.code,{children:"callFrom"})}),", the order of delegation checks is:"]}),"\n",(0,a.jsxs)(t.ol,{children:["\n",(0,a.jsxs)(t.li,{children:["If there is a ",(0,a.jsx)(t.code,{children:"world:UserDelegationControl"})," entry with the delegator and the delegatee (a.k.a. ",(0,a.jsx)(t.code,{children:"msg.sender"}),"), check it.\nIf it results in an approval, perform the call."]}),"\n",(0,a.jsxs)(t.li,{children:["If the user provided a fallback delegation (one where the delegatee is ",(0,a.jsx)(t.code,{children:"address(0)"}),"), check it.\nIf it results in an approval, perform the call."]}),"\n",(0,a.jsx)(t.li,{children:"If there is an applicable namespace delegation, check that one.\nIf it results in an approval, perform the call."}),"\n"]}),"\n",(0,a.jsxs)(t.p,{children:["This means that if there's a namespace delegation that modifies information (for example, writes to a MUD table to gather statistics) users will be able to bypass it by creating their own delegation with the same delegetee and a ",(0,a.jsx)(t.code,{children:"System"})," that would approve."]})]})}t.default=(0,r.j)(s)}},function(e){e.O(0,[3720,2888,179],function(){return e(e.s=1841)}),_N_E=e.O()}]);