本文章由老师所上课的内容,加上自己的理解,作为总结写出,并且会提出自己的一些疑问。(疑问会随着进一步学习不断解决)
总结
1.要理解区块链,需要理解Cryptography(密码学),Economics(经济学),Ditributed systems(分布式系统)三部分的内容
1).金融危机,国家灾难都证明了银行或者某一个中心都不是一定可以相信的,因此需要去中心化
2.A new digital currency aims to change the finnancial system should obey rules as follows
1)保护隐私(keep privacy)
Use public,private key pair
公钥用于交易,由私钥生成,公钥能被所有人看到以标识一次交易的对象,而私钥只有所有者所有,其他任何人都不会知道。
"there is not a way to derive from this public key what the private key is "
2)无法修改(can’t be modified)
for the one hand,no one could tamper the data in any of the block before
for the other hand,owing to the signature,only the people who have money can add a tansaction
“there is a big problem with this, that is what’s to stop somebody from just adding a transaction that spends all of someone else’s money”
solve->not every one could add a transaction:
first,we should create a private key and then generate a public key for transaction
then,when sending a transaction, a verified signature of the transaction will also be sent,if anyone change the tansaction,the signature will be invalid
tzy577
3) 货币有限(finite)
4)需要一定的代价或者努力(price or cost)
cpu
5)货币和用户间的联系(relationships between user and transaction)
用户拥有一个私钥,私钥可以生成公钥,用于交易。每一笔交易需要用户用交易数据和私钥生成签名用于确保交易真实
“you can check this siganature against this public key to see whether or not the private key behind this public key”
6)防止双花(prevent double spending)
疑问
1.parity中的library和多重签名钱包
那个攻击者不要承担parity的索赔要求吗?
为什么攻击者不用selfdestruct将所有钱转到自己的账户
“I‘m a newbie and researching over that article.I ended at that contract.
I triggered the kill," devops199 says before adding:
"I believe my kill will fail because most of my “kill” cmds were failed and parity is a big company,big heads,"he says
ok,that’s fine 😃
2.如何保证分布式一致性
3.如何防止双花
4.计算某一块hash时,发生新交易——>放在下一块交易吗?
5.the DAO and Parity attack
1)parity:
A——>B A中有delegate函数
delegatecall可以调用别的合约中的函数在本合约中运行
如果可以写delegate(msg.data),那么A可以调用B函数中的任何函数在A中运行
A调用B中的delegatecall(msg.data))函数,传入B中的攻击函数的名字,那么攻击函数会在A中运行
或者传入的是A自己的权限赋予函数,使B拥有A的权限,那么B可以随意在A中取钱(如parity的多重签名合约被攻击)
正常我们使用delegatecall来调用指定合约的指定函数时应该是使用我们上面所写的那样将函数选择器所
使用的函数id固定以锁定要调用的函数【直接bytes((keccak(“function name”)))】,不过事实上为了灵活性也有一部分的开发人员会使用msg.data来作为直接作为参数
其攻击的流程图:
2)the DAO
使用了创建者为了防止少数人不同意多数人意见而被牺牲而设置的子DAO(child DAO)的漏洞。
hacker申请了一个子DAO,并要求将钱退到子DAO而不是账户上,子DAO的fallback函数获得了转账会递归调用withdraw(),从而获得了以太
在软分叉中,为什么可以将黑客的子DAO限制交易,这不就相当于有一个权限很高的中心可以限制别人的交易?
DAO在筹集钱的前28天不允许转账
但之后的硬分叉违背了区块链的原则
solution
对于DAO,应该将从账户扣钱的代码写在退款之前,对于开发者,应该削减call函数的功能,不能将向合约转账和差错处理放在一个函数内
对于Parity,应谨慎使用delegecall函数,特别其参数时msg.data时,应该仔细审查
6.SHA3
参考: 1.https://zhuanlan.zhihu.com/p/42481392
2.https://anders.com/blockchain/
“Blockchain Demo”