Skip to content

fix: add accounts to caip25 permissions when adding chain permissions to ethereum-provider enabled snaps #33111

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

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

adonesky1
Copy link
Contributor

@adonesky1 adonesky1 commented May 21, 2025

Description

This PR updates migration 160 - recently added in #33018 - to add missing account permissions for Snaps with the endowment:caip25 permission.

Previously, when migrating Snaps with an existing endowment:caip25 permission, the accounts associated with that permission were not explicitly carried over to the newly added chainId scope. This change ensures that:

If a Snap already has the endowment:caip25 permission, any accounts previously permissioned under wallet:eip155 are applied to the new scopes added to the permission. This means these accounts will be permissioned for the currentChainId that is being added by the migration.

The corresponding tests in 160.test.ts have been updated to verify this new behavior, ensuring that existing accounts are correctly merged and applied to the relevant chainId scope in the endowment:caip25 permission caveat.

Pre-merge author checklist

Pre-merge reviewer checklist

  • I've manually tested the PR (e.g. pull and build branch, run the app, test code being changed).
  • I confirm that this PR addresses all acceptance criteria described in the ticket it closes and includes the necessary testing evidence such as recordings and or screenshots.

Copy link
Contributor

CLA Signature Action: All authors have signed the CLA. You may need to manually re-run the blocking PR check if it doesn't pass in a few minutes.

@adonesky1 adonesky1 changed the title add accounts to caip25 permissions when adding chain permissions to ethereum-provider enabled snaps fix: add accounts to caip25 permissions when adding chain permissions to ethereum-provider enabled snaps May 21, 2025
@metamaskbot metamaskbot added the INVALID-PR-TEMPLATE PR's body doesn't match template label May 21, 2025
@adonesky1 adonesky1 marked this pull request as ready for review May 21, 2025 21:14
@metamaskbot
Copy link
Collaborator

Builds ready [88c7859]
UI Startup Metrics (1194 ± 63 ms)
PlatformBuildTypePageMetricMean (ms)Min (ms)Max (ms)Std Dev (ms)P 75 (ms)P 95 (ms)
ChromeBrowserifyHomeuiStartup1194108014956312241269
load102992812785710681110
domContentLoaded102192112595710611105
domInteractive15133741524
firstPaint73477126639810501117
backgroundConnect84456823
firstReactRender20155962027
getState1465991929
initialActions001001
loadScripts78366398956816862
setupStore74263811
WebpackHomeuiStartup22461767278120323732640
load17411361205916318602031
domContentLoaded17331357204716118552022
domInteractive161267101443
firstPaint1656334158196294
backgroundConnect2911354343050
firstReactRender16745378114299341
getState2553165618105
initialActions3113246
loadScripts17301356203516018532010
setupStore4573338128309
FirefoxBrowserifyHomeuiStartup12841112183714812951681
load1136969165014211511497
domContentLoaded1136969165014211511497
domInteractive88361772293130
firstPaintNaNNaNNaNNaNNaNNaN
backgroundConnect19126491946
firstReactRender24195162449
getState7419279
initialActions001001
loadScripts1119957162114011381483
setupStore9319820633
WebpackHomeuiStartup15311334228314516191762
load13261154167212614281556
domContentLoaded13261154167112614281556
domInteractive79351441884124
firstPaintNaNNaNNaNNaNNaNNaN
backgroundConnect221483102240
firstReactRender38275154147
getState84315927
initialActions002111
loadScripts13081139165412614121541
setupStore10528628813
cc: @HowardBraham
Benchmark value 24 exceeds gate value 18 for chrome browserify home p95 backgroundConnect
Benchmark value 2247 exceeds gate value 2192 for chrome webpack home mean uiStartup
Benchmark value 1741 exceeds gate value 1711 for chrome webpack home mean load
Benchmark value 1734 exceeds gate value 1704 for chrome webpack home mean domContentLoaded
Benchmark value 1730 exceeds gate value 1699 for chrome webpack home mean loadScripts
Benchmark value 45 exceeds gate value 32 for chrome webpack home mean setupStore
Benchmark value 2640 exceeds gate value 2454 for chrome webpack home p95 uiStartup
Benchmark value 2032 exceeds gate value 2030 for chrome webpack home p95 load
Benchmark value 2022 exceeds gate value 2005 for chrome webpack home p95 domContentLoaded
Benchmark value 2010 exceeds gate value 1970 for chrome webpack home p95 loadScripts
Benchmark value 309 exceeds gate value 65 for chrome webpack home p95 setupStore
Benchmark value 1681 exceeds gate value 1660 for firefox browserify home p95 uiStartup
Benchmark value 1497 exceeds gate value 1495 for firefox browserify home p95 load
Benchmark value 1497 exceeds gate value 1495 for firefox browserify home p95 domContentLoaded
Benchmark value 1483 exceeds gate value 1475 for firefox browserify home p95 loadScripts
Benchmark value 33 exceeds gate value 27 for firefox browserify home p95 setupStore
Benchmark value 39 exceeds gate value 38 for firefox webpack home mean firstReactRender
Sum of mean exceeds: 160ms | Sum of p95 exceeds: 534ms
Sum of all benchmark exceeds: 694ms

