Skip to content
This repository has been archived by the owner on Apr 8, 2020. It is now read-only.

Reimplement random buffer with new runtime api #82

Merged
merged 6 commits into from Sep 24, 2019
Merged

Conversation

janedegtiareva
Copy link
Contributor

No description provided.

@ailisp ailisp mentioned this pull request Sep 12, 2019
assembly/math.ts Outdated
// const lastValue = storage.contains(this._LAST_RANDOM_VALUE_KEY) ? storage.get<u32>(this._LAST_RANDOM_VALUE_KEY) : 0;
// runtime_api.random_seed(0);
// add random seed to last random value
const randomSeed = randomSeed();
Copy link
Contributor

Choose a reason for hiding this comment

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

When this executed the first time we take random seed and add it to itself before hashing. Why do we need to do that?

Also it looks like it can overflow.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

good point, we can do without initializing with random seed.

Copy link
Contributor

Choose a reason for hiding this comment

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

The overflow issue is still present. resultValue[i] + randomSeed[i] can overflow.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

why is that a problem for generating a random buffer?

Copy link
Contributor

Choose a reason for hiding this comment

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

Overflowing is often UB and should be avoided in general. Do we know whether it is going to truncate it at 255, wrap around, take a random number, take some existing byte from the memory (e.g. neighboring byte)? It depends on AssemblyScript implementation and Wasm spec. Having deterministic UB is still bad. E.g. if it truncates it at 255 then this number is not that random and we will have a loop over the same small set of numbers instead of generating new numbers.

Copy link
Contributor

@MaksymZavershynskyi MaksymZavershynskyi left a comment

Choose a reason for hiding this comment

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

Looks good

@janedegtiareva janedegtiareva merged commit 5e9fc6c into master Sep 24, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants