Skip to content

Commit

Permalink
improve show proof logical
Browse files Browse the repository at this point in the history
  • Loading branch information
waterflier committed Dec 31, 2023
1 parent ec537f3 commit 6a6a6e0
Show file tree
Hide file tree
Showing 4 changed files with 197 additions and 157 deletions.
3 changes: 2 additions & 1 deletion contracts/PublicDataProof.sol
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,14 @@ library PublicDataProof {

if(noise != 0) {
//Enable PoW
pow_hash = _merkleRoot(hashType,m_path,index, _hashLeaf(hashType, bytes.concat(noise, leafdata, nonce)));
pow_hash = _merkleRoot(hashType,m_path,index, _hashLeaf(hashType, bytes.concat(leafdata, nonce, noise)));
}

return (new_root_hash, pow_hash);
}

function lengthFromMixedHash(bytes32 dataMixedHash) public pure returns (uint64) {
//REVIEW 1<<62是常数,会不会每次都消耗GAS计算?
return uint64(uint256(dataMixedHash) >> 192 & ((1 << 62) - 1));
}

Expand Down
11 changes: 7 additions & 4 deletions contracts/gwt.sol
Original file line number Diff line number Diff line change
Expand Up @@ -28,21 +28,24 @@ contract GWTToken is ERC20, Ownable {
}
}

function _calcGWTAmount(uint256 amount) internal pure returns(uint256) {
function _calcGWTAmount(uint256 dmc_amount) internal pure returns(uint256) {
// 1 : 210
return amount * 210;
return dmc_amount * 210;
}

function _calcDMCAmount(uint256 amount) internal pure returns(uint256) {
function _calcDMCAmount(uint256 gwt_amount) internal pure returns(uint256) {
// 210 : 1
return amount / 210;
return gwt_amount / 210;
}

function _update(address sender, address to, uint256 amount) internal override {
require(allow_transfer[sender] || allow_transfer[to], "transfer not allowed");
super._update(sender, to, amount);
}


//REVIEW 把兑换合约独立出去,GWT合约只需要认兑换合约(而不是认DMC合约)就可以。
// 兑换合约是可升级逻辑的。
function exchange(uint256 amount) public {
uint256 gwtAmount = _calcGWTAmount(amount);

Expand Down
Loading

0 comments on commit 6a6a6e0

Please sign in to comment.