Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(world): allow callFrom from own address without explicit delegation #1407

Merged
merged 2 commits into from
Sep 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/silver-mangos-thank.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@latticexyz/world": patch
---

Allow `callFrom` with the own address as `delegator` without requiring an explicit delegation
6 changes: 3 additions & 3 deletions packages/world/gas-report.json
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@
"file": "test/StandardDelegationsModule.t.sol",
"test": "testCallFromCallboundDelegation",
"name": "call a system via a callbound delegation",
"gasUsed": 44074
"gasUsed": 44114
},
{
"file": "test/StandardDelegationsModule.t.sol",
Expand All @@ -249,7 +249,7 @@
"file": "test/StandardDelegationsModule.t.sol",
"test": "testCallFromTimeboundDelegation",
"name": "call a system via a timebound delegation",
"gasUsed": 34779
"gasUsed": 34819
},
{
"file": "test/UniqueEntityModule.t.sol",
Expand Down Expand Up @@ -291,7 +291,7 @@
"file": "test/World.t.sol",
"test": "testCallFromUnlimitedDelegation",
"name": "call a system via an unlimited delegation",
"gasUsed": 17853
"gasUsed": 17893
},
{
"file": "test/World.t.sol",
Expand Down
5 changes: 5 additions & 0 deletions packages/world/src/World.sol
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,11 @@ contract World is StoreRead, IStoreData, IWorldKernel {
bytes32 resourceSelector,
bytes memory funcSelectorAndArgs
) external payable virtual returns (bytes memory) {
// If the delegator is the caller, call the system directly
if (delegator == msg.sender) {
return SystemCall.callWithHooksOrRevert(msg.sender, resourceSelector, funcSelectorAndArgs, msg.value);
}

// Check if there is an explicit authorization for this caller to perform actions on behalf of the delegator
Delegation explicitDelegation = Delegation.wrap(Delegations.get({ delegator: delegator, delegatee: msg.sender }));

Expand Down
21 changes: 21 additions & 0 deletions packages/world/test/World.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -664,6 +664,27 @@ contract WorldTest is Test, GasReporter {
assertEq(returnedAddress, address(this), "subsystem returned wrong address");
}

function testCallFromSelf() public {
// Register a new system
WorldTestSystem system = new WorldTestSystem();
bytes32 resourceSelector = ResourceSelector.from("namespace", "testSystem");
world.registerSystem(resourceSelector, system, true);

address caller = address(1);

// Call a system via callFrom with the own address
vm.prank(caller);
bytes memory returnData = world.callFrom(
caller,
resourceSelector,
abi.encodeWithSelector(WorldTestSystem.msgSender.selector)
);
address returnedAddress = abi.decode(returnData, (address));

// Expect the system to have received the delegator's address
assertEq(returnedAddress, caller);
}

function testCallFromUnlimitedDelegation() public {
// Register a new system
WorldTestSystem system = new WorldTestSystem();
Expand Down