Skip to content

Commit

Permalink
add callFrom entry point
Browse files Browse the repository at this point in the history
  • Loading branch information
alvrs committed Aug 30, 2023
1 parent 31a033a commit d63e159
Show file tree
Hide file tree
Showing 21 changed files with 849 additions and 37 deletions.
102 changes: 69 additions & 33 deletions packages/world/gas-report.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,71 +35,95 @@
"name": "AccessControl: requireAccess (this address)",
"gasUsed": 153
},
{
"file": "test/DelegationsModule.t.sol",
"test": "testCallFromDisposableDelegation",
"name": "register a disposable delegation with a non-root module",
"gasUsed": 112653
},
{
"file": "test/DelegationsModule.t.sol",
"test": "testCallFromDisposableDelegation",
"name": "call a system via a disposable delegation with a non-root module",
"gasUsed": 54285
},
{
"file": "test/DelegationsModule.t.sol",
"test": "testCallFromDisposableDelegationRoot",
"name": "register a disposable delegation with a root module",
"gasUsed": 104604
},
{
"file": "test/DelegationsModule.t.sol",
"test": "testCallFromDisposableDelegationRoot",
"name": "call a system via a disposable delegation with a root module",
"gasUsed": 45638
},
{
"file": "test/KeysInTableModule.t.sol",
"test": "testInstallComposite",
"name": "install keys in table module",
"gasUsed": 1411953
"gasUsed": 1411658
},
{
"file": "test/KeysInTableModule.t.sol",
"test": "testInstallGas",
"name": "install keys in table module",
"gasUsed": 1411953
"gasUsed": 1411658
},
{
"file": "test/KeysInTableModule.t.sol",
"test": "testInstallGas",
"name": "set a record on a table with keysInTableModule installed",
"gasUsed": 181989
"gasUsed": 182055
},
{
"file": "test/KeysInTableModule.t.sol",
"test": "testInstallSingleton",
"name": "install keys in table module",
"gasUsed": 1411953
"gasUsed": 1411658
},
{
"file": "test/KeysInTableModule.t.sol",
"test": "testSetAndDeleteRecordHookCompositeGas",
"name": "install keys in table module",
"gasUsed": 1411953
"gasUsed": 1411658
},
{
"file": "test/KeysInTableModule.t.sol",
"test": "testSetAndDeleteRecordHookCompositeGas",
"name": "change a composite record on a table with keysInTableModule installed",
"gasUsed": 25645
"gasUsed": 25667
},
{
"file": "test/KeysInTableModule.t.sol",
"test": "testSetAndDeleteRecordHookCompositeGas",
"name": "delete a composite record on a table with keysInTableModule installed",
"gasUsed": 250522
"gasUsed": 250544
},
{
"file": "test/KeysInTableModule.t.sol",
"test": "testSetAndDeleteRecordHookGas",
"name": "install keys in table module",
"gasUsed": 1411953
"gasUsed": 1411658
},
{
"file": "test/KeysInTableModule.t.sol",
"test": "testSetAndDeleteRecordHookGas",
"name": "change a record on a table with keysInTableModule installed",
"gasUsed": 24365
"gasUsed": 24387
},
{
"file": "test/KeysInTableModule.t.sol",
"test": "testSetAndDeleteRecordHookGas",
"name": "delete a record on a table with keysInTableModule installed",
"gasUsed": 128811
"gasUsed": 128833
},
{
"file": "test/KeysWithValueModule.t.sol",
"test": "testGetKeysWithValueGas",
"name": "install keys with value module",
"gasUsed": 650480
"gasUsed": 650464
},
{
"file": "test/KeysWithValueModule.t.sol",
Expand All @@ -117,25 +141,25 @@
"file": "test/KeysWithValueModule.t.sol",
"test": "testInstall",
"name": "install keys with value module",
"gasUsed": 650480
"gasUsed": 650464
},
{
"file": "test/KeysWithValueModule.t.sol",
"test": "testInstall",
"name": "set a record on a table with KeysWithValueModule installed",
"gasUsed": 151489
"gasUsed": 151511
},
{
"file": "test/KeysWithValueModule.t.sol",
"test": "testSetAndDeleteRecordHook",
"name": "install keys with value module",
"gasUsed": 650480
"gasUsed": 650464
},
{
"file": "test/KeysWithValueModule.t.sol",
"test": "testSetAndDeleteRecordHook",
"name": "change a record on a table with KeysWithValueModule installed",
"gasUsed": 117961
"gasUsed": 117983
},
{
"file": "test/KeysWithValueModule.t.sol",
Expand All @@ -147,7 +171,7 @@
"file": "test/KeysWithValueModule.t.sol",
"test": "testSetField",
"name": "install keys with value module",
"gasUsed": 650480
"gasUsed": 650464
},
{
"file": "test/KeysWithValueModule.t.sol",
Expand All @@ -165,31 +189,31 @@
"file": "test/query.t.sol",
"test": "testCombinedHasHasValueNotQuery",
"name": "CombinedHasHasValueNotQuery",
"gasUsed": 165699
"gasUsed": 165765
},
{
"file": "test/query.t.sol",
"test": "testCombinedHasHasValueQuery",
"name": "CombinedHasHasValueQuery",
"gasUsed": 75996
"gasUsed": 76018
},
{
"file": "test/query.t.sol",
"test": "testCombinedHasNotQuery",
"name": "CombinedHasNotQuery",
"gasUsed": 229855
"gasUsed": 229965
},
{
"file": "test/query.t.sol",
"test": "testCombinedHasQuery",
"name": "CombinedHasQuery",
"gasUsed": 151588
"gasUsed": 151676
},
{
"file": "test/query.t.sol",
"test": "testCombinedHasValueNotQuery",
"name": "CombinedHasValueNotQuery",
"gasUsed": 143470
"gasUsed": 143536
},
{
"file": "test/query.t.sol",
Expand All @@ -201,19 +225,19 @@
"file": "test/query.t.sol",
"test": "testHasQuery",
"name": "HasQuery",
"gasUsed": 34883
"gasUsed": 34905
},
{
"file": "test/query.t.sol",
"test": "testHasQuery1000Keys",
"name": "HasQuery with 1000 keys",
"gasUsed": 9272645
"gasUsed": 9272667
},
{
"file": "test/query.t.sol",
"test": "testHasQuery100Keys",
"name": "HasQuery with 100 keys",
"gasUsed": 861378
"gasUsed": 861400
},
{
"file": "test/query.t.sol",
Expand All @@ -225,13 +249,13 @@
"file": "test/query.t.sol",
"test": "testNotValueQuery",
"name": "NotValueQuery",
"gasUsed": 69590
"gasUsed": 69612
},
{
"file": "test/UniqueEntityModule.t.sol",
"test": "testInstall",
"name": "install unique entity module",
"gasUsed": 722077
"gasUsed": 722053
},
{
"file": "test/UniqueEntityModule.t.sol",
Expand All @@ -243,7 +267,7 @@
"file": "test/UniqueEntityModule.t.sol",
"test": "testInstallRoot",
"name": "installRoot unique entity module",
"gasUsed": 700972
"gasUsed": 700987
},
{
"file": "test/UniqueEntityModule.t.sol",
Expand All @@ -257,6 +281,18 @@
"name": "call a system via the World",
"gasUsed": 17531
},
{
"file": "test/World.t.sol",
"test": "testCallFromUnlimitedDelegation",
"name": "register an unlimited delegation",
"gasUsed": 55457
},
{
"file": "test/World.t.sol",
"test": "testCallFromUnlimitedDelegation",
"name": "call a system via an unlimited delegation",
"gasUsed": 17865
},
{
"file": "test/World.t.sol",
"test": "testDeleteRecord",
Expand All @@ -273,37 +309,37 @@
"file": "test/World.t.sol",
"test": "testRegisterFallbackSystem",
"name": "Register a fallback system",
"gasUsed": 70183
"gasUsed": 70137
},
{
"file": "test/World.t.sol",
"test": "testRegisterFallbackSystem",
"name": "Register a root fallback system",
"gasUsed": 63676
"gasUsed": 63700
},
{
"file": "test/World.t.sol",
"test": "testRegisterFunctionSelector",
"name": "Register a function selector",
"gasUsed": 90777
"gasUsed": 90731
},
{
"file": "test/World.t.sol",
"test": "testRegisterNamespace",
"name": "Register a new namespace",
"gasUsed": 140015
"gasUsed": 140037
},
{
"file": "test/World.t.sol",
"test": "testRegisterRootFunctionSelector",
"name": "Register a root function selector",
"gasUsed": 79587
"gasUsed": 79611
},
{
"file": "test/World.t.sol",
"test": "testRegisterTable",
"name": "Register a new table in the namespace",
"gasUsed": 650174
"gasUsed": 650005
},
{
"file": "test/World.t.sol",
Expand Down
23 changes: 23 additions & 0 deletions packages/world/mud.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,15 @@ export default mudConfig({
// schema in `getField` too. (See https://github.com/latticexyz/mud/issues/444)
dataStruct: true,
},
Delegations: {
keySchema: {
delegator: "address",
delegatee: "address",
},
schema: {
delegationControl: "bytes32",
},
},
/************************************************************************
*
* MODULE TABLES
Expand Down Expand Up @@ -131,6 +140,20 @@ export default mudConfig({
tableIdArgument: true,
storeArgument: true,
},
DisposableDelegations: {
directory: "modules/delegations/tables",
keySchema: {
delegator: "address",
delegatee: "address",
resourceSelector: "bytes32",
funcSelectorAndArgsHash: "bytes32",
},
schema: {
availableCalls: "uint256",
},
tableIdArgument: true,
storeArgument: true,
},
/************************************************************************
*
* TEST TABLES
Expand Down
59 changes: 59 additions & 0 deletions packages/world/src/Delegation.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
// SPDX-License-Identifier: MIT
pragma solidity >=0.8.0;

import { UNLIMITED_DELEGATION } from "./constants.sol";
import { IDelegationControl } from "./interfaces/IDelegationControl.sol";
import { SystemCall } from "./SystemCall.sol";

type Delegation is bytes32;

using DelegationInstance for Delegation global;

library DelegationInstance {
function exists(Delegation self) internal pure returns (bool) {
return Delegation.unwrap(self) != bytes32("");
}

function isUnlimited(Delegation self) internal pure returns (bool) {
return Delegation.unwrap(self) == UNLIMITED_DELEGATION;
}

function isLimited(Delegation self) internal pure returns (bool) {
return exists(self) && !isUnlimited(self);
}

/**
* Verify a delegation.
* Returns true if the delegation exists and is valid, false otherwise.
* Note: verifying the delegation might have side effects in the delegation control contract.
*/
function verify(
Delegation self,
address delegator,
address delegatee,
bytes32 systemId,
bytes memory funcSelectorAndArgs
) internal returns (bool) {
// Early return if there is an unlimited delegation
if (isUnlimited(self)) return true;

// Early return if there is no valid delegation
if (!exists(self)) return false;

// Call the delegation control contract to check if the delegator has granted access to the delegatee
(bool success, bytes memory data) = SystemCall.call({
caller: delegatee,
resourceSelector: Delegation.unwrap(self),
funcSelectorAndArgs: abi.encodeWithSelector(
IDelegationControl.verify.selector,
delegator,
systemId,
funcSelectorAndArgs
),
value: 0
});

if (!success) return false;
return abi.decode(data, (bool));
}
}
7 changes: 7 additions & 0 deletions packages/world/src/DelegationControl.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// SPDX-License-Identifier: MIT
pragma solidity >=0.8.0;

import { WorldContextConsumer } from "./WorldContext.sol";
import { IDelegationControl } from "./interfaces/IDelegationControl.sol";

abstract contract DelegationControl is WorldContextConsumer, IDelegationControl {}
Loading

0 comments on commit d63e159

Please sign in to comment.