Owner vs Authority in Solana (2024)

Owner vs Authority in Solana (1)

Newcomers to Solana are frequently confused by the distinction between an “owner” and an “authority.” This article attempts to clear up the confusion as succinctly as possible.

Owner vs Authority

Only programs can write data to accounts — specifically, only to accounts they own. A program cannot write data to arbitrary accounts.

Programs of course cannot spontaneously write data to accounts. They need to receive an instruction to do so from a wallet. However, programs will generally only accept write instructions for a particular account from a privileged wallet: the authority.

An owner of an account is a program. An authority is a wallet. An authority sends a transaction to a program and that program can write to the account.

All accounts in Solana have the following fields, which are mostly self-explanatory:

  • Public Key

  • lamport balance

  • owner

  • executable (a boolean flag)

  • rent_epoch (can be ignored for rent-exempt accounts)

  • data

We can see these by running solana account <our wallet address>in the terminal (with the Solana validator running in the background):

Owner vs Authority in Solana (2)

Note something interesting: we are not the owner of our wallet!The address 111…111 is the system program.

Why does the system program own wallets, instead of wallets owning themselves?

Only the owner of an account can modify the data in it.

The implication is that we are not able to modify our balance directly. Only the system program can do that. To transfer SOL out of our account, we send a signed transaction to the system program. The system program verifies we own the private key to the account, and then it modifies the balance on our behalf.

This is a pattern you will frequently see in Solana: only the owner of the account can modify the data in the account. The program will modify the data in the account if it sees a valid signature from a predesignated address: an authority.

An authority is an address from which a program will accept instructions if it sees a valid signature. An authority cannot modify an account directly. It needs to work through a program that owns the account it is trying to modify.

Owner vs Authority in Solana (3)

However the owner is always a program, and that program will modify the account on behalf of someone else if the signature for the transaction is valid.

We saw this for example, in our tutorial on modifying accounts with different signers.

Exercise: Create a program that initializes a storage account. You will want to have the address of the program and storage accounts handy. Consider adding the following code to the tests:

console.log(`program: ${program.programId.toBase58()}`);console.log(`storage account: ${myStorage.toBase58()}`);

Then run solana account <storage account>on the account that got initialized. You should see the owner being the program.

Here is a screenshot of the exercise being run:

Owner vs Authority in Solana (4)

When we look at the metadata of the storage account, we see the program is the owner.

Because the program owns the storage account, it is able to write to it.Users cannot write to the storage account directly, they sign a transaction and ask the program to write the data.

The owner in Solana is very different from the owner in Solidity

In Solidity, we usually refer to the owner as a special address with admin privileges over the smart contract. The “owner” is not a concept that exists at the Ethereum runtime level, it is a design pattern applied to Solidity contracts. An owner in Solana is much more fundamental. In Ethereum, a smart contract can only write to its own storage slots. Imagine we had a mechanism to allow an Ethereum smart contract to be able to write to some other storage slot. In Solana terms, it would become the owneror those storage slots.

Authority can mean who deployed a contract and who can send write transactions for a particular account

An authoritycan be a construct at the program level. In our tutorial on Anchor signers, we made a program where Alice could deduct points from her account to transfer to someone else. To know that only Alice can send a deduction transaction for that account, we stored her address in the account:

#[account]pubstructPlayer{ points:u32, authority:Pubkey}

Solana uses a similar mechanism to remember who deployed a program. In our tutorial on Anchor deploy, we noted that the wallet that deployed a program is also able to upgrade it.

“Upgrading” a program is the same as writing new data to it — i.e. new bytecode. Only the owner of the program can write to it (this program is BPFLoaderUpgradeableas we will see soon).

Therefore, how does Solana know how to give upgrade privileges to the wallet that deployed a certain program?

Viewing the authority of a program from the command line

Before we deploy the program, let’s see what wallet anchor is using by running solana addressin the terminal:

Owner vs Authority in Solana (5)

Take note that our address is 5jmi...rrTj. Now let’s create a program.

Be sure solana-test-validatorand solana logsare running in the background, then deploy the Solana program:

anchor init owner_authoritycd owner_authorityanchor buildanchor test --skip-local-validator

When we look at the logs, we see the address of the program we just deployed:

Owner vs Authority in Solana (6)

Remember, everything is an account on Solana, including programs. Now let’s inspect this account using the solana account 6Ye7CgrwJxH3b4EeWKh54NM8e6ZekPcqREgkrn7Yy3Tg. We get the following result:

Owner vs Authority in Solana (7)

Note the authority field is absent, because “authority” is not a field that Solana accounts hold. If you scroll up to the top of this article, you will see the keys in the console match the fields we listed at the top of the article.

Here, the “owner” is BPFLoaderUpgradeable111…111, which is the owner of all Solana programs.

Now let’s run solana program show 6Ye7CgrwJxH3b4EeWKh54NM8e6ZekPcqREgkrn7Yy3Tg, where 6Ye7...y3TGis the address of our program:

Owner vs Authority in Solana (8)

In the green box above, we see our wallet address — the one used to deploy the program and what we printed out earlier with solana address:

Owner vs Authority in Solana (9)

But this leads us to an important question…

Where does Solana store the “authority” for the program, which is currently our wallet?

It isn’t a field in an account, so it must be in the datafield of some Solana account. The “authority” is stored in the ProgramData Addresswhere the bytecode of the program is stored:

Owner vs Authority in Solana (10)

Hex encoding of our wallet (the authority)

Before we proceed, it will be helpful to convert the base58 encoding of the ProgramData Addressto a hex representation. The code to accomplish this is provided at the end of the article, but for now we ask the reader to accept that the hex representation of our Solana wallet address 5jmigjgt77kAfKsHri3MHpMMFPo6UuiAMF19VdDfrrTjis:

