-
Notifications
You must be signed in to change notification settings - Fork 43
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 Values provider #166
Merged
Merged
Changes from all commits
Commits
Show all changes
102 commits
Select commit
Hold shift + click to select a range
f2e29fd
Added initial code for random number generation
drinkcoffee 8405ce9
Improve documentation
drinkcoffee fd3644b
forge install: openzeppelin-contracts-upgradeable
drinkcoffee 33aff29
forge install: openzeppelin-contracts
drinkcoffee c2d6506
Added remappings
drinkcoffee cb56dbe
forge install: openzeppelin-contracts
drinkcoffee 1ea3540
forge install: openzeppelin-contracts-upgradeable
drinkcoffee e03392a
forge install: seaport
drinkcoffee 426407a
Remove incorrect version of seaport
drinkcoffee 545f341
forge install: seaport
drinkcoffee 015c4f2
Temporarily remove trading contracts
drinkcoffee acdca5a
forge install: solidity-bits
drinkcoffee 4a3f1a0
forge install: solidity-bytes-utils
drinkcoffee f11f239
Fixed compilation issues
drinkcoffee d10d6ba
Initial doc
drinkcoffee 87952c8
Update docs
drinkcoffee 8c03abf
Separated use of RANDAO
drinkcoffee b6a7956
Re-add trading
drinkcoffee 73b8569
forge install: seaport-core
drinkcoffee 9a57a6f
Rework seaport installs
drinkcoffee ff3b4b1
forge install: seaport-core
drinkcoffee f6b2a98
Fix import path
drinkcoffee 3678fe9
forge install: seaport-types
drinkcoffee 5e21128
Lib issue
drinkcoffee db07799
forge install: seaport-types
drinkcoffee 8bc1cf2
Remove old seaport
drinkcoffee 61adf8f
forge install: seaport
drinkcoffee e3a117c
Switch seaport version
drinkcoffee db8e31e
forge install: seaport
drinkcoffee cbb5ded
Switch to RandomSeedProvider
drinkcoffee 8d4b47a
forge install: seaport
drinkcoffee 14d6ae4
Rework seaport version
drinkcoffee b58eed2
Added seaport
drinkcoffee 57710bb
Remove seaport
drinkcoffee 0519516
Remove seaport
drinkcoffee 236c518
Remove seaport lib directory
drinkcoffee 1c30b08
Re-designed based on integration with chainlink
drinkcoffee aa82b49
Initial test plan
drinkcoffee 2034b99
Revised documentation. Added allow listing
drinkcoffee b245fd7
Initial tests
drinkcoffee 7515b9f
Add more tests
drinkcoffee f0bc1f1
Compiling
drinkcoffee 3c29314
Fixed most of the build process for hardhat
drinkcoffee 02f8980
Added more tests
drinkcoffee b0b8de3
Add more tests
drinkcoffee fbab874
Add more tests
drinkcoffee f875646
Rename tests
drinkcoffee e963736
Improve documentation
drinkcoffee 26b4991
Clean compile on hardhat and forge.
drinkcoffee d3db1ae
Added more tests
drinkcoffee f231404
Improve test coverage
drinkcoffee f286c00
Emit events when adding offchain consumers
drinkcoffee 68db3d5
RandomSeedProvider and RandomValues: 100% coverage
drinkcoffee 6a3f5bf
Remove coverage report
drinkcoffee 58eca56
Improve documentation
drinkcoffee 36ec087
Improve documentation
drinkcoffee e17ea3d
Added initial version of Supra source adaptor
drinkcoffee a0aadd7
Add initial chainlink tests
drinkcoffee 6110ec2
Run prettier
drinkcoffee c4c87c8
Fix test failure
drinkcoffee aaabda0
Add more tests
drinkcoffee 7300f87
Completed chainlink tests
drinkcoffee e246a89
Switch to UUPS and added upgrade tests
drinkcoffee 27eec2e
Added tests for supra adaptor
drinkcoffee 5db497d
Improve documentation
drinkcoffee 3356fce
Revert prettier changes across repo
drinkcoffee e1caa1b
Merged main
drinkcoffee 19eb7a7
Revert prettier changes
drinkcoffee a43fad6
Remove package lock file
drinkcoffee c6ca3da
Fixed yarn merge issue
drinkcoffee 61abd47
Ensure source used checking if a value is ready is the source supplie…
drinkcoffee f70d093
Remove chainlink package and instead include just the file needed
drinkcoffee d219997
Show version during forge test. Remove yarn install
drinkcoffee fcc02d1
Add more debug to github actions
drinkcoffee 7626c5a
Add more debug to github actions
drinkcoffee 5049c56
Fixed yaml format error
drinkcoffee b8628b4
Add more debug
drinkcoffee 476ec56
Fixed capitalisation of directory name
drinkcoffee 2b754da
Separate eslint and solhint
drinkcoffee 11a9c13
Fix yarn scripts
drinkcoffee 5f5bfdc
Fix so that eslint and solhint will now run in github actions
drinkcoffee 9813597
Fix linter issues
drinkcoffee f33554f
Linter errors no longer show failure on github actions
drinkcoffee 5076a2d
Improve readability
drinkcoffee 3c80c72
Fixed documentation reflect the change from transparent upgrade proxy…
drinkcoffee 89f3dda
Fix typos and improve documentation
drinkcoffee d39e5e9
Improved documentation
drinkcoffee 6fe6f29
Switch to using block.hash rather than block.number for initial rando…
drinkcoffee cd5d9ba
Fix call to blockhash
drinkcoffee 9dd9310
Fixed tests for initial seed values
drinkcoffee c895236
Merge branch 'main' into random
drinkcoffee 7893007
Fixed subscription typo
drinkcoffee ce60b7a
Removed extra hashing for _fetchRandomValue
drinkcoffee e3775c6
Switch to Australian spelling of fulfilment for all random number rel…
drinkcoffee 7a252e9
Fix slither issue: make VRF coordinator an immutable variable
drinkcoffee 956c7ac
Set the initial version to the constant defining VERSION 0. This also…
drinkcoffee b26db2f
Resolve slither issues
drinkcoffee 7c55aa0
Change RandomValues API to specify number of random numbers to be ret…
drinkcoffee f4876bd
Added explicit mapping for seaport types
drinkcoffee ae015c4
Update contracts/random/README.md
drinkcoffee 5d95ea3
Update contracts/random/RandomSeedProvider.sol
drinkcoffee 86e43a3
Switch naming from traditional to onchain in situations when the gene…
drinkcoffee File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,3 +15,6 @@ dist/ | |
|
||
# Forge files | ||
foundry-out/ | ||
|
||
# Apple Mac files | ||
.DS_Store |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,21 @@ | ||
[submodule "lib/forge-std"] | ||
path = lib/forge-std | ||
url = https://github.com/foundry-rs/forge-std | ||
[submodule "lib/solidity-bits"] | ||
path = lib/solidity-bits | ||
url = https://github.com/estarriolvetch/solidity-bits | ||
[submodule "lib/solidity-bytes-utils"] | ||
path = lib/solidity-bytes-utils | ||
url = https://github.com/GNSPS/solidity-bytes-utils | ||
[submodule "lib/openzeppelin-contracts-4.9.3"] | ||
path = lib/openzeppelin-contracts-4.9.3 | ||
url = https://github.com/OpenZeppelin/openzeppelin-contracts | ||
[submodule "lib/openzeppelin-contracts-upgradeable-4.9.3"] | ||
path = lib/openzeppelin-contracts-upgradeable-4.9.3 | ||
url = https://github.com/OpenZeppelin/openzeppelin-contracts-upgradeable | ||
[submodule "lib/immutable-seaport-1.5.0+im1.3"] | ||
path = lib/immutable-seaport-1.5.0+im1.3 | ||
url = https://github.com/immutable/seaport | ||
[submodule "lib/immutable-seaport-core-1.5.0+im1"] | ||
path = lib/immutable-seaport-core-1.5.0+im1 | ||
url = https://github.com/immutable/seaport-core |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,56 @@ | ||
{ | ||
"extends": "solhint:recommended", | ||
"plugins": ["prettier"], | ||
|
||
"rules": { | ||
"prettier/prettier": "error", | ||
"compiler-version": ["error", "^0.8.0"], | ||
"func-visibility": ["warn", { "ignoreConstructors": true }] | ||
}, | ||
"plugins": ["prettier"] | ||
"code-complexity": ["warn", 7], | ||
"custom-errors": "error", | ||
"explicit-types": ["error"], | ||
"function-max-lines": ["off", 50], | ||
"max-line-length": ["off", 120], | ||
"max-states-count": ["off", 15], | ||
"no-console": "error", | ||
"no-empty-blocks": "warn", | ||
"no-global-import": "warn", | ||
"no-unused-import": "warn", | ||
"no-unused-vars": "warn", | ||
"one-contract-per-file": "warn", | ||
"payable-fallback": "warn", | ||
"reason-string": ["warn", {"maxLength": 32}], | ||
"constructor-syntax": "warn", | ||
|
||
"comprehensive-interface": "off", | ||
"quotes": ["error", "double"], | ||
|
||
"const-name-snakecase": "warn", | ||
"foundry-test-functions": ["off", ["setUp"]], | ||
"func-name-mixedcase": "warn", | ||
"modifier-name-mixedcase": "warn", | ||
"named-parameters-mapping": "warn", | ||
"named-return-values": "off", | ||
"private-vars-leading-underscore": ["off", {"strict": false}], | ||
"use-forbidden-name": "warn", | ||
"var-name-mixedcase": "warn", | ||
"imports-on-top": "warn", | ||
"visibility-modifier-order": "warn", | ||
|
||
"avoid-call-value": "error", | ||
"avoid-low-level-calls": "error", | ||
"avoid-sha3": "error", | ||
"avoid-suicide": "error", | ||
"avoid-throw": "error", | ||
"avoid-tx-origin": "error", | ||
"check-send-result": "error", | ||
"compiler-version": ["error", "0.8.19"], | ||
"func-visibility": ["error", {"ignoreConstructors": true}], | ||
"multiple-sends": "warn", | ||
"no-complex-fallback": "warn", | ||
"no-inline-assembly": "warn", | ||
"not-rely-on-block-hash": "warn", | ||
"not-rely-on-time": "warn", | ||
"reentrancy": "warn", | ||
"state-visibility": "warn", | ||
|
||
"prettier/prettier": "error" | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
# Random Number Generation | ||
|
||
This directory contains contracts that provide random number generation capability using on-chain and off-chain sources. | ||
|
||
The reasons for using these contracts are that: | ||
|
||
* Enables you to leverage a random number generation system designed by Immutable's cryptographers. | ||
* Allows you to build your game against an API that won't change. | ||
* The quality of the random numbers generated will improve as new capabilities are added to the platform. That is, the migration from ```block.hash``` to ```block.prevrandao``` when the BFT fork occurs will be seamless. | ||
* For off-chain randomness, allows you to leverage the random number provider that Immutable has agreements with. | ||
|
||
# Status | ||
|
||
Contract audits: | ||
|
||
| Description | Date |Version Audited | Link to Report | | ||
|---------------------------|------------------|-----------------|----------------| | ||
| Not audited | - | - | - | | ||
|
||
Deployments: | ||
|
||
| Location | Version Deployed | Address | | ||
|---------------------------|------------------|---------| | ||
| Immutable zkEVM Testnet | Not deployed | - | | ||
| Immutable zkEVM Mainnet | Not deployed | - | | ||
|
||
## Architecture | ||
|
||
The Random Number Generation system on the immutable platform is shown in the diagram below. | ||
|
||
 | ||
|
||
Game contracts extend ```RandomValues.sol```. This contract interacts with the ```RandomSeedProvider.sol``` contract to request and retreive random seed values. | ||
|
||
There is one ```RandomSeedProvider.sol``` contract deployed per chain. Each game has its own instance of ```RandomValues.sol``` as this contract is integrated directly into the game contract. | ||
drinkcoffee marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
The ```RandomSeedProvider.sol``` operates behind a transparent proxy, ```ERC1967Proxy.sol```, with the upgrade | ||
logic included in the ```UUPSUpgradeable.sol``` contract that ```RandomSeedProvider.sol``` extends. Using an upgradeable pattern allows the random manager contract to be upgraded to extend its feature set and resolve issues. | ||
|
||
The ```RandomSeedProvider.sol``` contract can be configured to use an off-chain random number source. This source is accessed via the ```IOffchainRandomSource.sol``` interface. To allow the flexibility to switch between off-chain random sources, there is an adaptor contract between the offchain random source contract and the random seed provider. | ||
|
||
The architecture diagram shows a ChainLink VRF source and a Supra VRF source. This is purely to show the possibility of integrating with one off-chain service and then, at a later point choosing to switch to an alternative off-chain source. At present, there is no agreement to use any specific off-chain source. | ||
|
||
|
||
|
||
## Process of Requesting a Random Number | ||
|
||
The process for requesting a random number is shown below. Players do actions requiring a random number or a set of random numbers. They purchase, or commit to the random value(s), which is later revealed. | ||
|
||
 | ||
|
||
The steps are: | ||
|
||
* The game contract calls ```_requestRandomValueCreation```. | ||
The ```_requestRandomValueCreation``` returns a value ```_randomRequestId```. This value is supplied later to fetch the random value once it has been generated. The function ```_requestRandomValueCreation``` executes a call to the ```RandomSeedProvider``` contract requesting a seed value be produced. | ||
* The game contract calls ```_isRandomValueReady```, passing in the ```_randomRequestId```. This returns ```READY``` if the value is ready to be returned. | ||
* The game contract calls ```_fetchRandomValues```, passing in the ```_randomRequestId```. The random seed is returned to the ```RandomValues``` contract, which then customises the value prior returning it to the game. | ||
|
||
|
||
# Notes | ||
|
||
Sequence diagram source [here](https://sequencediagram.org/index.html#initialData=C4S2BsFMAICUEMB2ATA9gW2gOQK7oEaQBO0A4pIsfKKogFB0AO8RoAxiM4sAOZGo5G0AMTgQPABa8ikCtABU80vHSRFTFu05Jg0AETLV0ADKoeINgDoAzqnB7o8a2RWQNrC9u76EKDADV4cBxIaxs7Byc4fzoKZHctLmkBIVFxKXxgmEUASXR0HGB4TJgALwBrAFF-AFkAHUQcxAAzIidgIhw2YBwZdWYPDiSfJDR0AGVZZAAFfgA3EGRicPtHZ1ga2JQGPhToafB4AE9iaEZetgknUMdoNr9MeG6QWjpDSABaAD5YfwAuaAAfRkAEcQtZgL4xoEsgBhGTUF6IAAUgOsIFKkAAlHRft8NgDQeDIaMMJNIMhkTjfgAeD4fAlA5o4cDNEDgVTcHLIAA0QNsFzc7zpDP+QPuY1gkDBoWA3K28ToiFQwBgqDmp3ePIJAHV4GBoM1UCR4NBMqg2OVoMBUGaYIx+MguhToMbHIhXc1mh9LvqPRKMNbbYRoEsxBqZMhLDt+IJoLCJJBLXdSZg5kEQtAQM4Ecgjm9XPixYDs1CAhnIFL4HnUQH0FKZRDudT-PiagDS6nycgqzWGoDmaz2Zy5bz+QIiGxsbj-CLGR0QgXVHOxbBKgBBAAiAE0FTG9u9Q5Bw8RnAB6O6QDVBHOpxzPV7vIsAgeQYCXMvoGHg2uphvE5sZzbAEeDfT9u2RftBzZDkKFHPk0QnKcWzndtxS7KYgJ+MVplPWggmzGA62gRA8EIEgGnwI5oB4Vw+UYQ4TiIPlRkvRtdFIghliXSAVxfOtv1CPcGBEoA). |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we be scrutinizing these deps?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Those are brought in by the ERC1155, ERC 721Permit, and ERC721Psi code. I have brought those in so that the forge build would work.
Both of them have been around for a long time. However, we aren't bringing in a specific version.
I think we should address improvements related to them in a separate PR.