Skip to content

Commit

Permalink
runtime-sdk: randomize deoxysii nonce in simulation
Browse files Browse the repository at this point in the history
  • Loading branch information
nhynes committed Oct 19, 2022
1 parent 2ae6f57 commit 1ea36a4
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 14 deletions.
29 changes: 15 additions & 14 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions runtime-sdk/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ num-traits = "0.2.14"
impl-trait-for-tuples = "0.2.1"
base64 = "0.13.0"
once_cell = "1.8.0"
rand_core = "0.6.4"
slog = "2.7.0"
tiny-keccak = { version = "2.0", features = ["tuple_hash"] }
tokio = { version = "~1.20", features = ["rt"] }
Expand Down
5 changes: 5 additions & 0 deletions runtime-sdk/src/callformat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use std::convert::TryInto;
use anyhow::anyhow;
use byteorder::{BigEndian, WriteBytesExt};
use oasis_core_runtime::consensus::beacon;
use rand_core::{OsRng, RngCore};

use crate::{
context::Context,
Expand Down Expand Up @@ -206,6 +207,10 @@ pub fn encode_result<C: Context>(
.write_u32::<BigEndian>(index.try_into().unwrap())
.unwrap();
nonce.extend(&[0, 0, 0]);
if ctx.is_simulation() {
// Randomize the lower-order bytes of the nonce to facilitate private queries.
OsRng.fill_bytes(&mut nonce[12..]);
}
let nonce = nonce.try_into().unwrap();
// Serialize result.
let result: CallResult = result.into();
Expand Down

0 comments on commit 1ea36a4

Please sign in to comment.