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

[ACP-113] Provable Virtual Machine Randomness #113

Conversation

tsachiherman
Copy link
Contributor

@tsachiherman tsachiherman commented Jun 18, 2024

This PR adds the design document for the Provable Virtual Machine Randomness.

ACP: 113
Title: Provable Virtual Machine Randomness
Author(s): Tsachi Herman <http://github.com/tsachiherman>
Discussions-To: <GitHub Discussion URL (POPULATED BY MAINTAINER, DO NOT SET)>
Status: Proposed
Track: Standards
Replaces (*optional): n/a
Superseded-By (*optional): n/a

Abstract

Avalanche offers developers flexibility through subnets and EVM-compatible smart contracts. However, the platform's deterministic block execution limits the use of traditional random number generators within these contracts.

To address this, a mechanism is proposed to generate verifiable, non-cryptographic random number seeds on the Avalanche platform. This method ensures uniformity while allowing developers to build more versatile applications.

@tsachiherman tsachiherman changed the title ACP-112 : Provable Virtual Machine Randomness ACP-113 : Provable Virtual Machine Randomness Jun 18, 2024

a. If the parent block has a valid `signedParentBlockSig` signature, that signature would be signed using the proposer’s BLS key.

b. If the parent block does not have a valid `signedParentBlockSig` signature, the proposer would sign the bootStrappingBlockSignature with its BLS key ( see below )

Choose a reason for hiding this comment

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

We should clarify whether the hash of:

```
+-------------------------+----------+------------+
|  prefix :               | [8]byte  | "rng-derv" |
+-------------------------+----------+------------+
|  signedParentBlockSig : | [48]byte |  48 bytes  |
+-------------------------+----------+------------+
```

constitutes a "valid signedParentBlockSig signature" since it isn't a signature, it's a hash.

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 replaced the wording of "valid" with empty/non-empty. I think it would better describe the usage.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done


2. The current proposer does not have a BLS key

a. If the parent block has a valid `signedParentBlockSig` signature, the proposer would set the signedParentBlockSig to the hash result of the following preimage:

Choose a reason for hiding this comment

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

Same as above -- what is the set of "valid" signedParentBlockSig?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done


In order to bootstrap the signatures chain, a missing signature would be replaced with a byte slice that is the hash product of a verifiable and trustable seed.

The changes proposed here would affect the way a block is being validated. Therefore, when this change gets implemented, it needs to be deployed as a mandatory upgrade.
Copy link

Choose a reason for hiding this comment

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

it needs to be deployed as a mandatory upgrade.

Is this feature always activated, or would it be possible to opt-in to activate this feature via some kind of voting?
It might be that some subnet/L1 would prefer to not pay the extra overhead.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

A subnet would still be fully usable without having this feature active. From technical perspective, the subnet would need to be configured to set the activation time for this feature to infinity. I think that the technical aspects (how to enabled/disable) of this feature are a bit beyond the scope of this ACP.

@tsachiherman tsachiherman changed the title ACP-113 : Provable Virtual Machine Randomness [ACP-113] Provable Virtual Machine Randomness Aug 5, 2024
Comment on lines 80 to 82
a. If the parent block has an empty `vrfSig` signature, that signature would be signed using the proposer’s BLS key. This is the base case.

b. If the parent block does not have an empty `vrfSig` signature, the proposer would sign the bootStrappingBlockSignature with its BLS key. See the bootStrappingBlockSignature details below.

Choose a reason for hiding this comment

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

Aren't these cases swapped? You bootstrap if the vrfSig is empty right? If its not then you just chain sign.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

correct. fixed.

