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

Random implementation #2481

Closed
wants to merge 9 commits into from
Closed

Random implementation #2481

wants to merge 9 commits into from

Conversation

shargon
Copy link
Member

@shargon shargon commented May 25, 2021

Alternative to #2477 without consensus changes

  • Execution context counter (4 bytes) + hash of the current transaction + hash of the last n blocks (different primary nodes)

@shargon shargon requested a review from erikzhang May 25, 2021 11:35
Copy link
Contributor

@roman-khimov roman-khimov left a comment

Choose a reason for hiding this comment

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

I think it still allows Primary to pre-execute transactions and see how the last block hash affects random number generated and then choose some combination that benefits Primary for some reason. And it also still can generate/insert transaction of its own to see if it allows to win the lottery.

}

// Double Sha256
return BitConverter.ToUInt64(hash.Sha256().Sha256());
Copy link
Contributor

Choose a reason for hiding this comment

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

One hash is enough maybe?

@@ -133,7 +133,8 @@ protected internal ulong GetRandom()
// Block related
for (int count = 0; count < ProtocolSettings.ValidatorsCount; index--, count++)
{
System.Array.Copy(NativeContract.Ledger.GetBlockHash(Snapshot, index).ToArray(), 0, hash, offset + (UInt256.Length * count), UInt256.Length);
var blockHash = count == 0 ? PersistingBlock.Hash : NativeContract.Ledger.GetBlockHash(Snapshot, index);
Copy link
Contributor

Choose a reason for hiding this comment

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

PersistingBlock.Hash is decidable to the primary, this makes the random number not unique.

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

4 participants