Skip to content

Commit 1e2b4ad

Browse files
committed
Suggestions from jstarry and buffalojoec
1 parent 2ffbd56 commit 1e2b4ad

File tree

1 file changed

+46
-24
lines changed

1 file changed

+46
-24
lines changed

proposals/0315-loader-v3-v4-migration.md

Lines changed: 46 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ category: Standard
77
type: Core
88
status: Review
99
created: 2024-08-15
10-
feature: 2aQJYqER2aKyb3cZw22v4SL2xMX7vwXBRWfvS4pTrtED
10+
feature: TBD
1111
extends: SIMD-0167
1212
---
1313

@@ -23,20 +23,41 @@ loader-v4.
2323

2424
## Alternatives Considered
2525

26-
None.
26+
### Loader-v1 programs
27+
28+
Programs of loader-v1 have ABI v0, which is incompatible with ABI v1 used
29+
by programs of loader-v2, v3 and v4. Thus there is no way to migrate these.
30+
31+
### Loader-v2 programs
32+
33+
The two loader-v3 accounts per program in their sum are always larger than
34+
the one resulting loader-v4 account. Thus there is no need for additional
35+
funding. This would not be the case when migrating from loader-v2. Meaning
36+
that expanding this SIMD to cover it as well would require a funding source.
37+
38+
### Global Migration: Coordinated in valiator or out of validator
39+
40+
The global migration could be implemented in the validator, however:
41+
42+
- If the global migration mechanism is inside the validator, the risk of it
43+
being detrimental to block production outweights any possible benefits.
44+
- It would have to be coordinated across all validator implementations,
45+
tested, fuzzed, etc. simply a whole lot more work for something which is only
46+
used once.
47+
- It being triggered manually per program or once (via a feature gate) for all
48+
programs changes nothing about it being controlled by a single key.
49+
- The only difference is in having more fine granular control over the
50+
timing in when a specific programs migration is triggered.
51+
- Doing it outside of the validator allows for the process to be aborted or
52+
patched quickly in case things start going sideways.
2753

2854
## New Terminology
2955

3056
None.
3157

3258
## Detailed Design
3359

34-
The feature gate must:
35-
36-
- enable loader-v4 `LoaderV411111111111111111111111111111111111` program
37-
management and execution (see SIMD-0167).
38-
- enable the loader-v3 `BPFLoaderUpgradeab1e11111111111111111111111`
39-
instruction `UpgradeableLoaderInstruction::Migrate`.
60+
The feature gate must enable the new loader-v3 instruction.
4061

4162
### Loader-v3 Instruction: Migrate
4263

@@ -51,8 +72,9 @@ instruction `UpgradeableLoaderInstruction::Migrate`.
5172
otherwise throw `NotEnoughAccountKeys`
5273
- Check that the program data account is writable,
5374
otherwise throw `InvalidArgument`
54-
- Check that the program data was last modified before the current slot
55-
if the program data has the state `ProgramData`,
75+
- Check that the last modified slot (stored in the program data accounts
76+
header) is less than the current slot if the program data has the state
77+
`ProgramData`,
5678
otherwise throw `InvalidArgument`
5779
- Check that the provided authority is either:
5880
- the migration authority
@@ -67,26 +89,26 @@ instruction `UpgradeableLoaderInstruction::Migrate`.
6789
otherwise throw `InvalidArgument`
6890
- Check that the program account is owned by loader-v3,
6991
otherwise throw `IncorrectProgramId`
70-
- Check that the program account has the state `Program`,
71-
otherwise throw `InvalidAccountData`
72-
- Check that the program account points to the program data account,
73-
otherwise throw `InvalidArgument`
74-
- Clear the program account (setting its size to zero)
75-
- Transfer all funds from the program data account to the program account
76-
- Assign ownership of the program account to loader-v4
77-
- If the program data account was not closed / empty or uninitialized:
78-
- CPI loader-v4 `SetProgramLength` the program account to the size of the
79-
program data account minus the loader-v3 header size and use the migration
80-
authority.
92+
- If the program account has the state `Program` and
93+
the referenced program data account is owned by loader-v3:
94+
- Set the length of the program account to 0
95+
- Transfer all funds from the program data account to the program account
96+
- Assign ownership of the program account to loader-v4
97+
- CPI loader-v4 `SetProgramLength` the program account to the program data
98+
account size minus the loader-v3 header size (45 bytes) and use the
99+
provided authority.
81100
- CPI loader-v4 `Copy` the program data account into the program account
82101
- CPI loader-v4 `Deploy` the program account
83102
- If the program data account was finalized (upgrade authority is `None`):
84-
- CPI loader-v4 `Finalize` without a next version forwarding
103+
- CPI loader-v4 `Finalize`
85104
- otherwise, if the program data account was not finalized and the
86105
migration authority (as opposed to the upgrade authority) was provided:
87106
- CPI loader-v4 `TransferAuthority` to the upgrade authority
88-
- Clear the program data account (setting its size to zero)
89-
- Assign ownership of the program data account to the system program
107+
- Set the length of the program data account to 0 (removing the header too)
108+
- otherwise, if the program account is empty, has the state `Buffer` or has
109+
the state `Program` but the program data account is not owned by loader-v3:
110+
- Set the length of the program account to 0
111+
- Set the `is_executable` flag of the program account to `false`
90112

91113
## Impact
92114

0 commit comments

Comments
 (0)