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

Programs were not spawned by SystemProgram #1533

Merged

Conversation

jackcmay
Copy link
Contributor

No description provided.

@jackcmay jackcmay requested a review from mvines October 17, 2018 20:37
@jackcmay jackcmay self-assigned this Oct 17, 2018
@jackcmay jackcmay added this to the v0.10 Pillbox milestone Oct 17, 2018
SystemProgram::Spawn => {
if !accounts[0].executable || accounts[0].loader_program_id != Pubkey::default()
{
Err(Error::AssignOfUnownedAccount)?;
Copy link
Member

Choose a reason for hiding this comment

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

AssignOfUnownedAccount: emitting an Assign error from Spawn seems is a little confusing to me

src/system_program.rs Show resolved Hide resolved
src/bank.rs Outdated
// return Err(BankError::ModifiedContractId(instruction_index as u8));

// Make sure that program_id is still the same or this was just assigned by the system call contract
if !(*pre_program_id == account.program_id || SystemProgram::check_id(&tx_program_id)) {
Copy link
Member

Choose a reason for hiding this comment

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

Why change this logic?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Because this logic enforces that the only way for an account's program_id to be changed is if it starts the transaction owned by the SystemProgram. In the case of programs, the Accounts come into the Spawn assigned to the loader.

Copy link
Member

Choose a reason for hiding this comment

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

The negated logic got me, I find this much more readable myself:

Suggested change
if !(*pre_program_id == account.program_id || SystemProgram::check_id(&tx_program_id)) {
if *pre_program_id != account.program_id && !SystemProgram::check_id(&tx_program_id) {

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sounds good, was keeping the rest of the original logic.

}
} else if let Ok(instruction) = deserialize(tx_data) {
match instruction {
LoaderInstruction::Write { offset, bytes } => {
trace!("NativeLoader::Write offset {} bytes {:?}", offset, bytes);
if keyed_accounts[0].account.executable {
Copy link
Member

Choose a reason for hiding this comment

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

This check can be removed right? The bank should enforce that the account is read-only

Copy link
Contributor Author

Choose a reason for hiding this comment

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

How do you propose the loader determine if this is a dispatch or a write/finalize? (This is where call came in handy)

Copy link
Member

Choose a reason for hiding this comment

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

Why does the loader care either way here? If the bank enforces that an account marked executable is read-only then Write doesn’t need to check for executable (or rather if it doesn’t check then no big deal) as the bank would reject the transaction during it’s final verification phase.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sounds good, is that enforcement already in the bank?

Copy link
Member

Choose a reason for hiding this comment

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

I don't think it is, sry!

Copy link
Member

@mvines mvines left a comment

Choose a reason for hiding this comment

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

r+ with a follow-up issue to make the bank enforce immutable executable account userdata.

@jackcmay jackcmay merged commit 0a819ec into solana-labs:master Oct 18, 2018
@jackcmay jackcmay deleted the renable_test_create_spend_wrong_source branch October 18, 2018 17:34
TESLA-SATI pushed a commit to TESLA-SATI/solana that referenced this pull request May 30, 2024
…solana-labs#1533)

* replace `source`, `destination`, and `auditor` variable names in sigma proofs

* replace `source`, `destination`, and `auditor` variable names in elgamal program
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.

2 participants