You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Snapshotting profit is printed incorrectly when used in nested functions. This is because the index of the initial balance snapshot is not recorded and passed to the printProfit function (always uses index 0 as the initial condition). Should be an easy fix to record the index of the initial snapshot and use that when calculating profit. However, formatting is not great. This may just be a limitation of using modifiers for snapshotting functionality, but logs get very messy when snapshotting is used in nested functions. This may be able to be solved with formatting with more information when printing.
ex.
function setUp() public {
// Fork from specified block chain at block
vm.createSelectFork("https://rpc.ankr.com/eth"); // , block_number);
// Deploy attack contract
attackContract = new AttackContract();
// Fund attacker contract
deal(EthereumTokens.USDC, address(attackContract), 1 * 10 ** 10);
// Tokens to track during snapshotting
tokens.push(EthereumTokens.USDC);
setAlias(address(attackContract), "Attacker");
console.log("\n>>> Initial conditions");
}
function testAttack() public snapshot(address(attackContract), tokens) {
attackContract.initializeAttack();
doSomething();
}
function doSomething() public snapshot(address(attackContract), tokens) {
}
ex output:
Logs:
>>> Initial conditions
--- USDC balance of [Attacker]: 10000.0 ---
>>> Initialize attack
>>> Execute attack
>>> Complete attack
--- USDC balance of [Attacker]: 0.0 ---
--- USDC balance of [Attacker]: 0.0 ---
~~~ Profit for [Attacker]
-----------------------------------------------------------------------------------------
Token address | Symbol | Profit
-----------------------------------------------------------------------------------------
0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48 | USDC | -10000.0
--- USDC balance of [Attacker]: 0.0 ---
~~~ Profit for [Attacker]
-----------------------------------------------------------------------------------------
Token address | Symbol | Profit
-----------------------------------------------------------------------------------------
0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48 | USDC | -10000.0
The text was updated successfully, but these errors were encountered:
Snapshotting profit is printed incorrectly when used in nested functions. This is because the index of the initial balance snapshot is not recorded and passed to the printProfit function (always uses index 0 as the initial condition). Should be an easy fix to record the index of the initial snapshot and use that when calculating profit. However, formatting is not great. This may just be a limitation of using modifiers for snapshotting functionality, but logs get very messy when snapshotting is used in nested functions. This may be able to be solved with formatting with more information when printing.
ex.
ex output:
The text was updated successfully, but these errors were encountered: