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

runtime-sdk: add RNG #1037

Merged
merged 24 commits into from
Dec 9, 2022
Merged

runtime-sdk: add RNG #1037

merged 24 commits into from
Dec 9, 2022

Conversation

nhynes
Copy link
Contributor

@nhynes nhynes commented Jul 6, 2022

This PR adds a VRF-based RNG to the contract and EVM modules.

@codecov
Copy link

codecov bot commented Jul 6, 2022

Codecov Report

Merging #1037 (a7680f3) into main (04944cb) will decrease coverage by 0.60%.
The diff coverage is 48.09%.

@@            Coverage Diff             @@
##             main    #1037      +/-   ##
==========================================
- Coverage   65.18%   64.58%   -0.61%     
==========================================
  Files         134      135       +1     
  Lines       12309    12356      +47     
==========================================
- Hits         8024     7980      -44     
- Misses       4253     4344      +91     
  Partials       32       32              
Impacted Files Coverage Δ
client-sdk/go/modules/contracts/types.go 15.38% <ø> (ø)
contract-sdk-macros/src/error_derive.rs 86.07% <ø> (ø)
contract-sdk-macros/src/event_derive.rs 88.67% <ø> (ø)
contract-sdk/src/abi/env.rs 0.00% <ø> (ø)
contract-sdk/src/testing.rs 10.66% <0.00%> (-0.93%) ⬇️
runtime-sdk-macros/src/error_derive.rs 83.33% <ø> (ø)
runtime-sdk-macros/src/method_handler_derive.rs 93.82% <ø> (ø)
runtime-sdk/modules/contracts/src/lib.rs 66.18% <ø> (ø)
runtime-sdk/modules/evm/src/backend.rs 58.53% <0.00%> (-4.63%) ⬇️
runtime-sdk/src/crypto/random.rs 0.00% <0.00%> (ø)
... and 23 more

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

@nhynes nhynes force-pushed the nhynes/add-rng branch 2 times, most recently from 33622cc to 137e691 Compare July 6, 2022 12:00
@Yawning
Copy link
Contributor

Yawning commented Jul 10, 2022

As a side note:

Do we want to expose a VRF construct somewhere so that it would be easy to make a chainlink VRF knockoff?

I think to do it "correctly", you would need prove, verify, and proof to hash (roughly speaking the chainlink design is a 2-step process: commit to alpha in one step, retrieve pi/beta in another step). This is done so that properly coded applications can prevent users/executors/etc from fishing for an alpha value (because it is committed), to get a beta that produces a desired result.

contract-sdk/src/testing.rs Outdated Show resolved Hide resolved
runtime-sdk/src/crypto/random.rs Outdated Show resolved Hide resolved
runtime-sdk/modules/evm/src/lib.rs Outdated Show resolved Hide resolved
runtime-sdk/modules/evm/src/backend.rs Outdated Show resolved Hide resolved
runtime-sdk/modules/contracts/src/abi/oasis/crypto.rs Outdated Show resolved Hide resolved
runtime-sdk/src/crypto/random.rs Outdated Show resolved Hide resolved
@Yawning
Copy link
Contributor

Yawning commented Sep 27, 2022

should clients provide additional pers strings? it might be more secure if used properly, but will people know (how) to use it?

I like having an integrated way to do domain-separation. The case when nothing is provided should (still) be secure if this is done correctly.

@nhynes nhynes force-pushed the nhynes/add-rng branch 7 times, most recently from 9fb592b to 3e86f5e Compare December 8, 2022 18:44
@@ -19,7 +19,8 @@ hmac = "0.11.0"
sha2 = "0.9.8"
sha3 = { version = "0.10.1", default-features = false }
k256 = { version = "0.10.4" }
schnorrkel = "0.10.2"
schnorrkel = { version = "0.10.2", features = ["asm", "avx2_backend"] }
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I assume these instruction sets are fast and supported (@Yawning).

Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor Author

@nhynes nhynes Dec 9, 2022

Choose a reason for hiding this comment

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

this is why we can't have nice things. I'll disable it :P

4 GHz and ancient SIMD. I don't know what's going on here.

contract-sdk/src/abi/crypto.rs Outdated Show resolved Hide resolved
runtime-sdk/modules/evm/src/backend.rs Show resolved Hide resolved
runtime-sdk/modules/evm/src/lib.rs Outdated Show resolved Hide resolved
runtime-sdk/modules/evm/src/backend.rs Outdated Show resolved Hide resolved
@nhynes nhynes merged commit 8213e8a into main Dec 9, 2022
@nhynes nhynes deleted the nhynes/add-rng branch December 9, 2022 09:26
Copy link
Contributor

@Yawning Yawning left a comment

Choose a reason for hiding this comment

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

I know you merged this, but 2 comments.

impl Default for MockEnv {
fn default() -> Self {
Self {
rng: Arc::new(Mutex::new(XorShiftRng::seed_from_u64(0))),
Copy link
Contributor

Choose a reason for hiding this comment

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

Should this be deterministic?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

it helps if you need to hardcode values into tests or something

@@ -19,7 +19,8 @@ hmac = "0.11.0"
sha2 = "0.9.8"
sha3 = { version = "0.10.1", default-features = false }
k256 = { version = "0.10.4" }
schnorrkel = "0.10.2"
schnorrkel = { version = "0.10.2", features = ["asm", "avx2_backend"] }
Copy link
Contributor

Choose a reason for hiding this comment

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

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.

None yet

5 participants