4663b48dfe92ac464658e512f74a8ee0ffa99fffe89fb90e8d0101a0c3c7767a

Viewing the data in the ProgramData Addressaccount where the executable is stored

We can view the ProgramData Addressaccount with solana account, but we will also send it to a temporary file to avoid dumping too much data to the terminal.

solana account FkYygT7X7qjifdxfBVWXTHpj87THJGmtmKUyU4SamfQm > tempfilehead -n 10 tempfile

The output from the above commands shows our wallet (in hex) embedded into the data. Observe that the yellow underlinedhex code matches the hex encoding of our wallet (the authority):

Owner vs Authority in Solana (11)

The bytecode of a program is stored in a separate account, not the address of the program

This should be implied from the above sequence of commands, but it is worth stating explicitly. Even though the a program is an account that is marked as executable, the bytecode is not stored in its own data field, but in another account (which somewhat confusingly is not executable, it merely stores bytecode).

Exercise: Can you find where the program stores the address of the account that holds the bytecode? The addendum in this article has code that may be useful.

Summary

Only the owner of a program can change its data. The owner of Solana programs is the BPFLoaderUpgradeablesystem program, so by default, the wallet that deployed the program cannot change the data (bytecode) stored in an account.

To enable upgrading programs, the Solana runtime embeds the wallet of the deployer into the bytecode of the program. It refers to this field as the “authority.”

When the deploying wallet tries to upgrade the bytecode, the Solana runtime will check if the transaction signer is the authority. If the transaction signer matches the authority, then the BPFLoaderUpgradeablewill update the bytecode of the program on behalf of the authority.

Addendum: converting base 58 to hex

The following Python code will accomplish the conversion. It was generated by a chatbot, and therefore should only be used for illustrative purposes:

defdecode_base58(bc, length): base58_digits = '123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz' n = 0 forchar inbc: n = n * 58+ base58_digits.index(char) returnn.to_bytes(length, 'big')deffind_correct_length_for_decoding(base58_string): forlength inrange(25, 50): # Trying lengths from 25 to 50 try: decoded_bytes = decode_base58(base58_string, length) returndecoded_bytes.hex() exceptOverflowError: continue returnNone# Base58 string to convertbase58_string = "5jmigjgt77kAfKsHri3MHpMMFPo6UuiAMF19VdDfrrTj"# Convert and get the hexadecimal stringhex_string = find_correct_length_for_decoding(base58_string)print(hex_string)

Learn More with RareSkills

See our Solana development course to learn more Solana topics! For other blockchain topics, please see our blockchain bootcamp.

Owner vs Authority in Solana (2024)
Top Articles
Paying In Local Currency Outside The U.S.? – HSBC Bank USA
Micro Account in Forex:What it Means, How it Works
English Bulldog Puppies For Sale Under 1000 In Florida
Katie Pavlich Bikini Photos
Gamevault Agent
Pieology Nutrition Calculator Mobile
Hocus Pocus Showtimes Near Harkins Theatres Yuma Palms 14
Hendersonville (Tennessee) – Travel guide at Wikivoyage
Compare the Samsung Galaxy S24 - 256GB - Cobalt Violet vs Apple iPhone 16 Pro - 128GB - Desert Titanium | AT&T
Vardis Olive Garden (Georgioupolis, Kreta) ✈️ inkl. Flug buchen
Craigslist Dog Kennels For Sale
Things To Do In Atlanta Tomorrow Night
Non Sequitur
Crossword Nexus Solver
How To Cut Eelgrass Grounded
Pac Man Deviantart
Alexander Funeral Home Gallatin Obituaries
Energy Healing Conference Utah
Geometry Review Quiz 5 Answer Key
Hobby Stores Near Me Now
Icivics The Electoral Process Answer Key
Allybearloves
Bible Gateway passage: Revelation 3 - New Living Translation
Yisd Home Access Center
Pearson Correlation Coefficient
Home
Shadbase Get Out Of Jail
Gina Wilson Angle Addition Postulate
Celina Powell Lil Meech Video: A Controversial Encounter Shakes Social Media - Video Reddit Trend
Walmart Pharmacy Near Me Open
Marquette Gas Prices
A Christmas Horse - Alison Senxation
Ou Football Brainiacs
Access a Shared Resource | Computing for Arts + Sciences
Vera Bradley Factory Outlet Sunbury Products
Pixel Combat Unblocked
Movies - EPIC Theatres
Cvs Sport Physicals
Mercedes W204 Belt Diagram
Mia Malkova Bio, Net Worth, Age & More - Magzica
'Conan Exiles' 3.0 Guide: How To Unlock Spells And Sorcery
Teenbeautyfitness
Where Can I Cash A Huntington National Bank Check
Topos De Bolos Engraçados
Sand Castle Parents Guide
Gregory (Five Nights at Freddy's)
Grand Valley State University Library Hours
Hello – Cornerstone Chapel
Stoughton Commuter Rail Schedule
Nfsd Web Portal
Selly Medaline
Latest Posts
Article information

Author: The Hon. Margery Christiansen

Last Updated:

Views: 6192

Rating: 5 / 5 (70 voted)

Reviews: 93% of readers found this page helpful

Author information

Name: The Hon. Margery Christiansen

Birthday: 2000-07-07

Address: 5050 Breitenberg Knoll, New Robert, MI 45409

Phone: +2556892639372

Job: Investor Mining Engineer

Hobby: Sketching, Cosplaying, Glassblowing, Genealogy, Crocheting, Archery, Skateboarding

Introduction: My name is The Hon. Margery Christiansen, I am a bright, adorable, precious, inexpensive, gorgeous, comfortable, happy person who loves writing and wants to share my knowledge and understanding with you.