Skip to content

Commit

Permalink
remove pos for nonce
Browse files Browse the repository at this point in the history
  • Loading branch information
waterflier committed Dec 26, 2023
1 parent f5bfdd1 commit 26a453b
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 17 deletions.
14 changes: 3 additions & 11 deletions doc/erc/darft.md
Original file line number Diff line number Diff line change
Expand Up @@ -141,18 +141,10 @@ interface IERC721VerfiyDataHash{
TODO: Remove this comment before submitting
-->

No backward compatibility issues found.
1. 虽然存储证明的设计是算法性的,架构无关的。但现在的设计考虑了能在主流的L1上实现
2. 使用HashType来兼容现有的L1,并未未来的扩展留出空间
3. 目前HashType预留了4种,已经使用了两种。如下表:

## Test Cases

<!--
This section is optional for non-Core EIPs.
The Test Cases section should include expected input/output pairs, but may include a succinct set of executable tests. It should not include project build files. No new requirements may be be introduced here (meaning an implementation following only the Specification section should pass all tests here.)
If the test suite is too large to reasonably be included inline, then consider adding it as one or more files in `../assets/eip-####/`. External links will not be allowed
TODO: Remove this comment before submitting
-->

## Reference Implementation

Expand Down
10 changes: 4 additions & 6 deletions doc/erc/demo.sol
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ contract PublicStorageProofDemo {
}
}


function showStorageProofWihtPoW(bytes32 dataMixedHash, uint256 nonce_block_high,uint32 index_m, bytes16[] calldata m_path, bytes calldata leafdata,bytes32 noise) public {
StoargeProof storage last_proof = show_datas[dataMixedHash];
// 如果已经存在,判断区块高度差,决定这是一个新的挑战还是对旧的挑战的更新
Expand Down Expand Up @@ -95,7 +94,6 @@ contract PublicStorageProofDemo {
require(block.number - nonce_block_high < 256, "nonce block too old");

bytes32 nonce = blockhash(nonce_block_high);
uint16 pos = uint16(uint256(nonce) % 960 + 32);

//REVIEW: 应该先验证index落在MixedHash包含的长度范围内
require(index < lengthFromMixedHash(dataMixedHash) >> 10 + 1, "invalid index");
Expand All @@ -118,18 +116,18 @@ contract PublicStorageProofDemo {
// 只比较后192位
require(dataHash & bytes32(uint256(1 << 192 - 1)) == dataMixedHash & bytes32(uint256(1 << 192 - 1)), "mixhash mismatch");

//计算在leaf_data中插入nonce,noise后的root_hash
//REVIEW:似乎不需要计算插入位置,只是简单的在Leaf的数据后部和头部插入,也足够满足我们的设计目的了?
bytes memory new_leafdata;
if(noise != 0) {
//Enable PoW
new_leafdata = bytes.concat(leafdata[:pos], nonce,leafdata[pos+32:]);
new_leafdata = bytes.concat(leafdata, nonce);
bytes32 new_root_hash = _merkleRoot(hashType,m_path,index, _hashLeaf(hashType,new_leafdata));
new_leafdata = bytes.concat(leafdata[:pos-32],noise, nonce, leafdata[pos+32:]);

new_leafdata = bytes.concat(noise, leafdata, nonce);
return (new_root_hash,_merkleRoot(hashType,m_path,index, _hashLeaf(hashType,new_leafdata)));
} else {
//Disable PoW
new_leafdata = bytes.concat(leafdata[:pos], nonce, leafdata[pos+32:]);
new_leafdata = bytes.concat(leafdata, nonce);
return (_merkleRoot(hashType,m_path,index, _hashLeaf(hashType,new_leafdata)),0);
}
}
Expand Down

0 comments on commit 26a453b

Please sign in to comment.