@@ -0,0 +1,165 @@
```text
Copy link
Contributor

Choose a reason for hiding this comment

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

Would you mind updating the header to use the newly introduced table format?

https://github.com/avalanche-foundation/ACPs/blob/main/ACPs/TEMPLATE.md

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done.


To address this, a mechanism is proposed to generate verifiable, non-cryptographic random number seeds on the Avalanche platform. This method ensures uniformity while allowing developers to build more versatile applications.


Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done.


### Changes Summary

Existing avalanche protocol breaks the block building into two parts : external and internal. The external block is the SnowMan++ block, whereas the internal block is the actual virtual machine block.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
Existing avalanche protocol breaks the block building into two parts : external and internal. The external block is the SnowMan++ block, whereas the internal block is the actual virtual machine block.
The existing Avalanche protocol breaks the block building into two parts : external and internal. The external block is the Snowman++ block, whereas the internal block is the actual virtual machine block.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done.,


To support randomness, a BLS based VRF implementation is used, that would be recursively signing its own signatures as its message. Since the BLS signatures are deterministic, they provide a great way to construct a reliable VRF.

For proposers that do not have a BLS key associated with their node, the hash of the signature from the previous round.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
For proposers that do not have a BLS key associated with their node, the hash of the signature from the previous round.
For proposers that do not have a BLS key associated with their node, the hash of the signature from the previous round is used in place of their signature.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done.


In order to bootstrap the signatures chain, a missing signature would be replaced with a byte slice that is the hash product of a verifiable and trustable seed.

The changes proposed here would affect the way a block is being validated. Therefore, when this change gets implemented, it needs to be deployed as a mandatory upgrade.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
The changes proposed here would affect the way a block is being validated. Therefore, when this change gets implemented, it needs to be deployed as a mandatory upgrade.
The changes proposed here would affect the way a blocks are validated. Therefore, when this change gets implemented, it needs to be deployed as a mandatory upgrade.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done.


2. The current proposer does not have a BLS key

a. If the parent block has a non empty `vrfSig` signature, the proposer would set the proposed block `vrfSig` to the 32 byte hash result of the following preimage:
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
a. If the parent block has a non empty `vrfSig` signature, the proposer would set the proposed block `vrfSig` to the 32 byte hash result of the following preimage:
a. If the parent block has a non-empty `vrfSig` signature, the proposer would set the proposed block `vrfSig` to the 32 byte hash result of the following preimage:

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done.

Comment on lines 103 to 105
| chainID : | [32]byte | 32 bytes |
+-----------------------+----------+------------+
| networkID: | uint32 | 4 bytes |
Copy link
Contributor

Choose a reason for hiding this comment

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

Small nit: It may make more sense to put networkID before chainID here. Existing serializations (for Warp messages, P-Chain txs) that have those fields put them in that order to go from more general to more specific.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

makes sense.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

Validating the `vrfSig` would following this logic:
1. The proposer has a BLS key

a. If the parent block had a non empty `vrfSig`, then a BLS signature verification of the proposed block `vrfSig` would be made against the proposer’s BLS public key and the parent's block `vrfSig` as the message.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
a. If the parent block had a non empty `vrfSig`, then a BLS signature verification of the proposed block `vrfSig` would be made against the proposer’s BLS public key and the parent's block `vrfSig` as the message.
a. If the parent block's `vrfSig` was non-empty , then the `vrfSig` in the proposed block is verified to be a valid BLS signature of the parent block's `vrfSig` value for the proposer's BLS public key.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

thanks. done.

1. The proposer has a BLS key

a. If the parent block had a non empty `vrfSig`, then a BLS signature verification of the proposed block `vrfSig` would be made against the proposer’s BLS public key and the parent's block `vrfSig` as the message.
b. If the parent block does has an empty `vrfSig`, then a BLS signature verification of the proposed block `vrfSig` against the proposer’s BLS public key and bootStrappingBlockSignature would take place.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
b. If the parent block does has an empty `vrfSig`, then a BLS signature verification of the proposed block `vrfSig` against the proposer’s BLS public key and bootStrappingBlockSignature would take place.
b. If the parent block's `vrfSig` was empty, then a BLS signature verification of the proposed block `vrfSig` against the proposer’s BLS public key and bootStrappingBlockSignature would take place.


Before calculating the VRF Out, the method needs to explicitly check the case where the `vrfSig` is empty. In that case, the output of the VRF Out needs to be empty as well.

## Backwards Compatibility
Copy link
Contributor

Choose a reason for hiding this comment

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

You mentioned it above already, but I think the Backwards Compatibility section should also call out that these changes necessitate a required network upgrade.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

np.


However, the effectiveness of this attack is significantly limited for the following reasons:
- Limited options: While colluding attackers expand their potential random number choices, the overall pool remains immense (2^32 possibilities). This drastically reduces their ability to target a specific value.
- Protocol's countermeasure: The protocol automatically eliminates any bias introduced by previous proposals once an honest proposer submits their block.
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we also note that the presence of any bias is detectable and could be exposed in VMs so that applications can choose whether or not to use the resulting random number generated (i.e. only allow its use if it had <= 1 bit bias).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done.

@avalanche-foundation-admin avalanche-foundation-admin merged commit 15c2527 into avalanche-foundation:main Aug 26, 2024
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.

7 participants