Skip to content

Instantly share code, notes, and snippets.

View nikkaroraa's full-sized avatar
👨‍💻
building!

nikhil nikkaroraa

👨‍💻
building!
View GitHub Profile
@nikkaroraa
nikkaroraa / zero-copy-anchor.md
Created May 19, 2022 18:22
zero copy account on solana - via anchor

Zero-copy

Zero-copy is a deserialization technique that creates data structures by borrowing (not copying!) from the array holding the input, avoiding the expensive memory allocation and processing of traditional deserialization. With zero-copy, we can create accounts larger than the size of the stack or heap.

Usage

To enable zero-copy-deserialization, one can pass in the zero_copy argument to the macro as follows:

On Solana, a transaction must specify all accounts required for execution. And because an untrusted client specifies those accounts, a program must responsibly validate all such accounts are what the client claims they are--in addition to any instruction specific access control the program needs to do.

For example, you could imagine easily writing a faulty token program that forgets to check if the signer of a transaction claiming to be the owner of a Token Account actually matches the owner on that account. Furthermore, imagine what might happen if the program expects a Mint account but a malicious user gives a token Account.

To address these problems, Anchor provides several types, traits, and macros. It's easiest to understand by seeing how they're used in an example, but a couple include

Deployment

localnet

source: introduction to programming on solana

  • Use the cargo build-bpf command to compile your program to a file with the so file extension.
  • Run solana-keygen new to create and save a solana keypair locally.
  • Check solana config: make sure the RPC URL is set to http://localhost:8899
    • If it isn't already, do it with solana config set --url http://localhost:8899
  • Fire up your localnet with solana-test-validator
Verify Github on Galaxy. gid:nypSGYEuE2u4NiaoofLQb5

solana-bpf

As shown in the diagram above, a program author creates a program, compiles it to an ELF shared object containing BPF bytecode, and uploads it to the Solana cluster with a special deploy transaction. The cluster makes it available to clients via a program ID. The program ID is an address specified when deploying and is used to reference the program in subsequent transactions.

Upon a successful deployment the account that holds the program is marked executable. If the program is marked "final", its account data become permanently immutable. If any changes are required to the finalized program (features, patches, etc...) the new program must be deployed to a new program ID.

If a program is upgradeable, the account that holds the program is marked executable, but it is possible to redeploy a new shared object to the same program ID, provided that the program's upgrade authority signs the transaction.

The Solana command line interface supports deploying programs,

The latest loader serializes the program input parameters as follows (all encoding is little endian):

  • 8 bytes unsigned number of accounts
  • For each account
    • 1 byte indicating if this is a duplicate account, if not a duplicate then the value is 0xff, otherwise the value is the index of the account it is a duplicate of.
    • If duplicate: 7 bytes of padding
    • If not duplicate:
      • 1 byte boolean, true if account is a signer
      • 1 byte boolean, true if account is writable
  • 1 byte boolean, true if account is executable
@nikkaroraa
nikkaroraa / aws-dynamodb.md
Created March 5, 2021 12:26
AWS DynamoDb
  • keys

  • provisioned throughput

    • Overview
      • RCU (Read Capacity Units) & WCU (Write Capacity Units)
      • Tables must have provisioned read and write capacity units
  • Read Capacity Units (RCU): throughput for reads

@nikkaroraa
nikkaroraa / vscode-settings.json
Created October 20, 2020 13:00
vscode-settings.json
{
// Place your settings in this file to overwrite the default settings
"workbench.settings.editor": "json",
"editor.formatOnSave": false,
"editor.defaultFormatter": "esbenp.prettier-vscode",
"editor.detectIndentation": true,
"editor.fontSize": 18,
"editor.lightbulb.enabled": false,
"editor.parameterHints.enabled": false,
"editor.fontFamily": "'Dank Mono', Menlo, Monaco, 'Courier New', monospace",
@nikkaroraa
nikkaroraa / general-startup.md
Last active October 5, 2020 05:30
General thoughts on startups - Kunal Shah and Bhavin Turakhia

General thoughts on startups - Kunal Shah and Bhavin Turakhia

How much part does curiosity play in being successful?

  • Curiosity is a means to a different end
  • The end is finding insights
  • Insights are shortcuts to big impacts
  • abstractions -> insights -> businesses -> impact
  • most of the indian founders "struggle" their way through, since we are just now aware of the concept of "being curious"
@nikkaroraa
nikkaroraa / aws-monitoring.md
Created October 2, 2020 09:53
AWS Monitoring

AWS Monitoring

Why monitoring is important?

  • Once our applications are deployed, our users don't care how we did it
  • Our users only care that the application is working or not
    • Application latency: will it increase over time?
    • Application outages: customer experience should not be degraded

Monitoring in AWS