-
Notifications
You must be signed in to change notification settings - Fork 189
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): add support for modules, move logic to RegistrationModule #482
Merged
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
bf221c6
feat(cli): better error message for contract size limit exceeded
alvrs 311ea19
docs(store): fix comment
alvrs f5356b3
feat(world): add support for modules
alvrs bf7cd33
feat(world): add CoreModule
alvrs e43c935
chore: self-review
alvrs 194df28
chore: update gas-report
alvrs 3699464
chore(world): remove unused error
alvrs cac35f5
feat(world): add InstalledModules table to store installed modules
alvrs 486c3b1
refactor(world): rename WithMsgSender to WorldContext
alvrs efec0e7
chore: self-review
alvrs 5b83e73
feat(cli): install World core modules during deployment
alvrs bcff8cb
fix(cli): typo
alvrs 0330fef
chore(world): add github issue to comment
alvrs File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,11 @@ | ||
(test/World.t.sol) | Delete record [world.deleteRecord(namespace, file, singletonKey)]: 16038 | ||
(test/World.t.sol) | Push data to the table [world.pushToField(namespace, file, keyTuple, 0, encodedData)]: 96365 | ||
(test/World.t.sol) | Register a fallback system [bytes4 funcSelector1 = world.registerFunctionSelector(namespace, file, "", "")]: 80896 | ||
(test/World.t.sol) | Register a root fallback system [bytes4 funcSelector2 = world.registerRootFunctionSelector(namespace, file, worldFunc, 0)]: 72123 | ||
(test/World.t.sol) | Register a function selector [bytes4 functionSelector = world.registerFunctionSelector(namespace, file, "msgSender", "()")]: 101493 | ||
(test/World.t.sol) | Register a new namespace [world.registerNamespace("test")]: 151546 | ||
(test/World.t.sol) | Register a root function selector [bytes4 functionSelector = world.registerRootFunctionSelector(namespace, file, worldFunc, sysFunc)]: 96029 | ||
(test/World.t.sol) | Register a new table in the namespace [bytes32 tableSelector = world.registerTable(namespace, table, schema, defaultKeySchema)]: 252073 | ||
(test/World.t.sol) | Write data to a table field [world.setField(namespace, file, singletonKey, 0, abi.encodePacked(true))]: 44704 | ||
(test/World.t.sol) | Set metadata [world.setMetadata(namespace, file, tableName, fieldNames)]: 277121 | ||
(test/World.t.sol) | Write data to the table [Bool.set(tableId, world, true)]: 42576 | ||
(test/World.t.sol) | Delete record [world.deleteRecord(namespace, file, singletonKey)]: 16026 | ||
(test/World.t.sol) | Push data to the table [world.pushToField(namespace, file, keyTuple, 0, encodedData)]: 96397 | ||
(test/World.t.sol) | Register a fallback system [bytes4 funcSelector1 = world.registerFunctionSelector(namespace, file, "", "")]: 80940 | ||
(test/World.t.sol) | Register a root fallback system [bytes4 funcSelector2 = world.registerRootFunctionSelector(namespace, file, worldFunc, 0)]: 72166 | ||
(test/World.t.sol) | Register a function selector [bytes4 functionSelector = world.registerFunctionSelector(namespace, file, "msgSender", "()")]: 101537 | ||
(test/World.t.sol) | Register a new namespace [world.registerNamespace("test")]: 151631 | ||
(test/World.t.sol) | Register a root function selector [bytes4 functionSelector = world.registerRootFunctionSelector(namespace, file, worldFunc, sysFunc)]: 96072 | ||
(test/World.t.sol) | Register a new table in the namespace [bytes32 tableSelector = world.registerTable(namespace, table, schema, defaultKeySchema)]: 252158 | ||
(test/World.t.sol) | Write data to a table field [world.setField(namespace, file, singletonKey, 0, abi.encodePacked(true))]: 44714 | ||
(test/World.t.sol) | Set metadata [world.setMetadata(namespace, file, tableName, fieldNames)]: 277165 | ||
(test/World.t.sol) | Write data to the table [Bool.set(tableId, world, true)]: 42598 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity >=0.8.0; | ||
|
||
library Call { | ||
/** | ||
* Call a contract with delegatecall/call and append the given msgSender to the calldata. | ||
* If the call is successfall, return the returndata as bytes memory. | ||
* Else, forward the error (with a revert) | ||
*/ | ||
function withSender( | ||
address msgSender, | ||
address target, | ||
bytes memory funcSelectorAndArgs, | ||
bool delegate | ||
) internal returns (bytes memory) { | ||
// Append msg.sender to the calldata | ||
bytes memory callData = abi.encodePacked(funcSelectorAndArgs, msgSender); | ||
|
||
// Call the target using `delegatecall` or `call` | ||
(bool success, bytes memory data) = delegate | ||
? target.delegatecall(callData) // root system | ||
: target.call(callData); // non-root system | ||
|
||
// Forward returned data if the call succeeded | ||
if (success) return data; | ||
|
||
// Forward error if the call failed | ||
assembly { | ||
// data+32 is a pointer to the error message, mload(data) is the length of the error message | ||
revert(add(data, 0x20), mload(data)) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,10 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity >=0.8.0; | ||
|
||
contract System { | ||
// Extract the trusted msg.sender value appended to the calldata | ||
function _msgSender() internal pure returns (address sender) { | ||
assembly { | ||
// 96 = 256 - 20 * 8 | ||
sender := shr(96, calldataload(sub(calldatasize(), 20))) | ||
} | ||
} | ||
import { WorldContext } from "./WorldContext.sol"; | ||
|
||
// For now System is just an alias for `WorldContext`, | ||
// but we might add more default functionality in the future. | ||
contract System is WorldContext { | ||
|
||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no changes needed here, but we should be sure to not throw away the original error in case its useful (today or in the future) for debugging
viem has a good example of wrapping errors with nicer messages: https://github.com/wagmi-dev/viem/blob/main/src/errors/contract.ts
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed! In this case the original error message includes the entire bytecode, so it makes your terminal explode and buries the actual error message, but we could add a CLI flag (sth like
--debug
) to print the full error message tooThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(will leave that to a follow PR to not bloat this one too much)