Skip to content

Commit

Permalink
prevent potential revert on redeem (#591)
Browse files Browse the repository at this point in the history
* prevent potential revert on redeem

* better test + bump v to rc.7

* linting
  • Loading branch information
orenyodfat authored Jan 23, 2019
1 parent f5bf519 commit c43c0d8
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 3 deletions.
3 changes: 3 additions & 0 deletions contracts/schemes/Locking4Reputation.sol
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,9 @@ contract Locking4Reputation {
uint256 score = _period.mul(_amount).mul(_numerator).div(_denominator);
require(score > 0, "score must me > 0");
scores[_locker] = scores[_locker].add(score);
//verify that redeem will not overflow for this locker
require((scores[_locker] * reputationReward)/scores[_locker] == reputationReward,
"score is too high");
totalScore = totalScore.add(score);

emit Lock(_locker, lockingId, _amount, _period);
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@daostack/arc",
"version": "0.0.1-rc.6",
"version": "0.0.1-rc.7",
"description": "A platform for building DAOs",
"files": [
"contracts/",
Expand All @@ -16,7 +16,7 @@
},
"scripts": {
"test": "cross-conf-env run-with-ganache --ganache-cmd 'npm run ganache' 'npm run truffle compile && npm run truffle migrate && npm run truffle test'",
"ganache": "cross-conf-env ganache-cli --gasLimit npm_package_config_gasLimit --account=\"0x0191ecbd1b150b8a3c27c27010ba51b45521689611e669109e034fd66ae69621,9999999999999999999999999999999999999999999\" --account=\"0x00f360233e89c65970a41d4a85990ec6669526b2230e867c352130151453180d,9999999999999999999999999999999999999999999\" --account=\"0x987a26abca7432016104ce2f24ce639340e25afe06ac69f68791399e7a5d1028,9999999999999999999999999999999999999999999\" --account=\"0x89af34b1b7347834048b99423dad174a14bf14540d720d72c16ae92e94b987cb,9999999999999999999999999999999999999999999\" --account=\"0xc867be647eb2bc51e4c0d61066859875cf3634fe949b6f5f85c69ab90e485b37,9999999999999999999999999999999999999999999\" --account=\"0xefabcc2377dee5e51b5a9e65a3854aec85fbbec3cb584d8ad4f9679869fb33c6,9999999999999999999999999999999999999999999\"",
"ganache": "cross-conf-env ganache-cli --gasLimit npm_package_config_gasLimit --account=\"0x0191ecbd1b150b8a3c27c27010ba51b45521689611e669109e034fd66ae69621,0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff\" --account=\"0x00f360233e89c65970a41d4a85990ec6669526b2230e867c352130151453180d,9999999999999999999999999999999999999999999\" --account=\"0x987a26abca7432016104ce2f24ce639340e25afe06ac69f68791399e7a5d1028,9999999999999999999999999999999999999999999\" --account=\"0x89af34b1b7347834048b99423dad174a14bf14540d720d72c16ae92e94b987cb,9999999999999999999999999999999999999999999\" --account=\"0xc867be647eb2bc51e4c0d61066859875cf3634fe949b6f5f85c69ab90e485b37,9999999999999999999999999999999999999999999\" --account=\"0xefabcc2377dee5e51b5a9e65a3854aec85fbbec3cb584d8ad4f9679869fb33c6,9999999999999999999999999999999999999999999\"",
"start": "pm2 start truffle -- serve",
"lint": "eslint .",
"lint --fix": "eslint --fix .",
Expand Down
14 changes: 14 additions & 0 deletions test/lockingeth4reputation.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,20 @@ contract('LockingEth4Reputation', accounts => {

});

it("score too high", async () => {
let testSetup = await setup(accounts);
let BigNumber = require('bignumber.js');
BigNumber.set({ DECIMAL_PLACES: 0, ROUNDING_MODE: 4 });
let maxUint = ((new BigNumber(2)).toPower(256).sub(1)).div(100).add(1);
try {
await testSetup.lockingEth4Reputation.lock(1,{value:maxUint.toString(10)});
assert(false, "score too high should revert");
} catch(error) {
helpers.assertVMException(error);
}

});

it("cannot lock without initialize", async () => {
let testSetup = await setup(accounts,100,0,3000,3000,6000,false);
try {
Expand Down

0 comments on commit c43c0d8

Please sign in to comment.