What is DeFi cryptography? How keys, signatures and hashes secure your crypto

What is DeFi cryptography? How keys, signatures and hashes secure your crypto

DeFi cryptography is the set of mathematical techniques, including private keys, digital signatures and hash functions, that proves control of assets and authorizes transactions in decentralized finance.

No bank holds your funds when you use DeFi - like, for instance, 1inch. No password is stored on a server. A single string of numbers in your wallet proves that you control your funds.

That proof comes from cryptography, the same field of mathematics that protects online banking and messaging. Understanding the basics helps you see what your wallet actually does when you click "Sign," and how to avoid the mistakes that cost users their funds.

What is cryptography in DeFi?

Cryptography in DeFi is the use of mathematical techniques to prove control of assets, authorize transactions and keep blockchain records tamper-resistant. Every wallet, transaction and smart contract interaction depends on it.

Traditional finance relies on institutions to record what you own. DeFi replaces that record-keeping with cryptographic proofs that anyone can check.

Three building blocks do most of the work:

  • Public-key cryptography creates the keys that control your wallet.
  • Digital signatures prove that you approved a transaction.
  • Hash functions link blocks together and make the blockchain's history hard to change.

More advanced techniques, such as zero-knowledge proofs and multi-party computation, build on these foundations.

How do private and public keys work?

A crypto wallet is built on a pair of keys: a private key that only you hold and a public key that anyone can see. The two keys are mathematically linked, but the private key cannot feasibly be worked out from the public key.

A private key is a very large random number. On Ethereum, a private key is 256 bits long, which means there are about 10^77 possible keys. That number is so large that guessing someone's key is practically impossible.

Your wallet derives your public key from your private key using elliptic curve cryptography. Ethereum and Bitcoin both use an elliptic curve called secp256k1.

Your wallet address comes from your public key. On Ethereum, the address is the last 20 bytes of the public key's hash, shown as a string starting with "0x."

Anyone can send funds to your address. Only the holder of the matching private key can move funds out of it.

What is a seed phrase?

A seed phrase is a list of 12 or 24 words that can regenerate all the private keys in your wallet. Most wallets follow a standard called BIP-39, which turns a random number into an easy-to-write word list.

The seed phrase is a backup of your entire wallet. If your phone breaks, you can restore your wallet on a new device by entering the seed phrase.

Anyone who has your seed phrase has full control of your funds. No support team, protocol or blockchain can reverse a transfer made with a stolen seed phrase.

Write your seed phrase down on paper or metal and store it offline. Never type it into a website, share it in a chat or save it in a screenshot.

How do digital signatures work?

A digital signature proves that the holder of a private key approved a specific message or transaction, without revealing the private key. Ethereum uses the Elliptic Curve Digital Signature Algorithm (ECDSA) to create these signatures.

When you send a transaction, your wallet signs the transaction details with your private key. Every node on the network can check the signature against your public key to confirm the transaction came from you.

A signature also protects the transaction's contents. If anyone changes the amount or recipient after you sign, the signature no longer matches and the network rejects the transaction.

Signing transactions vs. signing messages

Not every signature sends a transaction onchain. Many DeFi apps ask you to sign an offchain message instead.

Offchain messages are used for actions like logging in to an app, approving token spending with a permit or placing an order. Ethereum's EIP-712 standard formats these messages in a readable, structured way, so your wallet can show you what you are signing.

An offchain signature costs no gas, but it can still authorize real actions. A signed permit can allow a smart contract to spend your tokens, which is why scammers often try to trick users into signing malicious messages.

What are hash functions?

A hash function turns any input, from a single word to an entire block of transactions, into a fixed-length string of characters called a hash. The same input always produces the same hash, and even a tiny change to the input produces a completely different hash.

Hash functions are one-way. You can easily compute a hash from data, but you cannot feasibly work backward from a hash to the original data.

Ethereum uses a hash function called Keccak-256. Bitcoin uses SHA-256.

Blockchains use hashes in several ways:

  • Linking blocks. Each block contains the hash of the previous block. Changing any past transaction would change every hash after it, which makes tampering obvious.
  • Creating addresses. Ethereum addresses are derived from the hash of a public key.
  • Summarizing data. Merkle trees combine the hashes of many transactions into a single root hash. A Merkle tree lets anyone prove that a transaction is included in a block without downloading the whole block.

What are zero-knowledge proofs?

A zero-knowledge proof lets one party prove that a statement is true without revealing the information behind it. For example, a zero-knowledge proof can show that a batch of transactions is valid without re-running every transaction.

