Skip to content
This repository has been archived by the owner on Jan 24, 2025. It is now read-only.

fix and improve owner-checks course #530

Closed
wants to merge 3 commits into from

Conversation

wuuer
Copy link
Contributor

@wuuer wuuer commented Sep 27, 2024

Problem

Magic number found on space calculation.
Unnecessary parameters are found in the test typescript.
Two Different ways to send transactions are found.

Summary of Changes

Use InitSpace to calculate space needed for accounts.
Delete Unnecessary parameters found in the test typescript.
Consistently use "rpc()" as sending transactions in the test typescript.

Also, I made a PR for solana-owner-checks starter branch and a PR for solana-owner-checks solution branch
which must be synced with this PR.

Jeff Wood and others added 3 commits September 27, 2024 09:58
….InitSpace.html) to calculate space needed for accounts.

Delete Unnecessary parameters found in the test typescript.
Consistently use "rpc()" as sending transactions in the test typescript.
Copy link
Contributor

@mikemaccana mikemaccana left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is another great, PR, we can get it in with a few small tweaks. Please also rebase on top of current main.

@@ -3,45 +3,44 @@ title: Owner Checks
objectives:
- Explain the security risks associated with not performing appropriate owner
checks
- Use Anchor's `Account<'info, T>` wrapper and an account type to automate
- Implement owner checks using long-form Rust
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We use 'native Rust' to mean without Anchor.

owner checks
- Use Anchor's `#[account(owner = <expr>)]` constraint to explicitly define an
- Use Anchors `#[account(owner = <expr>)]` constraint to explicitly define an
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just use ' rather than smart quotes. Do a find/replace.

represents the **program** that owns the account. Owner checks ensure that this
`owner` field in the `AccountInfo` matches the expected program ID.
As a refresher, the `AccountInfo` struct contains the following fields. An owner
check refers to checking that the `owner` field in the `AccountInfo` matches an
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
check refers to checking that the `owner` field in the `AccountInfo` matches an
check refers to checking that the `owner` field matches an

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems clear we're already talking about AccountInfo here.

@@ -81,7 +95,7 @@ declare_id!("Cft4eTTrt4sJU4Ar35rUQHx6PSXfJju3dixmvApzhWws");
#[program]
pub mod owner_check {
use super::*;
...
...
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Check indentation, this may be a tab characters, use four spaces.

```typescript
describe("owner-check", () => {
...
it("Insecure withdraw should be successful", async () => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See 'BDD' in CONTRIBUTING.md, and do that for all tests.

Copy link

This pull request has been automatically marked as stale because it has not had recent activity. Remove stale label or comment or this will be closed in 7 days.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants