Skip to main content

Posts

Showing posts from 2019

Programming Bitcoin I

Finite Field Definition: a "finite field" is defined as a finite set of numbers and two operations (addition) and (multiplication) that satisfy the following: 1. If a and b are in the set, a + b and a * b are in the set. We call this property closed. 2. 0 exists and has the property a + 0 = a. We call this additive identity. 3. 1 exists and has the property a * 1 = a. We call this multiplicative identity. 4. If a is in the set, -a is in the set, which is defined as the value that makes a + (-a) = 0. This is what we call the additive inverse. 5. If a is in the set and is not 0, a^-1 is in the set, which is defined as the value that makes a * a^-1 = 1. This is what we call the multiplicative inverse. We have a set of numbers that finite. The set is finite so we can designate  a number p, which is how big the set is. This is what we call the order of the set. Fp = { 0, 1, 2, .... p-1 } Field of p Modulo Arithmetic 7 % 3 = 1, 1747 % 241 = 60 a, b  ∈ F  19 ∈...

Mastering Ethereum Part II

Digital signature prove knowledge of a secret without revealing it. Account address are derived directly from private keys. Public key cryptography also known as asymmetric cryptography. Public key can be derived from private keys. A digital signature is code that is produced with private key and the transaction details (the message). A private key is a number between 1 and 2^256 The public key is on a point on an elliptic curve, with an X and Y value. PubK = PrivKey * G a constant generator point Ethereum cryptographic Hash function: Keccak-256 (not the finalized SHA-3 different output) Addresses are hex numbers dervied from the last 20 bytes of the public key. Inter exchange client address protocol (ICAP) checksum prevent wrongly input address. Wallet: serves as the primary user interface for the user to access money, managing keys, address, creating and signing transaction. But at it's core it's a data structure that acts as a container to store the private ke...

Designing Data-Intensive Applications I

The main goals of designing a data-Intensive applications: 1. Reliability: Tolerating hardware and software faults, human error 2. Scalability: Measuring load & performance, latency percentiles, throughput 3. Maintainability: Operability, simplicity and evolvability Databases: storing data Caches: remembering expensive operation Search Indexes: allow users to search data by keywords Stream processing: send message from one process to another Batch processing: periodically crunch a large amount of accumulated data Redis: datastore used as message queses Kafka: message queues with database-like durability guarantees Systems that anticipate faults and cope with them are called fault-tolerant or resilient. 1. Design systems in a way that minimizes opportunities for error. 2. Decouple the places where people make the most mistakes. 3. Test thoroughly from unit tests to whole-system integration tests. 4. Minimize impact in the case of failure 5. Setup monitoring refe...

Mastering Ethereum Part I

Account contains: -Address (rightmost 160 bits of Keccak(SHA-3) hash of public key) -Balance -Nonce -Storage and code Assert(false) compiles to 0xfe, uses up all gas and reverts all changes Big-endian: most significant digits first Little-endian: least significant digits first BIPS: bitcoin improvement proposals Byte code: numeric format virtual machine executable Contract account: An account containing code that executes when receiving a transaction from another account. Contract creation transaction: Special transaction with "zero address" as recipient that register a contact and recode it on the Ethereum blockchain Digital signature: Using a private key which the user produces a short string that can prove with the corresponding public key plus the signature(short string) combine to verify that document(transaction) was created by the user who owns the private key. Gas: The computational cost of an execution on a smart contract. Turing Complete: Gener...

Compilers Principles, Techniques, and Tools Part 1

Chapter 1 Intro to Compiling: A compiler take the "source" language and translate to another language "target" language. It is important for the compiler to report to the user any errors in the source program. There are two parts of compilation: analysis and synthesis. Analysis: breaks down the source program into a tree structure, called syntax tree. Synthesis: constructs the desired target program from the intermediate representation. source program -> compiler -> assembler -> loader/link-editor Lexical Analysis: linear analysis or scanning, how computer reads the source program, reads the characters in source program and group them into a stream of tokens, it identifies keywords,  expressions and statements. Syntax Analysis: parsing, grouping the tokens of the source program into grammatical phrases to synthesize output. Semantic Analysis: Checks for semantic errors then gathers type information for the subsequent code-generation phase. l...