Skip to content

Commit

Permalink
feat(redis): set sample max value (#223)
Browse files Browse the repository at this point in the history
  • Loading branch information
nugaon authored Oct 20, 2023
1 parent 9ea2e30 commit 3bcfa60
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 8 deletions.
1 change: 1 addition & 0 deletions deploy/main/011_deploy_state_changes.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import '../test/011_deploy_state_changes';
17 changes: 17 additions & 0 deletions deploy/test/011_deploy_state_changes.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { DeployFunction } from 'hardhat-deploy/types';

// Used for setting states in contracts according to the currently working environment
const func: DeployFunction = async function ({ deployments, getNamedAccounts }) {
const { execute, log } = deployments;
const { deployer } = await getNamedAccounts();

log('Setting Redistribution state "sampleMaxValue"');

const sampleMaxValue = '3500000000000000000000000000000000000000000000000000000000000000000000000';
await execute('Redistribution', { from: deployer }, 'setSampleMaxValue', sampleMaxValue);

log('----------------------------------------------------');
};

export default func;
func.tags = ['main', 'state_changes'];
27 changes: 19 additions & 8 deletions src/Redistribution.sol
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,10 @@ contract Redistribution is AccessControl, Pausable {
uint8 private penaltyMultiplierDisagreement = 1;
uint8 private penaltyMultiplierNonRevealed = 2;

// alpha=0.097612 beta=0.0716570 k=16
uint256 private sampleMaxValue =
1284401000000000000000000000000000000000000000000000000000000000000000000;

// The reveal of the winner of the last round.
Reveal public winner;

Expand All @@ -145,10 +149,6 @@ contract Redistribution is AccessControl, Pausable {
// The miniumum stake allowed to be staked using the Staking contract.
uint64 private constant MIN_STAKE = 100000000000000000;

// alpha=0.097612 beta=0.0716570 k=16
uint256 private constant SAMPLE_MAX_VALUE =
1284401000000000000000000000000000000000000000000000000000000000000000000;

// Maximum value of the keccack256 hash.
bytes32 private constant MAX_H = 0x00000000000000000000000000000000ffffffffffffffffffffffffffffffff;

Expand Down Expand Up @@ -467,6 +467,8 @@ contract Redistribution is AccessControl, Pausable {
entryProofLast.proofSegments[0]
);

estimateSize(entryProofLast.proofSegments[0]);

PostageContract.withdraw(winnerSelected.owner);
emit WinnerSelected(winnerSelected);
emit ChunkCount(PostageContract.validChunkCount());
Expand Down Expand Up @@ -625,6 +627,17 @@ contract Redistribution is AccessControl, Pausable {
penaltyMultiplierNonRevealed = _penaltyMultiplierNonRevealed;
}

/**
* @notice changes the max sample value used for reserve estimation
*/
function setSampleMaxValue(uint256 _sampleMaxValue) external {
if (!hasRole(DEFAULT_ADMIN_ROLE, msg.sender)) {
revert NotAdmin();
}

sampleMaxValue = _sampleMaxValue;
}

/**
* @notice Updates the source of randomness. Uses block.difficulty in pre-merge chains, this is substituted
* to block.prevrandao in post merge chains.
Expand Down Expand Up @@ -1091,12 +1104,10 @@ contract Redistribution is AccessControl, Pausable {
revert LastElementCheckFailed();
}
}

estimateSize(trALast);
}

function estimateSize(bytes32 trALast) internal pure {
if (uint256(trALast) >= SAMPLE_MAX_VALUE) {
function estimateSize(bytes32 trALast) internal view {
if (uint256(trALast) >= sampleMaxValue) {
revert ReserveCheckFailed(trALast);
}
}
Expand Down

0 comments on commit 3bcfa60

Please sign in to comment.