区块链笔记

1. 关于合约的日志

event_signature_hash = web3.keccak(text="eventName(uint32)").hex()
event_filter = web3.eth.filter({
    "address": myContract_address,
    "topics": [event_signature_hash,
               "0x000000000000000000000000000000000000000000000000000000000000000a"],
    })

The topics argument is order-dependent. For non-anonymous events, the first item in the topic list is always the keccack hash of the event signature. Subsequent topic items are the hex encoded values for indexed event arguments. In the above example, the second item is the arg1 value 10 encoded to its hex string representation.

摘自:Filtering — Web3.py 5.20.0 documentation (web3py.readthedocs.io)

意思是说topics 是有顺序的,对于非匿名事件,topics 列表的第一项是事件的签名(keccack hash), 接下来的每一项是事件的参数的hex 编码。上面的例子中,第二项是参数一 10的hex 编码。

In addition to being order-dependent, there are a few more points to recognize when specifying topic filters:

Given a transaction log with topics [A, B], the following topic filters will yield a match:

  • [] “anything”

  • [A] “A in first position (and anything after)”

  • [None, B] “anything in first position AND B in second position (and anything after)”

  • [A, B] “A in first position AND B in second position (and anything after)”

  • [[A, B], [A, B]] “(A OR B) in first position AND (A OR B) in second position (and anything after)”

由于topics 是有顺序的,假如有topics[A,B], 下面的几种topics 过滤器都会产生匹配:

[] 空的-任何

[A]        //第一个位置为A,

[None, B]  //第一个位置为空,第二个位置为B

[A, B]   //第一个位置为A, 第二个位置为B

[[A,B], [A,B]] 第一个位置是A,B中的一个,第二个位置也是A,B中的一个

2. kaccake hash 计算:

print(w3_laptop.keccak(text="swap(uint256,uint256,address,bytes)").hex())

3. 以太坊公钥和私钥

私钥是一个0~2**256范围内的一个数字,大概是10**77这么大个的数。在可见的宇宙中的原子大概是10**80个,也就是说差不多有足够的私钥来给宇宙中的每个原子了。因此你随机选择了某一个私钥后,几乎不可能有另一个人猜到,或者选中同一个。

每个以太坊公钥都是椭圆曲线上的一个点,也就是说每个公钥都是一组(x,y)坐标。这个点由私钥按照特定的算法生成。但是无法由公钥反推私钥。具体来说K = k * G, G是一个常量点,k是私钥,K是公钥。

4. 以太坊使用跟比特币一样的椭圆曲线算法,称为secp256k1:

                                                            y**2  mod p = (x**3 + 7) mod p

p 是一个非常大素数。

5. 椭圆曲线的运算有加法和乘法,乘法相当于多次加法。

6. 以太坊的地址:先由私钥计算出公钥P点(x,y),然后加上前缀04(表示未压缩的点),再计算Keccak-256哈希,即:

                                                         hash = Keccak-256(04xy)

再取哈希的后20个字节。

7. 关于ECDSA (椭圆曲线数字签名算法)是如何保护数据的,可以参考:一文读懂ECDSA算法如何保护数据

    该文章对该算法有详细的描述和推理。

还有关于拥有相同的R值来签名数据包为什么可以反推出私钥的证明。

还可以参考:ECDSA(椭圆曲线数字签名算法) - 简书 (jianshu.com)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值