👮
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. Cryptography

Sha-256 Example

We have the input string: "TimeIsMoney"

  • We first convert it into bits using the ASCII table

01010100 01101001 01101101 01100101 01001001 01110011 01001101 01101111 01101110 01100101 01111001

This results in a 11 x 8 bits (88 bits)

The input must be a multiple of 512, meaining pre-processing is necessary

88 bits round up to the closest multiple of 512

88 -> 512

  • NOTE: If the input were, for example, 960 bits, it would get rounded up to 1024 (2 x 512)

PreprocessingFirstly, 1 bit is added, making our total bits to 89We then keep adding 0's until our input is 64 bits away from the nearest multiple of 512 (448)ORIGINAL INPUT: 01010100 01101001 01101101 01100101 01001001 01110011 01001101 01101111 01101110 01100101 01111001We add 1 bit and keep adding 0's until the input is 448 bits:01010100 01101001 01101101 01100101 01001001 01110011 01001101 01101111 01101110 01100101 011110011 ..................................................00000000The remaining 64 bits represent the length of the input (original)Our input was initially 88 bits, 88 written in binary is 1011000We keep adding 0's (57 to be exact) and then add our length at the end

SplittingWe now have to split up the input into 512 bit blocks. Since our input string results in 512 bits exactly, we only have 1 block. (N = 1)We then express this 512 bit block into 16 x 32 bitsM0: 32 bitsM2: 32 bits.......M15: 32 bitsWe then set the intial hash values. Those are 8x64 bit words in hex. In sha-256, those are: (256 bits total)H(0)0 = 6a09e667H(0)1 = bb67ae85H(0)2 = 3c6ef372H(0)3 = a54ff53aH(0)4 = 510e527fH(0)5 = 9b05688cH(0)6 = 1f83d9abH(0)7 = 5be0cd19Where do those words come from?

PreviousElliptic curves and ECDSANextSha-256

Last updated 2 years ago