CRYPTO NEWS

What’s the logic behind the way block proofs (in GetBlockProof) is calculated?

Bitcoin Core uses GetBlockProof() function to determine the contribution of a block to the total difficulty of the current chain, aka, nChainWork in CBlockIndex. I’m having trouble understanding the logic in that implementation.

Let’s ignore the math gymnastics done there to avoid overflowing off uint256. The only part we need is the beginning of the comment:

// We need to compute 2**256 / (bnTarget+1) 

And the question is simply, why?!

If I want to calculate the difficulty contribution of a block to the chain, my (possibly naive) logic would be: The lower the block hash value, the higher its contribution. While the equation mentioned in the comment achieves that, it doesn’t do so linearly, but in a f(x)=1/x fashion. I don’t get why. Again, my (possibly naive) implementation would simply be:

~arith_uint256(0) - UintToArith256(block.GetBlockHash()) 

which basically means: The lower the hash of a block, the higher its contribution to the difficulty. And if using the block hash is bad for some reason (I’d appreciate explaining why if it’s the case), a similar proportionality can be made with just the target:

~arith_uint256(0) - bnTarget 

Can someone please explain the reason for that division choice?

Crypto Hats, Crypto Shirts, Crypto Socks, Crypto Clothing

Paycheck contract keeps trying to send to a new random contract address/not working properly

I’m very new to Solidity and facing a dumb problem. I’m trying to create a contract that pays my employee Mike (ex). Here, withdraw() function worked as expected. It returns ETH to my wallet again from the contract after I funded (fund()). Also the contract balance(balance()) is updated accordingly. However, for payMike function, when I::Listen

I’m very new to Solidity and facing a dumb problem. I’m trying to create a contract that pays my employee Mike (ex).

Here, withdraw() function worked as expected. It returns ETH to my wallet again from the contract after I funded (fund()). Also the contract balance(balance()) is updated accordingly.

However, for payMike function, when I put my wallet address to _to and put the value in paycheckInUsd here for instance, 111 (around 0.1 eth), like the photo I attached below, it keeps trying to send to a randomly generated new contract address(0xEOO~). Also even after the transaction confirmed, the balance of the contract is not updated which I assume means the transfer in payMike didn’t work or I wrote something very wrong. Please let me know what I’m doing wrong here or any advice on my code would be greatly appreciated. Thank you.

// SPDX-License-Identifier: MIT  pragma solidity ^0.8.7;  import "@chainlink/contracts/src/v0.8/interfaces/AggregatorV3Interface.sol";  // error minimumUSDError();  contract FundMe {      mapping(address => uint256) public addressToAmountFunded;     address public owner;       constructor() public {         owner = msg.sender;      }      function fund() public payable {         // $500 in gwei terms         uint256 minimumUSD = 50 * 10 ** 18;         require(minimumUSD < getConversionRate(msg.value), "You need to spend more ETH!");         // if (msg.value < minimumUSD) {         //     revert minimumUSDError();         // }          addressToAmountFunded[msg.sender] += msg.value;         // what the ETH -> USD conversion rate            }      function getVersion() public view returns(uint256) {         // we have a contract that has these functions defined in that interface, located at this address         AggregatorV3Interface priceFeed = AggregatorV3Interface(0x8A753747A1Fa494EC906cE90E9f37563A8AF630e);         return priceFeed.version();    }     function getPrice() public view returns(uint256) {         AggregatorV3Interface priceFeed = AggregatorV3Interface(0x8A753747A1Fa494EC906cE90E9f37563A8AF630e);         (,int256 answer,,,) = priceFeed.latestRoundData();         return uint256(answer*1000000000);    }      // 1000000000    function getConversionRate(uint256 ethAmount) public view returns(uint256) {        uint256 ethPrice = getPrice();        uint256 ethAmountInUsd = (ethPrice * ethAmount) / 100000000000000000;        return ethAmountInUsd;    }     modifier onlyOwner {        require(msg.sender == owner);        _;    }     function withdraw() public onlyOwner payable {        // transfer, send, call        payable(msg.sender).transfer(address(this).balance);    }      function payMike(address payable _to, uint256 paycheckInUsd) public payable {        uint256 ethPrice = getPrice() ;        uint256 paycheckInWei = (paycheckInUsd) / (ethPrice * 10);        _to.transfer(paycheckInWei);    }      function balance() public view returns(uint256) {        return address(this).balance;    } } 

enter image description here

What’s the logic behind the way block proofs (in GetBlockProof) is calculated?

Shopping cart
There are no products in the cart!
Continue shopping
0