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

chore(boundary): salt_sharing canister implementation #3650

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

nikolay-komarevskiy
Copy link
Contributor

@nikolay-komarevskiy nikolay-komarevskiy commented Jan 28, 2025

Provide all API boundary nodes with the same secret salt to anonymize the IP addresses and the sender principals when logging the incoming requests.

@github-actions github-actions bot added the chore label Jan 28, 2025
@nikolay-komarevskiy nikolay-komarevskiy force-pushed the komarevskiy/salt-canister-interface branch 2 times, most recently from 23696f2 to 0227c73 Compare January 28, 2025 13:08
@nikolay-komarevskiy nikolay-komarevskiy force-pushed the komarevskiy/salt-canister-interface branch from 0227c73 to b788460 Compare January 28, 2025 13:30
Comment on lines 29 to 30
pub static LAST_SALT_NS: RefCell<StableMap<(), Timestamp>> = RefCell::new(StableMap::init(
MEMORY_MANAGER.with(|m| m.borrow().get(MEMORY_ID_LAST_SALT_MS)),
Copy link
Contributor

Choose a reason for hiding this comment

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

Mismatch in naming:
LAST_SALT_NS vs. MEMORY_ID_LAST_SALT_MS

regenerate_salt();
}
// Start salt generation schedule based on the argument.
if let Some(strategy) = init_arg.salt_generation_strategy {
Copy link
Contributor

Choose a reason for hiding this comment

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

If we set the strategy again, will it cancel the old timer or will it then have two timers: then one from before and the new one?

Copy link
Contributor Author

@nikolay-komarevskiy nikolay-komarevskiy Jan 28, 2025

Choose a reason for hiding this comment

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

When the canister is upgraded all existing timers will be stopped. and should be restarted manually. That's why there is a call to init in the post_upgrade.

static RNG: RefCell<ChaCha20Rng> = {
let mut seed = [42; 32];
seed[..8].copy_from_slice(&time().to_le_bytes());
RefCell::new(ChaCha20Rng::from_seed(seed))
Copy link
Contributor

Choose a reason for hiding this comment

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

This is quite predicable; at worst an attacker just has to iterate over timestamps near where they think the canister started.

Getting randomness can be done by accessing the random beacon. This is at least more random than the time. But I'm not sure if other canisters on the same subnet see the same beacon value or not. [Made a query on internal channels on this]

What I'd suggest is modifying the interface such that BN can "contribute" randomness to the canister whenever they contact it, since they have access to "real" randomness. For example by just sending a 256-bit string they generated using their local RNG (/dev/random or whatever). Then the canister takes that input plus the current internal seed, computes SHA-256 of both, then uses that as the new seed value. As soon as 2 or more honest boundary nodes have contacted the canister, the randomness of the canisters state is unknown to everyone except the node providers running that subnet.

Copy link
Contributor

Choose a reason for hiding this comment

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

Per @andreacerulli each canister will see a different value for the random beacon so that should be sufficient without having to do a BN randomness contribution scheme like I outlined above

Copy link
Contributor Author

@nikolay-komarevskiy nikolay-komarevskiy Jan 28, 2025

Choose a reason for hiding this comment

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

Interesting idea. That would require the following logic in the canister and nodes:

  • collect N>=2 random secrets from nodes via update calls
  • generate the final seed based on canister's own secret + N collected secrets
  • generate the shared salt based on the final seed and start serving salt
  • nodes need additional logic to stop "contributing" and just fetch the shared salt

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

Successfully merging this pull request may close these issues.

3 participants