Fix native invoke writable privileges#19750
Conversation
84c5619 to
dabef09
Compare
|
Looking now.. But first, can you also add a feature switch? There are two places where this will change behavior:
|
Pull request has been modified.
93d8bf2 to
81ba221
Compare
Pull request has been modified.
Codecov Report
@@ Coverage Diff @@
## master #19750 +/- ##
=========================================
- Coverage 82.5% 82.5% -0.1%
=========================================
Files 476 476
Lines 132822 132964 +142
=========================================
+ Hits 109708 109792 +84
- Misses 23114 23172 +58 |
* Fix native invoke writable privileges * build downstream spl bpf programs for tests (cherry picked from commit 00d7981) # Conflicts: # program-runtime/src/instruction_processor.rs # runtime/src/message_processor.rs # sdk/src/feature_set.rs
|
This all boils down to this, right? let caller_keyed_accounts = invoke_context.get_keyed_accounts()?;
let mut caller_write_privileges = Vec::with_capacity(message.account_keys.len());
if invoke_context.is_feature_active(&fix_write_privs::id()) {
for key in message.account_keys.iter() {
let index = caller_keyed_accounts
.iter()
.position(|keyed_account| keyed_account.unsigned_key() == key)
.ok_or(InstructionError::MissingAccount)?;
caller_write_privileges.push(caller_keyed_accounts[index].is_writable());
}
} else {
caller_write_privileges.push(false);
for index in keyed_account_indices.iter() {
caller_write_privileges.push(caller_keyed_accounts[*index].is_writable());
}
// caller_write_privileges.insert(0, false);
}And because let callee_keyed_accounts = keyed_account_indices
.iter()
.map(|index| keyed_account_at_index(caller_keyed_accounts, *index))
.collect::<Result<Vec<&KeyedAccount>, InstructionError>>()?;
let (message, callee_program_id, _) = Self::create_message(
&instruction,
&callee_keyed_accounts,
signers,
&invoke_context,
)?;The only real difference remaining is the: @jackcmay Do we have a test to highlight the difference? Because I have my doubts that this change actually changes anything (except for the first entry and thus everything being shifted by one). |
|
Found the new test: And the flaw in my reasoning: But then the question is: Why do we even pass |
|
We may not need to pass |
|
Here, I refactored it already but still waiting for CI tests: I think |
|
That would be nice to consolidate |
* Fix native invoke writable privileges * build downstream spl bpf programs for tests (cherry picked from commit 00d7981) # Conflicts: # program-runtime/src/instruction_processor.rs # runtime/src/message_processor.rs # sdk/src/feature_set.rs
* Fix native invoke writable privileges * build downstream spl bpf programs for tests (cherry picked from commit 00d7981) # Conflicts: # program-runtime/src/instruction_processor.rs # runtime/src/message_processor.rs # sdk/src/feature_set.rs
* Fix native invoke writable privileges * build downstream spl bpf programs for tests (cherry picked from commit 00d7981) # Conflicts: # program-runtime/src/instruction_processor.rs # runtime/src/message_processor.rs # sdk/src/feature_set.rs
* Fix native invoke writable privileges (#19750) * Fix native invoke writable privileges * build downstream spl bpf programs for tests (cherry picked from commit 00d7981) # Conflicts: # program-runtime/src/instruction_processor.rs # runtime/src/message_processor.rs # sdk/src/feature_set.rs * resolve conflictds Co-authored-by: Jack May <jack@solana.com>
Addressed in #19762 |
* Fix native invoke writable privileges * build downstream spl bpf programs for tests
This reverts commit 9976d72.
Problem
Caller write privileges are not created correctly for native cpi. The
caller_write_privilegesvector should match up withmessage.account_keysbecause they will be indexed the same.Summary of Changes
accountsvector built frommessage.account_keysFix sourced from: #18616, thanks @jstarry !
Fixes #18629