In fiat currencies, law enforcement is necessary for stopping people from breaking the rules of the system.Howerver,Cryptocurrencies need to be enforced purely technologically and without relying on a central authority.
Bitcoin relies on only a handful of relatively simple and well-known cryptographic constructions: cryptographic hashes and digital signatures,zero-knowledge proofs.
Properties of a hash fuction:
- Its input can be any string of any size.
- It produces a fixed-sized output.
- It is efficiently computable.More technically, computing the hash of an n-bit string should have a running time that is O(n).
Three additional properties to be secure for a hash function:
- collision resistance
- hiding
- puzzle friendliness
Collsion resistance:
A hash function H is said to be collision resistant if it is infeasible to find two values, x and y, such that x ≠ y, yet H(x) = H(y).
A collision occurs when two distinct inputs produce the same output.
Consider the following simple method for finding a collision for a hash function with a 256-bit output size: pick 2256 + 1 distinct values, compute the hashes of each of them.
APPLICATION: MESSAGE DIGESTS
To ensure file integrity:
the file people download is the same as the one he uploaded to a online file storage system.
That is, Compare the hash of the downloaded file to the local copy.
Hiding:
A hash function H is said to be hiding if when a secret value r is chosen from a probability distribution that has high min-entropy, then, given H(r ‖ x), it is infeasible to find x.
The hiding property asserts that if we’re given the output of the hash function y = H(x), there’s no feasible way to figure out what the input, x, was
APPLICATION: COMMITMENTS
commitment:
the digital analog of taking a value, sealing it in an envelope, and putting that envelope out on the table where everyone can see it.
---------------------------------------------------
Commitment scheme:
com := commit(msg, nonce) : The commit function takes a message and secret random value, called a nonce, as input and returns a commitment.
verify(com, msg, nonce) : The verify function takes a commitment, nonce, and message as input. It returns true if com == commit(msg, nonce) and false otherwise.
-------------------------------------------------------
Two security peoperties:
Hiding: Given com, it is infeasible to find msg.
Binding: It is infeasible to find two pairs (msg, nonce) and (msg′, nonce′) such that msg ≠ msg′ and commit(msg, nonce) == commit(msg′, nonce′).
To use a commitment scheme :
We first need to generate a random nonce. We then apply the commit function to this nonce together with msg, the value being committed to, and we publish the commitment com. This stage is analogous to putting the sealed envelope on the table. At a later point, if we want to reveal the value that we committed to earlier, we publish the random nonce that we used to create this commitment, and the message, msg. Now anybody can verify that msg was indeed the message committed to earlier. This stage is analogous to opening the envelope.
Implemetation of a commitment scheme:
commit(msg, nonce) := H(nonce ‖ msg).
Nonce is a random 256-bit value.
Then, concatenate the nonce and the message.
Return the hash of this concatenated value as the commitment.
Puzzle friendliness. A hash function H is said to be puzzle friendly if for every possible n-bit output value y, if k is chosen from a distribution with high min-entropy, then it is infeasible to find x such that H(k ‖ x) = y in time significantly less than 2n.
Intuitively, if someone wants to target the hash function to have some particular output value y, and if part of the input has been chosen in a suitably randomized way, then it’s very difficult to find another value that hits exactly that target.
APPLICATION: SEARCH PUZZLE
A search puzzle consists of
• a hash function, H,
• a value, id (which we call the puzzle-ID), chosen from a high min-entropy distribution
• a target set Y.A solution to this puzzle is a value, x, such that
H(id || x) ∈ Y
If a hash funtion is puzzle friendly, then there’s no solving strategy for this puzzle that is much better than just trying random values of x.
Merkle-Damgård transform
As long as we can build a hash function that works on fixed-length inputs, there’s a generic method to convert it into a hash function that works on arbitrary-length inputs.
Compression function
the underlying fixed-length collision-resistant hash function is called the compression function.
The process of Merkle-Damgård transform
Suppose that the compression function takes inputs of length m and produces an output of a smaller length n.
The input to the hash function, which can be of any size, is divided into blocks of length m – n.
The construction works as follows: pass each block together with the output of the previous block into the compression function.
Input length will then be (m – n) + n = m.
Hash pointer:
A hash pointer is a pointer to where data is stored together with a cryptographic hash of the value of this data at some fixed point in time.
Whereas a regular pointer gives you a way to retrieve the information, a hash pointer also allows you to verify that the information hasn’t been changed
Block Chain
Similat to a linked list
Each block not only tells us where the value of the previous block was, but it also contains a digest of that value, which allows us to verify that the value hasn’t been changed.
If an adversary modifies data anywhere in the block chain, it will result in the hash pointer in the following block being incorrect
Merkle Trees
In a Merkle tree, data blocks are grouped in pairs, and the hash of each of these blocks is stored in a parent node. The parent nodes are in turn grouped in pairs, and their hashes stored one level up the tree. This pattern continues up the tree until we reach the root node.
Proof of membership
To prove that a data block is included in the tree only requires showing the blocks in the path from that data block to the root.
If there are n nodes in the tree,it takes about log(n) time for us to verify it.
Two properties of digital signatures
First, only you can make your signature.
Second, the signature is to be tied to a particular document, so that the signature cannot be used to indicate your agreement or endorsement of a different document.
Digital signature scheme
three algorithms are consisted:
-----------------------------------------------------------------
First, (sk, pk) := generateKeys(keysize)
The generateKeys method takes a key size and generates a key pair. The secret key sk is kept privately and used to sign messages. pk is the public verification key that you give to everybody. Anyone with this key can verify your signature.
------------------------------------------------------------------
sig := sign(sk, message)
The sign method takes a message and a secret key, sk, as input and outputs a signature for message under sk.
------------------------------------------------------------------
isValid := verify(pk, message, sig)
The verify method takes a message, a signature, and a public key as input. It returns a boolean value, isValid, that will be true if sig is a valid signature for message under public key pk, and false otherwise.
Unforgeability game
If the attacker is able to successfully output a signature on a message that he has not previously seen, he wins.
If he is unable to do so, the challenger wins, and the digital signature scheme is unforgeable.
We give the secret key to the challenger, and we give the public key to both the challenger and the adversary. So the adversary only knows information that’s public, and his mission is to try to forge a message. The challenger knows the secret key. So he can make signatures.
we allow the adversary to try a number of guesses that is a polynomial function of the key size, but no more (e.g., he cannot try exponentially many guesses).
The challenger runs the verify algorithm to determine whether the signature produced by the attacker is a valid signature on M under the public verification key.
The idea is to take a public key, one of those public verification keys from a digital signature scheme, and equate it to an identity of a person or an actor in a system.
The first rule of Goofycoin is that a designated entity, Goofy, can create new coins whenever he wants and these newly created coins belong to him.
The second rule of Goofycoin is that whoever owns a coin can transfer it to someone else.
Let’s say Goofy wants to transfer a coin that he created to Alice. To do this, he creates a new statement that says “Pay this to Alice” where “this” is a hash pointer that references the coin in question. And as we saw earlier, identities are really just public keys, so “Alice” refers to Alice’s public key. Finally, Goofy signs the string representing the statement. Since Goofy is the one who originally owned that coin, he has to sign any transaction that spends the coin. Once this data structure representing Goofy’s transaction is signed by him, Alice owns the coin. She can prove to anyone that she owns the coin, because she can present the data structure with Goofy’s valid signature. Furthermore, it points to a valid coin that was owned by Goofy. So the validity and ownership of coins are self-evident in the system.
double-spending attack
Someone spends a coin twice.
Goofycoin does not solve the double-spending attack, and therefore it’s not secure.
The first key idea is that a designated entity called Scrooge publishes an append-only ledger containing the history of all transactions.
The append-only property ensures that any data written to this ledger will remain forever in the ledger.
If the ledger is truly append only, we can use it to defend against double spending by requiring all transactions to be written in the ledger before they are accepted.
That way, it will be publicly documented if coins were previously sent to a different owner.
To implement this append-only functionality, Scrooge can build a block chain, which he will digitally sign. It consists of a series of data blocks, each with one transaction in it (in practice, as an optimization, we’d really put multiple transactions in the same block, as Bitcoin does.) Each block has the ID of a transaction, the transaction’s contents, and a hash pointer to the previous block. Scrooge digitally signs the final hash pointer, which binds all the data in this entire structure, and he publishes the signature along with the block chain.
Why do we need a block chain with hash pointers in addition to having Scrooge sign each block?
As long as someone is monitoring the latest hash pointer published by Scrooge, the change will be obvious and easy to catch.
A block chain makes it easy for any two individuals to verify that they have observed the same history of transactions signed by Scrooge.
CreateCoins:
to make new coins.
Datastructure:
(serial number, value, recipent)
TransID: to represent a transaction
num: Each coin has a serial number in the transaction.
value: it’s worth a certain number of scroogecoins.
recipient: a public key that gets the coin.
PayCoins
It consumes some coins (i.e., destroys them) and creates new coins of the same total value.
So if you’re the owner of one of the coins that’s going to be consumed in this transaction, then you need to digitally sign the transaction to say that you’re OK with spending this coin.
The problem here is centralization.much of the early research on cryptosystems assumed there would indeed be some central trusted authority.
The minting of new coins also needs to be decentralized. If we can solve these problems, then we can build a currency that would be like Scroogecoin but without a centralized party. In fact, this would be a system much like Bitcoin.
我正在DocBook中编写文档,并希望以带有页眉和页脚的PDF格式发布它。为此,我有这种风格:通过这段代码,我得到了以下标题:Myfirstchapterblah-blah1我想得到这个:Chapter1:Myfirstchapterblah-blah1我应该调用什么模板来创建这样的自动文本? 最佳答案 尝试以下(尝试是因为我对DocBook不太熟悉):添加到header.content模板。这应该插入“带有章节编号标签的章节标题”。请参阅Docbook文档引用here.Chapter但请注意,title.markup和titlea
我想提示用户输入一些double值,然后存储最小值和最大值,然后打印文本。这是我到目前为止的代码:#include#include#include#includeusingnamespacestd;intmain(){doublemin=1000000000;//Hereismyissue!doublemax=-100000000;//Hereismyissue!for(doubleinput;cin>>input;){if(input=='|')return0;elseif(inputmax){max=input;cout所以我的代码工作正常并且做我想做的,但我对处理双最小值和最大值
以下课程来源于MOOC学习—原课程请见:数据库原理与应用数据管理技术的发展发展三阶段人工管理【1950前】采用批处理;主要用于科学计算;外部设备只有磁带,卡片,纸带等特点:1.数据面向应用2.数据不保(内)存3.数据不能共享4.不具有数据独立性1.数据需要由应用程序自己设计、说明(定义)和管理,程序员在编写程序时自己规定数据的存储结构、存取方法和输入方式等。比如编写C语言,定义一个数组;不同程序的数组元素即使相同也不可以调用;程序结束运行后,内存清空;2.数据独立性是指用户的应用程序与数据的逻辑结构和物理结构是相互独立的;数据逻辑结构变化时,应用程序不变文件系统管理【1950-1960】采用批
我正在学习本书的第一章,但无法弄清楚实验:Addanothervariabletokeeptrackofwhichkindofnumberwasthelargest,aswellaswhatthatlargestnumberwas.这是书中的代码:letinterstingNumbers=["Prime":[2,3,5,7,11,13,17],"Fibonacci":[1,1,2,3,5,8],"Square":[1,4,9,16,25,36],]varlargest=0for(kind,numbers)ininterstingNumbers{fornumberinnumbers{if
我正在学习本书的第一章,但无法弄清楚实验:Addanothervariabletokeeptrackofwhichkindofnumberwasthelargest,aswellaswhatthatlargestnumberwas.这是书中的代码:letinterstingNumbers=["Prime":[2,3,5,7,11,13,17],"Fibonacci":[1,1,2,3,5,8],"Square":[1,4,9,16,25,36],]varlargest=0for(kind,numbers)ininterstingNumbers{fornumberinnumbers{if
逻辑书上写的已经很清楚了,但是书上的代码里有一点错误,最大能取到的数字是‘11111’而不是‘1111’,好了,下面上代码:python:deffun(x):#初始化一个方法用来查看某个搭建某个数字需要多少根火柴棍num=0#初始化一个变量存储数字x需要的总的火柴根数f=[6,2,5,5,4,5,6,3,7,6]ifx//10!=0:#如果这个数是两位数以上,需要从个位数开始逐个计算每个单独的数字需要的火柴个数whilex//10!=0:#当x是两位数以上时digit=x%10#取x的最后一个数字num+=f[digit]#将搭建这个数字需要的火柴数加到需要的总根数里x=x//10#将x中除了
逻辑书上写的已经很清楚了,但是书上的代码里有一点错误,最大能取到的数字是‘11111’而不是‘1111’,好了,下面上代码:python:deffun(x):#初始化一个方法用来查看某个搭建某个数字需要多少根火柴棍num=0#初始化一个变量存储数字x需要的总的火柴根数f=[6,2,5,5,4,5,6,3,7,6]ifx//10!=0:#如果这个数是两位数以上,需要从个位数开始逐个计算每个单独的数字需要的火柴个数whilex//10!=0:#当x是两位数以上时digit=x%10#取x的最后一个数字num+=f[digit]#将搭建这个数字需要的火柴数加到需要的总根数里x=x//10#将x中除了
Chapter1IntroductiontoCryptographyandCryptocurrenciesInfiatcurrencies,lawenforcementisnecessaryforstoppingpeoplefrombreakingtherulesofthesystem.Howerver,Cryptocurrenciesneedtobeenforcedpurelytechnologicallyandwithoutrelyingonacentralauthority.传统法定货币(fiatcurrencies),使用法律手段来确保安全性。但加密货币(cryptocurrencie
Chapter1IntroductiontoCryptographyandCryptocurrenciesInfiatcurrencies,lawenforcementisnecessaryforstoppingpeoplefrombreakingtherulesofthesystem.Howerver,Cryptocurrenciesneedtobeenforcedpurelytechnologicallyandwithoutrelyingonacentralauthority.传统法定货币(fiatcurrencies),使用法律手段来确保安全性。但加密货币(cryptocurrencie
嗨嗨~,这里是一个学习编程已有一年的RICESHOWER_SCREAM!从今天起为了更好的学习编程,我开始在CSDN上正式开始发表文章啦!这也是我的第一次在这种场合发表文章(好紧张~)。目前我的学习进度是把C语言学的差不多了,所以最近这段时间可能会分享一些关于C语言的一些文章,希望可以用我自己的学习经历帮助大家更好的学习吧! 那么既然这是我的第一篇文章,那我就先来讲讲我的编程学习目标吧!一.编程学习目标 目前我对自己学习编程的历程为: C语言————>数据结构与算法————>C++————>系统编程————>网络编程————>数据库————>Java(如果有时间的话会考虑学习)