1

When a client sends a transaction he must specify a list of addresses. For those addresses for which are declared as writable, the user must provide a signature. According to the Solana docs, the solana runtime verifies that each signature was signed by the private key corresponding to the public key at the same index in the message's account address array.

What I understand is this, for each account that stores data and we want to modify we must use its corresponding private key to sign the transaction. (not our solana-user-account private key but the data's account pk)

Now the part that confuses me is the signer authority. Can we use this user's private key to sign the transaction rather, allowing the data storage account to me modified ? But doesnt the runtime compares the signature corresponding public key to the public key in the message's account address ? If so then the signer authority is not equal to the writable storage account and so this check would fail.

I've seen other posts saying that signer authority is used by a program (and not the runtime) as a check, kind of like a require (msg.sender == address x) in solidity.

This is all very confusing which is the correct definition for "Authority". Is there perhaps a difference between Authority and Signer Authority ?

I know how owner works so there is no confusion there

1 Answer 1

2

there is a concept called PDAs on Solana. Program derived addresses.

These Accounts can be changed by the program using Seeds. The seeds act somewhat as a private key for these accounts.

#[account(
    init_if_needed,
    seeds = [b"level1"],
    bump,
    payer = signer,
    space = 8 + 1
)]
pub new_game_data_account: Account<'info, GameDataAccount>,

In this case the seeds would be just the string "level1". But it could also be the users account for examples:

#[account(
    init_if_needed,
    seeds = [b"level1", signer.key().as_ref()],
    bump,
    payer = signer,
    space = 8 + 1
)]
pub new_game_data_account: Account<'info, GameDataAccount>,
#[account(mut)]
pub signer: Signer<'info>,

Like this the program can still change the account, but the only way to change it would be to sign with the seeds for the account. Having the account as a "Signer" makes sure that the user needs the private key. So the signer is basically the authority of this account.

You can also do that manually and save the authority in your account like so:

#[account]
pub struct GameDataAccount {
    player_position: u8,
    authority: Pubkey
}

and then you set it when you initialize the account and do the check yourself.

I would recommend play around with it yourself a bit to get a feel for it. Here is a simple example:
https://beta.solpg.io/tutorials/tiny-adventure

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.