@@ -28,7 +28,7 @@ describe(`migration #${version}`, () => {
expect(newStorage.meta).toStrictEqual({ version });
});

it('adds the network endowment to Snaps with the `endowment:ethereum-provider` permission', async () => {
it('adds the `endowment:caip25` permission with the current globally selected chainId (and no accounts) permissioned to Snaps with the `endowment:ethereum-provider` permission and which do not already a `endowment:caip25` permission', async () => {
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
it('adds the `endowment:caip25` permission with the current globally selected chainId (and no accounts) permissioned to Snaps with the `endowment:ethereum-provider` permission and which do not already a `endowment:caip25` permission', async () => {
it('adds the `endowment:caip25` permission with the current globally selected chainId (and no accounts) permissioned to Snaps with the `endowment:ethereum-provider` permission and which do not already have a `endowment:caip25` permission', async () => {

Copy link
Contributor Author

@adonesky1 adonesky1 May 22, 2025

Choose a reason for hiding this comment

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

done here: 483e2f8

Comment on lines 214 to 227
if (subject.permissions[Caip25EndowmentPermissionName]) {
const existingCaveat = subject.permissions[
Caip25EndowmentPermissionName
]?.caveats?.find((caveat) => caveat.type === Caip25CaveatType);
if (existingCaveat && existingCaveat.value) {
const alreadyPermissionedAccounts = getEthAccounts(
existingCaveat.value as Caip25CaveatValue,
);
caip25PermissionCaveatWithCurrentChainIdAndAccountsSet = setEthAccounts(
caip25PermissionCaveatWithCurrentChainIdSet,
alreadyPermissionedAccounts,
);
}
}
Copy link
Member

Choose a reason for hiding this comment

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

This can be deduplicated using the getExistingCaip25PermissionCaveat(subject) above.

Copy link
Contributor Author

@adonesky1 adonesky1 May 22, 2025

Choose a reason for hiding this comment

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

done here: 483e2f8

@adonesky1 adonesky1 requested a review from Mrtenz May 22, 2025 18:16
@adonesky1 adonesky1 force-pushed the ad/add-accounts-in-snaps-switch-chain-migration branch from feb0add to 483e2f8 Compare May 22, 2025 18:19
Mrtenz
Mrtenz previously approved these changes May 22, 2025
@metamaskbot
Copy link
Collaborator

Builds ready [483e2f8]
UI Startup Metrics (1243 ± 68 ms)
PlatformBuildTypePageMetricMean (ms)Min (ms)Max (ms)Std Dev (ms)P 75 (ms)P 95 (ms)
ChromeBrowserifyHomeuiStartup1243109215786812821347
load106895213156511121162
domContentLoaded106194713086511071153
domInteractive1713111101629
firstPaint860146119336210921147
backgroundConnect85295825
firstReactRender21164552233
getState1564792133
initialActions001001
loadScripts815702104463861897
setupStore85182812
WebpackHomeuiStartup21401727271220722722470
load16621359224215717441893
domContentLoaded16561356223815617361883
domInteractive151156101344
firstPaint1706332358212286
backgroundConnect22964102840
firstReactRender15644352105290327
getState1247081430
initialActions317145
loadScripts16521354223615517351872
setupStore3063196418296
FirefoxBrowserifyHomeuiStartup12971108181614713421631
load1146966167813611831482
domContentLoaded1146965167813611831482
domInteractive944826730103161
firstPaintNaNNaNNaNNaNNaNNaN
backgroundConnect19128291934
firstReactRender24207272329
getState11419826812
initialActions0028301
loadScripts1129953166213411671469
setupStore839412626
WebpackHomeuiStartup16081405223017616762011
load13841207196216914501785
domContentLoaded13841207196216914501784
domInteractive81511531986135
firstPaintNaNNaNNaNNaNNaNNaN
backgroundConnect22167382333
firstReactRender41306854449
getState126310301014
initialActions102111
loadScripts13641192194416914341763
setupStore10523323811
cc: @HowardBraham
Benchmark value 1243 exceeds gate value 1234 for chrome browserify home mean uiStartup
Benchmark value 1062 exceeds gate value 1061 for chrome browserify home mean domContentLoaded
Benchmark value 861 exceeds gate value 800 for chrome browserify home mean firstPaint
Benchmark value 25 exceeds gate value 18 for chrome browserify home p95 backgroundConnect
Benchmark value 2470 exceeds gate value 2454 for chrome webpack home p95 uiStartup
Benchmark value 296 exceeds gate value 65 for chrome webpack home p95 setupStore
Benchmark value 12 exceeds gate value 11 for firefox browserify home mean getState
Benchmark value 1384 exceeds gate value 1380 for firefox webpack home mean load
Benchmark value 1384 exceeds gate value 1380 for firefox webpack home mean domContentLoaded
Benchmark value 42 exceeds gate value 38 for firefox webpack home mean firstReactRender
Benchmark value 1364 exceeds gate value 1360 for firefox webpack home mean loadScripts
Benchmark value 2011 exceeds gate value 1935 for firefox webpack home p95 uiStartup
Benchmark value 1785 exceeds gate value 1660 for firefox webpack home p95 load
Benchmark value 1784 exceeds gate value 1660 for firefox webpack home p95 domContentLoaded
Benchmark value 1763 exceeds gate value 1630 for firefox webpack home p95 loadScripts
Sum of mean exceeds: 88ms | Sum of p95 exceeds: 712ms
Sum of all benchmark exceeds: 800ms

@Mrtenz Mrtenz dismissed their stale review May 22, 2025 19:01

Need to test this further.

caip25PermissionCaveatWithCurrentChainIdSet;

if (existingCaip25Caveat) {
const alreadyPermissionedAccounts = getEthAccounts(existingCaip25Caveat);
Copy link
Contributor

Choose a reason for hiding this comment

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

existingPermittedAccounts? or just plain old permittedAccounts? idk. nit.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

switched to existingPermittedAccounts here: 9e3276c


if (existingCaip25Caveat) {
const alreadyPermissionedAccounts = getEthAccounts(existingCaip25Caveat);
if (alreadyPermissionedAccounts) {
Copy link
Contributor

Choose a reason for hiding this comment

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

empty array is always truthy

Copy link
Contributor

Choose a reason for hiding this comment

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

should we leave a comment what this block is trying to achieve? or nah because specs help clarify?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed here + added a comment: 9e3276c

@@ -28,7 +28,7 @@ describe(`migration #${version}`, () => {
expect(newStorage.meta).toStrictEqual({ version });
});

it('adds the network endowment to Snaps with the `endowment:ethereum-provider` permission', async () => {
it('adds the `endowment:caip25` permission with the current globally selected chainId (and no accounts) permissioned to Snaps with the `endowment:ethereum-provider` permission and which do not already have a `endowment:caip25` permission', async () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
it('adds the `endowment:caip25` permission with the current globally selected chainId (and no accounts) permissioned to Snaps with the `endowment:ethereum-provider` permission and which do not already have a `endowment:caip25` permission', async () => {
it('adds the `endowment:caip25` permission with the current globally selected chainId (and no accounts) permissioned to Snaps with the `endowment:ethereum-provider` permission but do not already have a `endowment:caip25` permission', async () => {

?

Copy link
Contributor

Choose a reason for hiding this comment

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

idk

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done here: 9e3276c

@@ -122,7 +122,7 @@ describe(`migration #${version}`, () => {
});
});

it('merges with an existing permission if the Snap already has `endowment:caip25`', async () => {
it('merges with an existing permission and adds existing account permissions along with the current globally selected chainId if the Snap already has `endowment:caip25`', async () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
it('merges with an existing permission and adds existing account permissions along with the current globally selected chainId if the Snap already has `endowment:caip25`', async () => {
it('adds the current globally selected chainId with the existing permitted eth accounts to the existing `endowment:caip25` permission if the Snap already has `endowment:caip25` permission', async () => {

maybe?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done here: 9e3276c

@adonesky1 adonesky1 enabled auto-merge May 22, 2025 20:47
@metamaskbot
Copy link
Collaborator

Builds ready [9e3276c]
UI Startup Metrics (1243 ± 68 ms)
PlatformBuildTypePageMetricMean (ms)Min (ms)Max (ms)Std Dev (ms)P 75 (ms)P 95 (ms)
ChromeBrowserifyHomeuiStartup1243112714036812881368
load107597012556511191209
domContentLoaded106795412486611031199
domInteractive17134151631
firstPaint78580125341910971206
backgroundConnect94437830
firstReactRender20165342128
getState1563482128
initialActions001001
loadScripts82070599366859953
setupStore85162811
WebpackHomeuiStartup20731654270821722062438
load15921288208415316871824
domContentLoaded15861284207515216811816
domInteractive15115291341
firstPaint1707937660209289
backgroundConnect20106782433
firstReactRender14743344111297336
getState145312301224
initialActions316134
loadScripts15821283206515016781805
setupStore5163099420303
FirefoxBrowserifyHomeuiStartup13351154169911014021557
load11841025156211212481388
domContentLoaded11841025156111212481388
domInteractive984127334110163
firstPaintNaNNaNNaNNaNNaNNaN
backgroundConnect211486112131
firstReactRender25205972434
getState75293810
initialActions001001
loadScripts11661013154311212291369
setupStore74376627
WebpackHomeuiStartup14971347185411415791731
load12961169163910313711489
domContentLoaded12951169163910313701489
domInteractive79562672682128
firstPaintNaNNaNNaNNaNNaNNaN
backgroundConnect22157682340
firstReactRender37265254046
getState104759929
initialActions002111
loadScripts12761148161210213551469
setupStore10422922812
Benchmark value 1244 exceeds gate value 1234 for chrome browserify home mean uiStartup
Benchmark value 1076 exceeds gate value 1070 for chrome browserify home mean load
Benchmark value 1068 exceeds gate value 1061 for chrome browserify home mean domContentLoaded
Benchmark value 1369 exceeds gate value 1365 for chrome browserify home p95 uiStartup
Benchmark value 1209 exceeds gate value 1190 for chrome browserify home p95 load
Benchmark value 1199 exceeds gate value 1180 for chrome browserify home p95 domContentLoaded
Benchmark value 1206 exceeds gate value 1180 for chrome browserify home p95 firstPaint
Benchmark value 31 exceeds gate value 18 for chrome browserify home p95 backgroundConnect
Benchmark value 954 exceeds gate value 940 for chrome browserify home p95 loadScripts
Benchmark value 52 exceeds gate value 32 for chrome webpack home mean setupStore
Benchmark value 303 exceeds gate value 65 for chrome webpack home p95 setupStore
Sum of mean exceeds: 43ms | Sum of p95 exceeds: 333ms
Sum of all benchmark exceeds: 376ms

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
INVALID-PR-TEMPLATE PR's body doesn't match template team-wallet-api-platform
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants