5

From the Solana Cookbook, I can tell from the diagram that an Authority can sign transactions on behalf of the account whereas only an Owner can modify it. I can also tell that ownership can be transferred whereas authority remains fixed.

Elsewhere on the internet, I read that you can omit Authority entirely. So what exactly is the use of the idea of Authority? Accounts are always owned by programs that can write to them but in certain situations, they also tend to require signatures from certain authorities, why is that?

As a follow-up, who decides the Authority and Owner of an Account?

2 Answers 2

3

owner can unfortunately mean two things, in the same way that heap can mean multiple things in computer science.

This is how the Solana runtime stores accounts. You will notice that it has an owner field of type Pubkey and a data field that stores bytes. The runtime only allows an account's owner to modify that account's data. So this is the meaning of owner in the context of the runtime.

The other meaning can be best explained with reference to an example. Say you want to write a token program. Users should be able to 'transfer', which decrements their own balance and increments the payee's balance. But they shouldn't be able to arbitrarily change their own balances (else, they would be able to give themselves infinite tokens), which is what would be possible if they owned their balance accounts directly.

So instead, what you can do is have your token program be the owner of balance accounts according to the runtime, and store balance accounts as a tuple of (balance (number), authority (public key)). Then, inside your transfer code, you can check that the authority account has signed this transaction before decrementing their balance and incrementing the payee's balance.

You'll notice that calling it an authority was completely arbitrary; you could have called it something else like owner or user. And indeed, many programs such as the SPL token program do call it owner (src). This is where we get the second meaning of owner.

An analogy you might want to consider is a bank. Ostensibly, you 'own' your bank account. But you can't climb into your bank's database and start changing your balance. You are like the authority over your account; the bank allows you to trigger state transitions, but at the end of the day the bank is the one making the changes in the database.

1
  • 1
    That analogy nailed it. Can you also comment on how ownership is transferred? For example, in the bank analogy, when I make a deposit the bank needs to temporarily "own" the account. How is it accomplished in Solana and are there any limitations one needs to be aware of?
    – Tharsalys
    Commented Nov 4, 2022 at 6:25
0

I saw the clear difference when working with the token swap program:

Before you can create a swap pool, you'll need to create a token swap state account.

const tokenSwapStateAccountInstruction = await Web3.SystemProgram.createAccount({
    newAccountPubkey: tokenSwapStateAccount.publicKey,
    fromPubkey: wallet.publicKey,
    lamports: rent,
    space: TokenSwapLayout.span,
    programId: TOKEN_SWAP_PROGRAM_ID })

then it explains programId which is the owner:

programId must be set to TOKEN_SWAP_PROGRAM_ID. This sets the owner of the new account to be the Token Swap Program itself. The Token Swap Program will need to write data to the new account and so must be set as the owner.

then we need to create Swap Pool Authority

The swap pool authority is the account used to sign for transactions on behalf of the swap program. This account is a Program Derived Address (PDA) derived from the Token Swap Program and the token swap state account.

So the owner is used to write data, authority is used to sign transaction

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.