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

Implement ext_random_seed #53

Closed
shawntabrizi opened this issue Apr 15, 2019 · 2 comments · Fixed by #54
Closed

Implement ext_random_seed #53

shawntabrizi opened this issue Apr 15, 2019 · 2 comments · Fixed by #54
Assignees
Labels
A-ink_storage [ink_storage] Work Item B-enhancement New feature or request

Comments

@shawntabrizi
Copy link
Contributor

Add support for ext_random_seed() in PDSL.

As supported in Substrate:
https://github.com/paritytech/substrate/blob/e748c33c8ef40bd51dc122b7f11fcf26b8354957/srml/contract/src/wasm/runtime.rs#L493

ext_random_seed(ctx) => {
	ctx.scratch_buf = ctx.ext.random_seed().encode();
	Ok(())
},
@shawntabrizi shawntabrizi self-assigned this Apr 15, 2019
@Robbepop Robbepop added A-ink_storage [ink_storage] Work Item B-enhancement New feature or request labels Apr 15, 2019
@Robbepop Robbepop changed the title Add random seed Implement ext_random_seed Apr 15, 2019
@xlc
Copy link

xlc commented Apr 15, 2019

We also needs helper methods to make a reasonable secure random number from the seed. i.e. have more entropy incorporated into it like sender account, extrinsic index etc.
And bunch more helper methods to generate randoms numbers from seed and update seeds within the contract.
Because otherwise each contract within a same block will see a same seed and it can be a security issue. e.g. a contract execution can read the seed, determine if it should do something to change the state (top up account balance), to possibly effect the result of following contract execution in the same block (gambling tx will fail if account have no enough balance, but the the previous tx in the same block can top it up if it thinks it is a favorable game in this block).

@shawntabrizi
Copy link
Contributor Author

shawntabrizi commented Apr 17, 2019

@xlc We will do this after Sub0. It totally makes sense to develop a more user friendly, less error prone API, we just need to figure out the specific details.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-ink_storage [ink_storage] Work Item B-enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants