👮
Contract Cops
  • Mastering Ethereum Book
    • What is ethereum?
    • Tokens
    • Oracles
    • Decenralized Applications(DApps)
    • The Ethereum virtual machine
    • Ethereum basics
    • Ethereum clients
    • Cryptography
    • Wallets
    • Transactions
    • Chapter 7 - Smart Contracts & Solidity
    • Side Notes
      • Tokens
      • Smart Contracts and Solidity
  • Cryptography
    • Ethereum Cryptography - Cheatsheet
    • Assymetric vs symmetric cryptography
    • ECDSA vs RSA
    • Elliptic curves and ECDSA
    • Sha-256 Example
    • Sha-256
    • What are the different steps in SHA-256?
  • Ethereum Blocks
    • Block Headers
  • Learning Solidity
    • Storage vs memory
    • Upgradeable contracts
      • Proxy pattern in smart contracts
  • PoS
    • Proof of stake
  • PoW
    • PoW
  • Tokens
    • ERC-1155
    • ERC20
  • Cryptonomics
    • Automated market makers
    • Collateral Tokens
    • Collateralized Stablecoin
    • Fiat currency
    • Liquidity pool
    • Open Position: Meaning and Risk in Trading
    • Slippage
    • Spot price
  • Common Attack Vectors
    • Checking access control
    • Access control issues on critical functions
    • Account Existence Check for low level calls
    • Account Existence Check
    • Common attacks with contract/EOA addresses
    • Arithmetic under/overflow
    • Assert Attack
    • Assert require revert
    • Assert Violation
    • Bad Interface DOS
    • Bad pragma and compiler
    • Block Timestamp Manipulation
    • Bypassing contract check
    • Code With No Effects
    • Code size check vulnerability
    • Constructors with Care
    • Default Visibilities
    • Delegatecall
    • Delegatecall
    • Denial of Service (DoS)
    • DoS with block gas limit
    • Entropy Illusion
    • External contract referencing
    • Flash Loan Attack
    • Floating Point and Precision
    • Function selector abuse
    • Function selector abuse
    • Smart contract gas griefing
    • Hash collision parameters
    • Hash Collisions With Multiple Variable Length Arguments
    • Imprecise arithmetic
    • Improper Array Deletion
    • Incorrect array deletion
    • Incorrect interface
    • Insufficient Gas Griefing
    • Loop through long arrays
    • Message call with hardcoded gas amount
    • Not enough gas for ether transfer
    • Precision Loss in Calculations
    • Oracle Manipulation
    • Public Burn Function
    • Read-only reentrancy
    • Race Conditions/Front Running
    • Reentrancy Attacks
    • Reentrancy
    • Requirement Violation
    • Right-To-Left-Override control character (U+202E)
    • Shadowing State Variables
    • Short Address / Parameter attack
    • Signature Malleability
    • Signature Replay
    • Transaction Order Dependence
    • Tx.Origin Authentication
    • Unchecked CALL Return Values
    • Unexpected ether
    • Uninitialized Storage Pointers
    • Unsafe Ownership Transfer
  • EIP's
    • EIP155
    • EIP55
  • PoW
    • Ethash
    • Scrypt - RFC 7914
  • Questions for self evaluation
    • Questions 23/04/2023 (Nr: 84)
    • Usability guide for questions
  • Frequently asked questions
    • What is the difference between transaction and message?
    • What is the use of a interface or function without implementation?
  • UsefulResources
Powered by GitBook
On this page
  1. Common Attack Vectors

Short Address / Parameter attack

This attack does not originate from within Solidity itself, but instead comes externally of the blockchain.

ContextA transaction on the Ethereum blockchain can be either a value send (EOA to EOA), contract deployment (compiled bytecode, sent to the 0x0) address or a function callThe way that a function call is done is as follows:The EVM leaves 4 bytes for the function identifier.After that, for every parameter for that function, a fixed amount of bytes are set aside (this is all deterministic and already pre-configured by the EVM).Lets say we have the following function in a contract:This looks like a perfectly safe function to use, but it can be the subject of a parameter/short address attack.However, because of how the EVM compiles the parameters in their pre-fixed byte size, a user can provide malicious input.The pre-fixed bytes assigned for an address parameter is 32 bytes. Same goes for uint => 32 bytes.If a user decides to give a hex of 31 bytes, the EVM deals with this by adding two zeros for every byte thats missing. In the function above, this can be exploited because of what the hex looks like:{4 bytes for function reference}{32 bytes for the address}{32 bytes for the uint}Let's say the user provides 31 bytes for his address(instead of 32) and a uint of 100 (for the sending of 100 tokens).The EVM would compile tis as follows:a9059cbb000000000000000000000000deaddeaddea ddeaddeaddeaddeaddeaddeadde00000000000000 00000000000000000000000000000000056bc75e2d6310000000If you notice, there are 2 more zeros than there should be at the end. This means that the user will send 25600 tokens, instead of the original 100.

Preventative measuresAll parameters should be checked and validated. This is done by the web3 provider used to build the external side of the application. Providers like web3.js handle this automatically.Ordering of variables can prevent (mitigate) such attacks.While this attack is very rare and no major exploit has been done using it, the best advice is for developers to stick with reliable and up to date technology. Using outdated clients might lead to someone being able to perform the exploit and send a misconfigured transaciton, forcing the EVM to add zero's and achieve unexpected issues.

PreviousShadowing State VariablesNextSignature Malleability

Last updated 2 years ago