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-modules): register delegation with signature #2480

Merged
merged 76 commits into from
Mar 26, 2024

Conversation

yonadaaa
Copy link
Contributor

@yonadaaa yonadaaa commented Mar 20, 2024

Addresses #2383

This PR adds a new registerDelegationWithSignature function to the World:

function registerDelegationWithSignature(
  address delegatee,
  ResourceId delegationControlId,
  bytes memory initCallData,
  address delegator,
  bytes memory signature
) public onlyDelegatecall;

and a new UserDelegationNonces table, to prevent reply attacks:

UserDelegationNonces: {
  schema: { delegator: "address", nonce: "uint256" },
  key: ["delegator"],
}

Anyone can call registerDelegationWithSignature to register a delegation for delegator, provided that the given EIP-1271 signature is valid (ie. was signed for the same contract address, chain ID, nonce, delegation details etc.)

If the signature is valid, the delegation is created and the nonce is incremented.

Copy link

changeset-bot bot commented Mar 20, 2024

🦋 Changeset detected

Latest commit: 25ed862

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 24 packages
Name Type
@latticexyz/cli Patch
@latticexyz/world-modules Patch
@latticexyz/world Patch
@latticexyz/dev-tools Patch
@latticexyz/store-sync Patch
@latticexyz/store-indexer Patch
@latticexyz/abi-ts Patch
@latticexyz/block-logs-stream Patch
@latticexyz/common Patch
@latticexyz/config Patch
create-mud Patch
@latticexyz/faucet Patch
@latticexyz/gas-report Patch
@latticexyz/protocol-parser Patch
@latticexyz/query Patch
@latticexyz/react Patch
@latticexyz/recs Patch
@latticexyz/schema-type Patch
@latticexyz/services Patch
solhint-config-mud Patch
solhint-plugin-mud Patch
@latticexyz/store Patch
@latticexyz/utils Patch
mock-game-contracts Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@yonadaaa yonadaaa marked this pull request as ready for review March 20, 2024 13:53
@yonadaaa yonadaaa requested review from alvrs and holic as code owners March 20, 2024 13:53
}

function install(bytes memory) public pure {
revert Module_RootInstallNotSupported();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
revert Module_RootInstallNotSupported();
revert Module_NonRootInstallNotSupported();

// If the message was not signed by the delegator or is invalid, revert
address signer = ECDSA.recover(hash, signature);
if (signer != delegator) {
revert InvalidSigner(delegator, delegatee);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think InvalidSignature would be more descriptive here, since the signer would not match the delegator if any piece of the signature doesn't match (delegatee, nonce, etc)

Suggested change
revert InvalidSigner(delegator, delegatee);
revert InvalidSignature(signer);

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

since this file exports a single constant called delegationWithSignatureTypes we should call the file the same

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I want to really make sure it's clear this module is not meant for stable usage yet and we will remove it in the near future once it's audited and moved into the World. Should we rename it to Unstable_DelegationWithSignatureSystem for now?

.changeset/cold-apes-play.md Outdated Show resolved Hide resolved
@yonadaaa yonadaaa changed the title feat(world): register delegation with signature feat(world-modules): register delegation with signature Mar 26, 2024
@alvrs alvrs merged commit e86bd14 into main Mar 26, 2024
12 checks passed
@alvrs alvrs deleted the yonadaaa/register-with-signature branch March 26, 2024 21:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants