@0x/contracts-staking
: Fix overflow w/ LibFixedMath._mul(-1, -2*255)
.
This commit is contained in:
parent
8e6d92cad5
commit
4f56d68689
@ -21,6 +21,10 @@
|
|||||||
{
|
{
|
||||||
"note": "The fallback function in `StakingProxy` reverts if there is no staking contract attached",
|
"note": "The fallback function in `StakingProxy` reverts if there is no staking contract attached",
|
||||||
"pr": 2310
|
"pr": 2310
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"note": "Fix overflow w/ `LibFixedMath._mul(-1, -2*255)",
|
||||||
|
"pr": 2311
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
@ -349,7 +349,7 @@ library LibFixedMath {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
c = a * b;
|
c = a * b;
|
||||||
if (c / a != b) {
|
if (c / a != b || c / b != a) {
|
||||||
LibRichErrors.rrevert(LibFixedMathRichErrors.BinOpError(
|
LibRichErrors.rrevert(LibFixedMathRichErrors.BinOpError(
|
||||||
LibFixedMathRichErrors.BinOpErrorCodes.MULTIPLICATION_OVERFLOW,
|
LibFixedMathRichErrors.BinOpErrorCodes.MULTIPLICATION_OVERFLOW,
|
||||||
a,
|
a,
|
||||||
|
@ -184,14 +184,14 @@ blockchainTests('LibFixedMath unit tests', env => {
|
|||||||
return expect(tx).to.revertWith(expectedError);
|
return expect(tx).to.revertWith(expectedError);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('mulDiv(MIN_FIXED, int(-1), int(1)) throws', async () => {
|
it('mulDiv(int(-1), MIN_FIXED, int(1)) throws', async () => {
|
||||||
const [a, n, d] = [MIN_FIXED_VALUE, -1, 1];
|
const [a, n, d] = [-1, MIN_FIXED_VALUE, 1];
|
||||||
const expectedError = new FixedMathRevertErrors.BinOpError(
|
const expectedError = new FixedMathRevertErrors.BinOpError(
|
||||||
FixedMathRevertErrors.BinOpErrorCodes.MultiplicationOverflow,
|
FixedMathRevertErrors.BinOpErrorCodes.MultiplicationOverflow,
|
||||||
a,
|
a,
|
||||||
n,
|
n,
|
||||||
);
|
);
|
||||||
const tx = testContract.mulDiv.callAsync(a, new BigNumber(n), new BigNumber(d));
|
const tx = testContract.mulDiv.callAsync(new BigNumber(a), n, new BigNumber(d));
|
||||||
return expect(tx).to.revertWith(expectedError);
|
return expect(tx).to.revertWith(expectedError);
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -506,6 +506,17 @@ blockchainTests('LibFixedMath unit tests', env => {
|
|||||||
return expect(tx).to.revertWith(expectedError);
|
return expect(tx).to.revertWith(expectedError);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('int(-1) * MIN_FIXED throws', async () => {
|
||||||
|
const [a, b] = [-1, MIN_FIXED_VALUE];
|
||||||
|
const expectedError = new FixedMathRevertErrors.BinOpError(
|
||||||
|
FixedMathRevertErrors.BinOpErrorCodes.MultiplicationOverflow,
|
||||||
|
a,
|
||||||
|
b,
|
||||||
|
);
|
||||||
|
const tx = testContract.mul.callAsync(new BigNumber(a), b);
|
||||||
|
return expect(tx).to.revertWith(expectedError);
|
||||||
|
});
|
||||||
|
|
||||||
it('MAX_FIXED * int(-1) == -MAX_FIXED / FIXED_1', async () => {
|
it('MAX_FIXED * int(-1) == -MAX_FIXED / FIXED_1', async () => {
|
||||||
const [a, b] = [MAX_FIXED_VALUE, -1];
|
const [a, b] = [MAX_FIXED_VALUE, -1];
|
||||||
const r = await testContract.mul.callAsync(a, new BigNumber(b));
|
const r = await testContract.mul.callAsync(a, new BigNumber(b));
|
||||||
|
Loading…
x
Reference in New Issue
Block a user