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

feat(docs): add security best practices #1070

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

Conversation

a-bahdanau
Copy link
Contributor

@a-bahdanau a-bahdanau commented Nov 22, 2024

Issue

Closes #1069.
Closes tact-lang/tact-docs#72.

Checklist

  • I have updated CHANGELOG.md
  • I have run the linter, formatter and spellchecker
  • I did not do unrelated and/or undiscussed refactorings

@a-bahdanau a-bahdanau requested a review from a team as a code owner November 22, 2024 15:30
@a-bahdanau
Copy link
Contributor Author

Closed all comments from tact-lang/tact-docs#397

@anton-trunov
Copy link
Member

Docs CI is failing


## Insecure random numbers

Note that [`random()`](/ref/core-random#random) function is pseudo-random and depends on [logical time](https://docs.ton.org/develop/smart-contracts/guidelines/message-delivery-guarantees#what-is-a-logical-time). A hacker can predict random by brute-forcing the logical time in the current block.
Copy link
Contributor

@Shvandre Shvandre Nov 24, 2024

Choose a reason for hiding this comment

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

Not really. If a hacker does not own a Validator Node (or does not agreed with validator ) he can do nothing if you yse randomize_lt() before generating a random. And I guess this link should be provided (https://docs.ton.org/v3/guidelines/smart-contracts/security/random-number-generation). It is still not 100% correct but surely better than nothing

Copy link
Contributor

Choose a reason for hiding this comment

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

But no one should use random in external_message receivers. Random there can be hacked even if person is not a Validator and even if you use randomize_lt()

Copy link
Contributor

Choose a reason for hiding this comment

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

However, a commit-and-disclose scheme is sometimes possible. First, both sides generate offchain a number each, and send a hash of their numbers to the contract. After both hashes have arrived, the original numbers can be sent - and their sum can be used, for example, as a randomizer.


##### Do's ✅

Always include and validate a unique identifier, like seqno, to differentiate messages. Update the identifier after successful processing to prevent duplicates.
Copy link
Contributor

Choose a reason for hiding this comment

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

Or, you can implement replay protection like it is done in Highload V3. It is not seqno-based

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