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

[Design] Catastrophic enclave failure - Encrypted data recovery #1737

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

StefanIliev545
Copy link
Contributor

Why this change is needed

Please provide a description and a link to the underlying ticket

What changes were made as part of this PR

Please provide a high level list of the changes made

PR checks pre-merging

Please indicate below by ticking the checkbox that you have read and performed the required
PR checks

  • PR checks reviewed and performed

Copy link

coderabbitai bot commented Jan 7, 2024

Walkthrough

The recent update introduces a protocol for recovering enclave secrets after a catastrophic failure. It employs RandomX-based encryption keys, detailing key derivation, publishing rollups, and a bruteforcing mechanism for recovery. The document also addresses security concerns, details how to motivate participants in the bruteforcing effort, and explores potential applications for the collected bruteforcing funds.

Changes

File Path Change Summary
design/.../Design_secret_recovery.md Added a new protocol for enclave state and secret recovery using RandomX-derived encryption keys, with a comprehensive algorithm for key derivation, rollup publication, and bruteforcing for recovery. Discussed security implications, incentives for bruteforcing, and uses for the bruteforcing pot.

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share

Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit-tests for this file.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit tests for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository from git and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit tests.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • The JSON schema for the configuration file is available here.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/coderabbit-overrides.v2.json

CodeRabbit Discord Community

Join our Discord Community to get help, request features, and share feedback.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Review Status

Actionable comments generated: 2

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between b6dada7 and a64fea2.
Files selected for processing (1)
  • design/scratchpad/Design_secret_recovery.md (1 hunks)
Additional comments: 4
design/scratchpad/Design_secret_recovery.md (4)
  • 1-8: The introduction clearly outlines the purpose and high-level approach of the protocol. It sets the context for the reader about the trade-off between privacy and speed of recovery, which is a crucial aspect of the design.

  • 10-12: The section on RandomX is informative and provides a good explanation of why it's chosen for this protocol due to its ASIC resistance and suitability for CPU-based execution.

  • 32-40: The security considerations are well thought out, addressing the randomness of the number within the constrained range and the implications of a state actor with significant resources. It's important to ensure that the assumptions made here are validated with empirical data or expert review.

  • 42-55: The incentivization strategy for bruteforcing is innovative, with a decaying reward structure and the possibility of donations. It's crucial to model the economic incentives and decay rates to ensure they align with the desired outcomes and do not introduce unintended consequences.

Comment on lines +15 to +24
# Algorithm

The sequencer wants to publish a rollup. It picks a random big number `rollup_encryption_seed`. This number is put in the public rollup header that goes on chain.
To derive the encryption key, the rollup initializes an instance of `RandomX` hasher. The `rollup_encryption_seed` is fed into the hasher as the key that would generate the random hashing bytecode.
Once the hasher is initialized, the sequencer needs to derive the `constrained input range` for the hasher. This would be done by using `rollup_encryption_seed` as the input for a `keccak256` hash. The resulting hash can be converted to a `uint256` number.
The converted number is taken as the central point of the `constrained range`. We derieve the range to be `[hashResult-difficulty:hashResult+difficulty]`.
Now the sequencer picks another random number in the `constrained range`. This number is hashed with `RandomX`. The result is the `encryption_secret`.

Now the sequencer can use the `encryption_secret` to derieve an AES256 key and encrypt the rollup. Then its published as it would normally; The header contains the `rollup_encryption_seed` and a keccak256 hash of the `encryption_secret`.

Copy link

Choose a reason for hiding this comment

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

The algorithm for publishing rollups and deriving encryption keys is well-explained. However, it would be beneficial to include pseudocode or a flowchart for better clarity, especially for complex operations like deriving the constrained input range.

Comment on lines +26 to +31
## Bruteforcing

To bruteforce, we have to take the `rollup_encryption_seed` from the header published on chain and derive the `constrained_range` and `RandomX`. Then we have to go through each possible input in the `constrained_range` and hash it with `RandomX`; The result is then hashed through keccak256 and compared the published hash of the `encryption_secret` in the rollup header. This continues until we score a match. The preimage of the keccak256 we have is the `encryption_secret` for the rollup.

Bruteforcing can be done in parallel. With a special orchestrator it can be also done in parallel across many machines. There are up to date online benchmarks for all CPUs and their hash rate for `RandomX` with the monero default params, which we can reuse. Based on those benchmarks we can come up with the initial `difficulty` in terms of expected CPU duration to bruteforce and then convert the duration into a dollar cost based on cloud pricing for similair VMs. The cost should be something we can afford if we ever wanted to bruteforce, but it can also be higher and community subsidized.

Copy link

Choose a reason for hiding this comment

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

The bruteforcing process is described with enough detail to understand the steps involved. It might be helpful to mention any potential optimizations or parallelization limits to set realistic expectations for the recovery time.

@BedrockSquirrel
Copy link
Collaborator

BedrockSquirrel commented Jan 8, 2024

For me the biggest problem with this is that the value of the brute-forcing to an attacker is hard to predict. We re-introduce some serious MEV-style exploits.

If the value of knowing, for example, a random number outcome in some viral game becomes high and people can pay to discover it then it'll be discovered. If we try to price it super-conservatively then we make it super expensive to recover.

And what's more I don't think the network would even know if someone had spent the money to crack it? Whereas with other recovery mechanisms we've talked about it has always been very publicly visible when shenanigans are afoot.

Plus, probably negligible given it would be rare and tiny scale compared to BTC etc., but be a shame to burn a ton of CPU CO2 to recover the network.

That said, I do appreciate any ideas that can help us decentralise some of the protocol stuff, recovery ideas all seem super centralised at the moment.

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

Successfully merging this pull request may close these issues.

2 participants