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

DRAFT: Enable Slither github action; Resolve slither, solhint and eslint issues #168

Closed
wants to merge 120 commits into from
Closed
Changes from 1 commit
Commits
Show all changes
120 commits
Select commit Hold shift + click to select a range
f2e29fd
Added initial code for random number generation
drinkcoffee Dec 18, 2023
8405ce9
Improve documentation
drinkcoffee Dec 19, 2023
fd3644b
forge install: openzeppelin-contracts-upgradeable
drinkcoffee Dec 19, 2023
33aff29
forge install: openzeppelin-contracts
drinkcoffee Dec 19, 2023
c2d6506
Added remappings
drinkcoffee Dec 19, 2023
cb56dbe
forge install: openzeppelin-contracts
drinkcoffee Dec 19, 2023
1ea3540
forge install: openzeppelin-contracts-upgradeable
drinkcoffee Dec 19, 2023
e03392a
forge install: seaport
drinkcoffee Dec 19, 2023
426407a
Remove incorrect version of seaport
drinkcoffee Dec 19, 2023
545f341
forge install: seaport
drinkcoffee Dec 19, 2023
015c4f2
Temporarily remove trading contracts
drinkcoffee Dec 19, 2023
acdca5a
forge install: solidity-bits
drinkcoffee Dec 19, 2023
4a3f1a0
forge install: solidity-bytes-utils
drinkcoffee Dec 19, 2023
f11f239
Fixed compilation issues
drinkcoffee Dec 19, 2023
d10d6ba
Initial doc
drinkcoffee Dec 19, 2023
87952c8
Update docs
drinkcoffee Dec 19, 2023
8c03abf
Separated use of RANDAO
drinkcoffee Dec 20, 2023
b6a7956
Re-add trading
drinkcoffee Dec 21, 2023
73b8569
forge install: seaport-core
drinkcoffee Dec 21, 2023
9a57a6f
Rework seaport installs
drinkcoffee Dec 21, 2023
ff3b4b1
forge install: seaport-core
drinkcoffee Dec 21, 2023
f6b2a98
Fix import path
drinkcoffee Dec 21, 2023
3678fe9
forge install: seaport-types
drinkcoffee Dec 21, 2023
5e21128
Lib issue
drinkcoffee Dec 21, 2023
db07799
forge install: seaport-types
drinkcoffee Dec 21, 2023
8bc1cf2
Remove old seaport
drinkcoffee Dec 21, 2023
61adf8f
forge install: seaport
drinkcoffee Dec 21, 2023
e3a117c
Switch seaport version
drinkcoffee Dec 21, 2023
db8e31e
forge install: seaport
drinkcoffee Dec 21, 2023
cbb5ded
Switch to RandomSeedProvider
drinkcoffee Dec 21, 2023
8d4b47a
forge install: seaport
drinkcoffee Dec 21, 2023
14d6ae4
Rework seaport version
drinkcoffee Dec 21, 2023
b58eed2
Added seaport
drinkcoffee Dec 21, 2023
57710bb
Remove seaport
drinkcoffee Dec 21, 2023
0519516
Remove seaport
drinkcoffee Dec 21, 2023
236c518
Remove seaport lib directory
drinkcoffee Dec 21, 2023
1c30b08
Re-designed based on integration with chainlink
drinkcoffee Dec 22, 2023
aa82b49
Initial test plan
drinkcoffee Dec 22, 2023
2034b99
Revised documentation. Added allow listing
drinkcoffee Jan 10, 2024
b245fd7
Initial tests
drinkcoffee Jan 10, 2024
7515b9f
Add more tests
drinkcoffee Jan 10, 2024
f0bc1f1
Compiling
drinkcoffee Jan 11, 2024
3c29314
Fixed most of the build process for hardhat
drinkcoffee Jan 11, 2024
02f8980
Added more tests
drinkcoffee Jan 11, 2024
b0b8de3
Add more tests
drinkcoffee Jan 11, 2024
fbab874
Add more tests
drinkcoffee Jan 12, 2024
f875646
Rename tests
drinkcoffee Jan 12, 2024
e963736
Improve documentation
drinkcoffee Jan 12, 2024
26b4991
Clean compile on hardhat and forge.
drinkcoffee Jan 15, 2024
d3db1ae
Added more tests
drinkcoffee Jan 15, 2024
f231404
Improve test coverage
drinkcoffee Jan 15, 2024
f286c00
Emit events when adding offchain consumers
drinkcoffee Jan 15, 2024
68db3d5
RandomSeedProvider and RandomValues: 100% coverage
drinkcoffee Jan 15, 2024
6a3f5bf
Remove coverage report
drinkcoffee Jan 15, 2024
58eca56
Improve documentation
drinkcoffee Jan 16, 2024
36ec087
Improve documentation
drinkcoffee Jan 16, 2024
e17ea3d
Added initial version of Supra source adaptor
drinkcoffee Jan 16, 2024
a0aadd7
Add initial chainlink tests
drinkcoffee Jan 17, 2024
6110ec2
Run prettier
drinkcoffee Jan 18, 2024
c4c87c8
Fix test failure
drinkcoffee Jan 18, 2024
aaabda0
Add more tests
drinkcoffee Jan 18, 2024
7300f87
Completed chainlink tests
drinkcoffee Jan 19, 2024
e246a89
Switch to UUPS and added upgrade tests
drinkcoffee Jan 19, 2024
27eec2e
Added tests for supra adaptor
drinkcoffee Jan 19, 2024
5db497d
Improve documentation
drinkcoffee Jan 19, 2024
3356fce
Revert prettier changes across repo
drinkcoffee Jan 19, 2024
e1caa1b
Merged main
drinkcoffee Jan 19, 2024
19eb7a7
Revert prettier changes
drinkcoffee Jan 19, 2024
a43fad6
Remove package lock file
drinkcoffee Jan 22, 2024
c6ca3da
Fixed yarn merge issue
drinkcoffee Jan 22, 2024
61abd47
Ensure source used checking if a value is ready is the source supplie…
drinkcoffee Jan 22, 2024
f70d093
Remove chainlink package and instead include just the file needed
drinkcoffee Jan 22, 2024
d219997
Show version during forge test. Remove yarn install
drinkcoffee Jan 23, 2024
fcc02d1
Add more debug to github actions
drinkcoffee Jan 23, 2024
7626c5a
Add more debug to github actions
drinkcoffee Jan 23, 2024
5049c56
Fixed yaml format error
drinkcoffee Jan 23, 2024
b8628b4
Add more debug
drinkcoffee Jan 23, 2024
476ec56
Fixed capitalisation of directory name
drinkcoffee Jan 23, 2024
2b754da
Separate eslint and solhint
drinkcoffee Jan 23, 2024
11a9c13
Fix yarn scripts
drinkcoffee Jan 23, 2024
5f5bfdc
Fix so that eslint and solhint will now run in github actions
drinkcoffee Jan 23, 2024
9813597
Fix linter issues
drinkcoffee Jan 23, 2024
f33554f
Linter errors no longer show failure on github actions
drinkcoffee Jan 23, 2024
0f67007
Remove warnings
drinkcoffee Jan 23, 2024
5076a2d
Improve readability
drinkcoffee Jan 23, 2024
6be99a6
Merge branch 'random' into slither
drinkcoffee Jan 23, 2024
c722bbe
Add script directory to remove error
drinkcoffee Jan 24, 2024
3c80c72
Fixed documentation reflect the change from transparent upgrade proxy…
drinkcoffee Jan 24, 2024
89f3dda
Fix typos and improve documentation
drinkcoffee Jan 24, 2024
d39e5e9
Improved documentation
drinkcoffee Jan 24, 2024
6fe6f29
Switch to using block.hash rather than block.number for initial rando…
drinkcoffee Jan 24, 2024
cd5d9ba
Fix call to blockhash
drinkcoffee Jan 24, 2024
9dd9310
Fixed tests for initial seed values
drinkcoffee Jan 24, 2024
c895236
Merge branch 'main' into random
drinkcoffee Jan 24, 2024
d806ace
Enable slither testing
drinkcoffee Jan 24, 2024
a05f527
Applied prettier
drinkcoffee Jan 24, 2024
2817df8
Fixed more linting issues
drinkcoffee Jan 24, 2024
7893007
Fixed subscription typo
drinkcoffee Jan 24, 2024
55cfbfc
Merge branch 'random' into slither
drinkcoffee Jan 24, 2024
ce60b7a
Removed extra hashing for _fetchRandomValue
drinkcoffee Jan 24, 2024
e84782a
Fixed linter issues
drinkcoffee Jan 24, 2024
e3775c6
Switch to Australian spelling of fulfilment for all random number rel…
drinkcoffee Jan 24, 2024
6acf4ac
Merged change from random branch: change from fulfill to fulfil
drinkcoffee Jan 24, 2024
07e9ea5
Fixed most solhint issues
drinkcoffee Jan 24, 2024
bf87b12
Fix linting issues
drinkcoffee Jan 25, 2024
5af381d
Change how slither is installed and run
drinkcoffee Jan 25, 2024
dd1d101
Fix yarn syntax issues
drinkcoffee Jan 25, 2024
7be804a
Fixed slither install
drinkcoffee Jan 25, 2024
cce5cd1
Added forge install to running slither
drinkcoffee Jan 25, 2024
ec56e1a
Fix slither issues
drinkcoffee Jan 25, 2024
7a252e9
Fix slither issue: make VRF coordinator an immutable variable
drinkcoffee Jan 25, 2024
815b357
Merge branch 'random' into slither
drinkcoffee Jan 25, 2024
330192d
Fix more slither issues
drinkcoffee Jan 25, 2024
956c7ac
Set the initial version to the constant defining VERSION 0. This also…
drinkcoffee Jan 25, 2024
6232c6f
Merge branch 'random' into slither
drinkcoffee Jan 25, 2024
d073dc2
Fixed slither issues
drinkcoffee Jan 25, 2024
c4ef154
Resolve more slither issues
drinkcoffee Jan 25, 2024
b26db2f
Resolve slither issues
drinkcoffee Jan 25, 2024
dbb5c5f
Merge branch 'random' into slither
drinkcoffee Jan 25, 2024
7989b9c
Resolved more slither issues
drinkcoffee Jan 25, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fixed compilation issues
drinkcoffee committed Dec 19, 2023
commit f11f239645737a95ca59429299fded5d3d76dd86
6 changes: 3 additions & 3 deletions contracts/mocks/MockOnReceive.sol
Original file line number Diff line number Diff line change
@@ -13,10 +13,10 @@ contract MockOnReceive {

// Attempt to transfer token to another address on receive
function onERC721Received(
address operator,
address from,
address /* operator */,
address /* from */,
uint256 tokenId,
bytes calldata data
bytes calldata /* data */
) public returns (bytes4) {
tokenAddress.transferFrom(address(this), recipient, tokenId);
return this.onERC721Received.selector;
28 changes: 21 additions & 7 deletions contracts/random/RandomManager.sol
Original file line number Diff line number Diff line change
@@ -9,7 +9,8 @@ import {IOffchainRandomSource} from "./IOffchainRandomSource.sol";

// TODO should be upgradeable
contract RandomManager is AccessControl {
error INVALID_DEGREE_OF_RANDOMNESS(uint256 _degreeOfRandomness);
error InvalidSecurityLevel(uint256 _securityLevel);
error WaitForRandom();


mapping (uint256 => bytes32) private randomOutput;
@@ -21,12 +22,12 @@ contract RandomManager is AccessControl {

// TODO set-up access control
constructor() {
randomOutput[0] = keccak256(block.chainid, block.number);
randomOutput[0] = keccak256(abi.encodePacked(block.chainid, block.number));
nextRandomIndex = 1;
}

// TODO Access control
function setOffchainRandomSource(address _offchainRandomSource) {
function setOffchainRandomSource(address _offchainRandomSource) external {
offchainRandomSource = IOffchainRandomSource(_offchainRandomSource);
}

@@ -48,7 +49,7 @@ contract RandomManager is AccessControl {
if (index != nextRandomIndex) {
return;
}
randomOutput[nextRandomIndex++] = keccak256(chainId, prevRandomOutput, offchainRandom);
randomOutput[nextRandomIndex++] = keccak256(abi.encodePacked(prevRandomOutput, offchainRandom));
}
else {
// If the off chain random provider has NOT been configured, use on-chain sources.
@@ -78,7 +79,7 @@ contract RandomManager is AccessControl {
uint256 prevRanDAO = block.prevrandao;

// The new random value is a combination of
randomOutput[nextRandomIndex++] = keccak256(chainId, blockHash, timestamp, prevRanDAO, prevRandomOutput);
randomOutput[nextRandomIndex++] = keccak256(abi.encodePacked(prevRandomOutput, blockHash, timestamp, prevRanDAO));
}
}

@@ -87,15 +88,28 @@ contract RandomManager is AccessControl {
* @dev Note that the same _randomFulfillmentIndex will be returned to multiple games and even within
* the one game. Games must personalise this value to their own game, the the particular game player,
* and to the game player's request.
* @param _securityLevel The number of random number generations to wait. A higher value provides
* better security. For most applications, a value of 1 or 2 is ideal. If the random number
* is for a high value transaction, choose a high number, for instance 3 or 4.
* The reasoning behind a low value providing less security is that when the security level
* is set to one, the seed is derived from the next off-chain random value. However, this
* value could relate to an off-chain random value being supplied by a transaction that is currently
* in the transaction pool. Some game players may be able to see this value and hence guess the
* outcome for the random generation. Having a higher value means that the game player has to commit
* before the off-chain random number is put into a transaction that is then put into the
* transaction pool.
* @return _randomFulfillmentIndex The index for the game contract to present to fetch the next random value.
*/
function requestRandom() external returns(uint256 _randomFulfillmentIndex) {
function requestRandom(uint256 _securityLevel) external returns(uint256 _randomFulfillmentIndex) {
if (_securityLevel == 0 || _securityLevel > 10) {
revert InvalidSecurityLevel(_securityLevel);
}
// Generate a new value now using offchain values that might be cached in the blockchain already.
// Do this to ensure nafarious actors can't read the cached values and use them to determine
// the next random value.
generateNextRandom();
// Indicate that the next generated random value can be used.
_randomFulfillmentIndex = nextRandomIndex + 1;
_randomFulfillmentIndex = nextRandomIndex + _securityLevel;
}


13 changes: 8 additions & 5 deletions contracts/random/RandomValues.sol
Original file line number Diff line number Diff line change
@@ -24,11 +24,14 @@ abstract contract RandomValues {
/**
* @notice Register a request to generate a random value. This function should be called
* when a game player has purchased an item that has a random value.
* @param _securityLevel The number of random number generations to wait. A higher value provides
* better security. For most applications, a value of 1 or 2 is ideal. If the random number
* is for a high value transaction, choose a high number, for instance 3 or 4.
* @return _randomRequestId A value that needs to be presented when fetching the random
* value with fetchRandom.
*/
function requestRandomValueCreation() internal returns (uint256 _randomRequestId) {
uint256 randomFulfillmentIndex = randomManager.requestRandom();
function requestRandomValueCreation(uint256 _securityLevel) internal returns (uint256 _randomRequestId) {
uint256 randomFulfillmentIndex = randomManager.requestRandom(_securityLevel);
_randomRequestId = nextNonce++;
randCreationRequests[_randomRequestId] = randomFulfillmentIndex;
}
@@ -41,16 +44,16 @@ abstract contract RandomValues {
* and no game player will have the same random value twice.
* @return _randomValue The index for the game contract to present to fetch the next random value.
*/
function fetchRandom(uint256 _randomRequestId) internal view returns(bytes32 _randomValue) {
// Request the randon seed. If not enough time has elapsed yet, this call will revert.
function fetchRandom(uint256 _randomRequestId) internal returns(bytes32 _randomValue) {
// Request the random seed. If not enough time has elapsed yet, this call will revert.
bytes32 randomSeed = randomManager.getRandomSeed(randCreationRequests[_randomRequestId]);
// Generate the random value by combining:
// address(this): personalises the random seed to this game.
// msg.sender: personalises the random seed to the game player.
// _randomRequestId: Ensures that even if the game player has requested multiple random values,
// they will get a different value for each request.
// randomSeed: Value returned by the RandomManager.
_randomValue = keccak256(address(this), msg.sender, _randomRequestId, randomSeed);
_randomValue = keccak256(abi.encodePacked(address(this), msg.sender, _randomRequestId, randomSeed));
}

// TODO storage gap
9 changes: 6 additions & 3 deletions foundry.toml
Original file line number Diff line number Diff line change
@@ -2,10 +2,13 @@
src = 'contracts'
out = 'foundry-out'
libs = ["lib", "node_modules"]
remappings = [
"node_modules/seaport:@rari-capital/solmate/=node_modules/@rari-capital/solmate/",

remappings = [
'@openzeppelin/contracts/=lib/openzeppelin-contracts/contracts/',
'@openzeppelin/contracts-upgradeable/=lib/openzeppelin-contracts-upgradeable/contracts/'
'@openzeppelin/contracts-upgradeable/=lib/openzeppelin-contracts-upgradeable/contracts/',
'solidity-bits/=lib/solidity-bits/',
'solidity-bytes-utils/=lib/solidity-bytes-utils/'
]

# See more config options https://github.com/foundry-rs/foundry/blob/master/crates/config/README.md#all-options