Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Program security - Updated type cosplay lesson #411

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

0xCipherCoder
Copy link
Contributor

Problem

Summary of Changes

  • Updated code snippets with the latest anchor version
  • Fixed content,
  • Fixed grammar and styling
  • Fixed as per guidelines

Fixes #
Unboxed PRs -
Starter - Unboxed-Software/solana-type-cosplay#1
Solution - Unboxed-Software/solana-type-cosplay#2

- Use discriminators to distinguish between different account types
- To implement a discriminator in Rust, include a field in the account struct to
represent the account type
- **Use discriminators** to distinguish between different account types.
Copy link
Collaborator

Choose a reason for hiding this comment

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

We should add:

- Discriminators are data written to account that determines the type of data stored inside

or something similar to make sure people know what they are.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes adding it. Also, should I add a section to explain the concept?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added a bit of explanation in the same line.

Copy link
Collaborator

@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 a good start, but I have a few large-ish questions to resolve before getting it merged.

content/courses/program-security/type-cosplay.md Outdated Show resolved Hide resolved
To solve this, you can add a discriminant field for each account type and set
the discriminant when initializing an account.
To resolve this, add a discriminant field for each account type and set the
discriminant when initializing an account.
Copy link
Collaborator

Choose a reason for hiding this comment

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

More of complaint with the old lesson, but is a discriminant the same thing as a discriminator? This is confusing.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes it's a bit confusing to me as well initially but discriminant manages enum variants internally in the Rust and discriminator is an explicit identifier used to distinguish different account types within Solana programs.

content/courses/program-security/type-cosplay.md Outdated Show resolved Hide resolved
@0xCipherCoder
Copy link
Contributor Author

0xCipherCoder commented Sep 5, 2024

This is a good start, but I have a few large-ish questions to resolve before getting it merged.

@mikemaccana Answered the questions and resolved the comments. Let me know if there is any additional feedback.

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

Successfully merging this pull request may close these issues.

2 participants