Skip to content

Commit

Permalink
fix: TMC1-1 Maliciously Initialisable Contracts and TMC1-2 Inconsiste…
Browse files Browse the repository at this point in the history
…nt Handling of Contracts for Return
  • Loading branch information
ipromise2324 committed Apr 30, 2024
1 parent 963daaf commit ede7241
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 11 deletions.
7 changes: 6 additions & 1 deletion contracts/ton_master_chef.tact
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,12 @@ contract TonMasterChef with Deployable, MasterChef {
let feeForDevs: Int = msg.totalReward * FEE_PERCENT_FOR_DEV / 1000;
let expectedTon: Int = msg.totalReward + feeForDevs;
if (remainTon < expectedTon) {
self.sendTon(msg.owner, remainTon, 0);
send(SendParameters{
to: msg.owner,
value: remainTon,
mode: SendRemainingBalance + SendDestroyIfZero,
body: "Setup Error: not enough reward TON".asComment()
});
return;
}
// Update storage when ton is sufficient
Expand Down
26 changes: 16 additions & 10 deletions tests/TonMasterChef.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1035,9 +1035,13 @@ describe('TON MasterChef Tests', () => {
to: masterChef.address,
});

// isInitialized Should be true
const isInitialized = (await masterChef.getGetTonMasterChefData()).isInitialized;
expect(isInitialized).toBe(false);
// If the total reward is not enough, the contract should return the TON and destroy itself
try {
const isInitialized = (await masterChef.getGetTonMasterChefData()).isInitialized;
} catch (e) {
const error = e as Error;
expect(error.message).toEqual('Trying to run get method on non-active contract');
}
});

it('Should not deposit after deadline', async () => {
Expand Down Expand Up @@ -1162,12 +1166,16 @@ describe('TON MasterChef Tests', () => {
to: deployer.address,
});

let returnFee = 300000000n; // 221021736n
let returnFee = 300000000n;
expect(balanceAfter + returnFee).toBeGreaterThanOrEqual(balanceBefore); // 0.5 TON is the fee

let isInitialized = (await masterChef.getGetTonMasterChefData()).isInitialized;
// Should not be initialized
expect(isInitialized).toBe(false);
// If the total reward is not enough, the contract should return the TON and destroy itself
try {
(await masterChef.getGetTonMasterChefData()).isInitialized;
} catch (e) {
const error = e as Error;
expect(error.message).toEqual('Trying to run get method on non-active contract');
}
});

it('Should not initialize if start time > deadline', async () => {
Expand Down Expand Up @@ -1201,7 +1209,6 @@ describe('TON MasterChef Tests', () => {
success: false,
exitCode: 29461, // start time > deadline
});

});

it('Should not initialize if start time or deadline == 0', async () => {
Expand Down Expand Up @@ -1235,7 +1242,6 @@ describe('TON MasterChef Tests', () => {
success: false,
exitCode: 62197, // start time > deadline
});

});

// Test user deposit behavior before a pool is added.
Expand Down Expand Up @@ -1554,7 +1560,7 @@ describe('TON MasterChef Tests', () => {

deadline = BigInt(blockchain.now!! + 2000);
totalReward = toNano('10');
let sendingTon = (totalReward * 1003n) / 1000n;
let sendingTon = (totalReward * 1003n) / 1000n + toNano('1');
// Build the MasterChef contract from kitchen
await kitchen.send(
deployer.getSender(),
Expand Down

0 comments on commit ede7241

Please sign in to comment.