Zero-knowledge proofs power zk rollups, a type of Ethereum layer 2 network. A zk rollup processes transactions off Ethereum and submits a short validity proof that Ethereum can check quickly and cheaply.

Zero-knowledge proofs also support privacy features. A user can prove they meet a requirement, such as passing an identity check, without revealing personal details.

What other cryptography does DeFi use?

  • Multi-party computation (MPC). MPC wallets split a private key into several shares held by different parties or devices. No single share can sign a transaction alone, which reduces the single-point-of-failure risk of a regular private key.
  • Multisignature wallets. A multisig wallet requires approval from several keys before a transaction goes through. DAOs and teams often use multisigs to protect shared funds.
  • Hashlocks. A hashlock locks funds until someone reveals a secret that matches a known hash. Hashlocks let two parties swap assets across different blockchains, in a way designed so that either both transfers complete or neither does.
  • Commit-reveal schemes. A user first publishes the hash of a choice, then reveals the choice later. Commit-reveal schemes stop others from copying or front-running a decision before it is public.

How does 1inch use cryptography?

1inch uses cryptographic signatures and secrets to let users trade without giving 1inch custody of their funds.

  • Signed orders for intent-based swaps. With intent-based swaps on 1inch, you sign an order offchain using the EIP-712 standard. Signing the order costs no gas. Independent resolvers then compete to fill the order onchain, and the smart contract is designed to settle the swap only on the terms you signed. Learn more in our guide to intent-based swaps. 
  • Secrets for cross-chain swaps. Cross-chain swaps on 1inch use secrets and hashlocks to keep both sides of the swap linked. The contracts are designed to release funds on the destination chain only when the correct secret is revealed. 
  • Non-custodial design. The 1inch dApp and 1inch Wallet do not take custody of your assets. Your private keys stay under your control. Some third-party protocols that can be accessed through 1inch hold user assets under their own arrangements. 

How can you use cryptography safely?

Strong cryptography only protects you if your keys stay private and you know what you are signing.

  1. Protect your seed phrase. Store it offline and never share it with anyone, including people claiming to be support staff.
  2. Read every signature request. Check what your wallet shows before you sign. Be especially careful with permit and approval requests, which can give a contract access to your tokens.
  3. Avoid blind signing. If your wallet shows a signature request it cannot decode, do not sign it unless you fully trust the source.
  4. Use trusted tools for key generation. Weak randomness can expose your private key, as the 2022 Profanity vulnerability, disclosed by 1inch contributors, showed.
  5. Consider a hardware wallet. A hardware wallet keeps your private keys offline and asks you to confirm each transaction on the device.
  6. Revoke old approvals. Regularly remove token approvals you no longer need, so a compromised contract cannot use them to take your tokens.

The math behind DeFi

Cryptography is what makes DeFi trust-minimized. Keys prove control, signatures prove consent and hashes keep the record honest, without a central party keeping the ledger.

The mathematics is extremely hard to break. Most losses in DeFi come from smart contract bugs, leaked seed phrases, malicious signatures and weak key generation, not from broken cryptography.

FAQ

What is cryptography in crypto?

Cryptography in crypto is the use of mathematical techniques to secure wallets and transactions. Private keys prove control, digital signatures authorize transactions and hash functions protect the blockchain's history.

What is the difference between a private key and a public key?

A private key is a secret number that controls your wallet. A public key is derived from the private key and can be shared, and your wallet address is created from it.

Can someone hack my wallet by guessing my private key?

Guessing a properly generated private key is practically impossible, because there are about 10^77 possible keys. Wallets are usually compromised through leaked seed phrases, phishing or weak key generation.

Does signing a message cost gas?

Signing an offchain message costs no gas. An offchain signature can still authorize actions, such as letting a contract spend your tokens, so always check what you sign.

Will quantum computers break crypto cryptography?

Large quantum computers could one day weaken the elliptic curve cryptography used by most blockchains. Researchers are developing quantum-resistant cryptography, and blockchain communities are discussing how to upgrade before such computers exist. 

Swap tokens on 1inch.com.

Disclaimer: This content is for general information purposes only and does not constitute financial, investment, legal or tax advice, or a recommendation to buy, sell or hold any asset. Digital assets carry risk, including the risk of loss. Access to 1inch services is subject to the 1inch Terms of Use and may be restricted in certain jurisdictions. Nothing here is security advice: you are responsible for protecting your keys and checking what you sign.