Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Expose block hash in pallet-contracts #14724

Open
2 tasks done
SkymanOne opened this issue Aug 7, 2023 · 4 comments
Open
2 tasks done

Expose block hash in pallet-contracts #14724

SkymanOne opened this issue Aug 7, 2023 · 4 comments
Labels
J0-enhancement An additional feature request. J2-unconfirmed Issue might be valid, but it’s not yet known.

Comments

@SkymanOne
Copy link

Is there an existing issue?

  • I have searched the existing issues

Experiencing problems? Have you tried our Stack Exchange first?

  • This is not a support question.

Motivation

See use-ink/ink#1849

Request

ink! requires block_hash environment function to be exposed on the pallet-contracts' side:

Solution

No response

Are you willing to help with this request?

Yes!

@SkymanOne SkymanOne added the J0-enhancement An additional feature request. label Aug 7, 2023
@github-actions github-actions bot added the J2-unconfirmed Issue might be valid, but it’s not yet known. label Aug 7, 2023
@agryaznov
Copy link
Contributor

If such a host function is intended to serve as a source of randomness, then for the reasons stated in #13204, I don't think we should expose in the pallet API.

@burdges
Copy link

burdges commented Aug 8, 2023

We removed the collective-flip randomness there, which afaik never really suffices. In theory, you could've whole block fiat-shamir transforms, but this winds up really nasty in practice.

A smart contract parachain could expose VRF based randomness, of which we've two choices:

  1. Slot VRFs - Adversary knows these 6 hours in advance, so they have many choices for their own tx. If otoh an honest user binds their tx to a specific slot, then the adversary has only one choice, accept the tx or not.
  2. Running hash of slot VRFs - We do not currently collect or expose these in polkadot, except at epoch boundaries, but we'll try to change this in sassafras. An adversary spends like 10 n DOTs to have 2^n choices for a running hash of slot VRFs, but their n is bounded by their control over block production, backing, etc.

A smart contract could also create commit-reveal protocols, which work somewhat better in some scenarios, but again require thought.

It all depends somewhat upon what the smart contract chain really does.

@SkymanOne
Copy link
Author

We removed the collective-flip randomness there, which afaik never really suffices. In theory, you could've whole block fiat-shamir transforms, but this winds up really nasty in practice.

A smart contract parachain could expose VRF based randomness, of which we've two choices:

  1. Slot VRFs - Adversary knows these 6 hours in advance, so they have many choices for their own tx. If otoh an honest user binds their tx to a specific slot, then the adversary has only one choice, accept the tx or not.
  2. Running hash of slot VRFs - We do not currently collect or expose these in polkadot, except at epoch boundaries, but we'll try to change this in sassafras. An adversary spends like 10 n DOTs to have 2^n choices for a running hash of slot VRFs, but their n is bounded by their control over block production, backing, etc.

A smart contract could also create commit-reveal protocols, which work somewhat better in some scenarios, but again require thought.

It all depends somewhat upon what the smart contract chain really does.

To sum up what you are saying, it still all comes down to the specific smart contract chain exposing their own randomness interface to the smart contract developer via, let's say, chain extensions, and we should not (or can not) provide a default method of achieving randomness on-chain?

@burdges
Copy link

burdges commented Aug 10, 2023

It feel premature.. At minimum there should be some way to turn it off since there might even bespoke uses for smart contracts where exposing the block hash creates problems.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
J0-enhancement An additional feature request. J2-unconfirmed Issue might be valid, but it’s not yet known.
Projects
None yet
Development

No branches or pull requests

3 participants