test/wrb_gas.js
// Function to calculate merkle roots for Proof-of-Inclusions (PoI)
Function to calculate merkle roots for Proof-of-Inclusions (PoI)
Function to calculate merkle roots for Proof - of - Inclusions ( PoI )
function calculateRoots (levels, drBytes, resBytes) {
  let hash = sha256.create()
  hash.update(web3.utils.hexToBytes(drBytes))
  const drHash = "0x" + hash.hex()
  hash = sha256.create()
  hash.update(web3.utils.hexToBytes(drHash))
  hash.update(web3.utils.hexToBytes(drHash))
  const drTxHash = "0x" + hash.hex()
  let temp = drTxHash
  for (let i = 0; i < levels; i++) {
    hash = sha256.create()
    hash.update(web3.utils.hexToBytes(temp))
    hash.update(web3.utils.hexToBytes(drHash))
    temp = "0x" + hash.hex()
  }
  const expectedDrHash = temp
  hash = sha256.create()
  hash.update(web3.utils.hexToBytes(drTxHash))
  hash.update(web3.utils.hexToBytes(resBytes))
  temp = "0x" + hash.hex()
  for (let i = 0; i < levels; i++) {
    hash = sha256.create()
    hash.update(web3.utils.hexToBytes(temp))
    hash.update(web3.utils.hexToBytes(drHash))
    temp = "0x" + hash.hex()
  }
  const expectedResHash = temp
  return [expectedDrHash, expectedResHash]
}
function calculateRoots ( levels , drBytes , resBytes ) { let hash = sha256 . create ( ) hash . update ( web3 . utils . hexToBytes ( drBytes ) ) const drHash = "0x" + hash . hex ( ) hash = sha256 . create ( ) hash . update ( web3 . utils . hexToBytes ( drHash ) ) hash . update ( web3 . utils . hexToBytes ( drHash ) ) const drTxHash = "0x" + hash . hex ( ) let temp = drTxHash for ( let i = 0 ; i < levels ; i ++ ) { hash = sha256 . create ( ) hash . update ( web3 . utils . hexToBytes ( temp ) ) hash . update ( web3 . utils . hexToBytes ( drHash ) ) temp = "0x" + hash . hex ( ) } const expectedDrHash = temp hash = sha256 . create ( ) hash . update ( web3 . utils . hexToBytes ( drTxHash ) ) hash . update ( web3 . utils . hexToBytes ( resBytes ) ) temp = "0x" + hash . hex ( ) for ( let i = 0 ; i < levels ; i ++ ) { hash = sha256 . create ( ) hash . update ( web3 . utils . hexToBytes ( temp ) ) hash . update ( web3 . utils . hexToBytes ( drHash ) ) temp = "0x" + hash . hex ( ) } const expectedResHash = temp return [ expectedDrHash , expectedResHash ] }
Function to calculate merkle roots for Proof-of-Inclusions (PoI)
Function to calculate merkle roots for Proof - of - Inclusions ( PoI )