Skip to content

dkcumming/solana-contact-memory

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Solana Logger Program

Start a Local Validator

Do this in a different terminal

solana-test-validator --reset

Configure Solana CLI for Localhost

Need to connect to local validator not mainnet or devnet etc.

solana config set --url http://localhost:8899
solana config get # to confirm

Start Log Stream

Do this in a different terminal again

solana logs

Build Smart Contract

Creates solana_logger_program.so in target/deploy/

cd program
cargo-build-sbf
# or specify version
cargo-build-sbf --arch v3

Check Program Size

Will need this if you are redeploying to make sure you have enough space in your account

ls -la target/deploy/solana_logger_program.so

Deploy Smart Contract

Will return the address your smart contract is at

solana program deploy target/deploy/solana_logger_program.so

Check On-Chain Program Size

Shoes details of the program (like data length)

solana program show <PROGRAM_PUBKEY>

Dump Program from Chain

In case you want to analyse a program from the chain

solana program dump <PROGRAM_PUBKEY> dumped_program.so

Increase Program Account Size

To resize the program so it can fit a larger program

solana program extend <PROGRAM_PUBKEY> <BYTES_TO_ADD>

Redeploy Smart Contract

Writing the buffer will give a pubkey that to that buffer, you then move from buffer to account

cd program
cargo-build-sbf
solana program write-buffer target/deploy/solana_logger_program.so
solana program upgrade <BUFFER_PUBKEY> <PROGRAM_PUBKEY>

Invoke Smart Contract

Inside client/src/main.rs there is the logic to form the Instructions and Transaction and submit it

cd client
cargo run

Disassemble Smart Contract Binary

Lifts the binary into sBPF bytecode instructions

agave-ledger-tool program disassemble target/deploy/solana_logger_program.so

About

A simple smart contract that logs some information about memory. The recommended way to go through this is in chronological order of commits. Commit 1. logs a simple message. Commit 2. prints out memory addresses of data in the different sections. Commit 3. adds a Use-After-Free example. Commit 4. Adds a Buffer-Overflow example.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Languages