From 90da08062528406dcba739e95459a86787da5adc Mon Sep 17 00:00:00 2001 From: lordforever Date: Thu, 13 Jul 2023 04:59:57 +0530 Subject: [PATCH 1/6] internal library --- .solhint.json | 2 +- contracts/DealStatus.sol | 47 ++++++++++++++-------- contracts/data-segment/Cid.sol | 6 +-- contracts/data-segment/Const.sol | 2 +- contracts/data-segment/Proof.sol | 33 ++++++--------- contracts/data-segment/ProofTypes.sol | 2 +- contracts/interfaces/IAggregatorOracle.sol | 11 +++-- hardhat.config.js | 14 +++---- 8 files changed, 64 insertions(+), 53 deletions(-) diff --git a/.solhint.json b/.solhint.json index f3e31e8..78c527b 100644 --- a/.solhint.json +++ b/.solhint.json @@ -1,7 +1,7 @@ { "extends": "solhint:recommended", "rules": { - "compiler-version": ["error", "^0.8.0"], + "compiler-version": ["error", "^0.8.17"], "func-visibility": ["warn", { "ignoreConstructors": true }] } } diff --git a/contracts/DealStatus.sol b/contracts/DealStatus.sol index 1356766..8722e3f 100644 --- a/contracts/DealStatus.sol +++ b/contracts/DealStatus.sol @@ -1,5 +1,5 @@ // SPDX-License-Identifier: MIT -pragma solidity ^0.8.0; +pragma solidity ^0.8.17; // Uncomment this line to use console.log // import "hardhat/console.sol"; @@ -8,14 +8,13 @@ import "./interfaces/IAggregatorOracle.sol"; import "./data-segment/Proof.sol"; import {MarketAPI} from "./mocks/MarketAPIMock.sol"; -import { MarketTypes } from "@zondax/filecoin-solidity/contracts/v0.8/types/MarketTypes.sol"; +import {MarketTypes} from "@zondax/filecoin-solidity/contracts/v0.8/types/MarketTypes.sol"; // Delta that implements the AggregatorOracle interface contract DealStatus is IAggregatorOracle, Proof { - uint256 private transactionId; - mapping (uint256 => bytes) private txIdToCid; - mapping (bytes => uint64[]) private cidToDealIds; + mapping(uint256 => bytes) private txIdToCid; + mapping(bytes => uint64[]) private cidToDealIds; event ActiveDeals(uint64[] activeDealIDs); event ExpiringDeals(uint64[] expiringDealIDs); @@ -24,9 +23,16 @@ contract DealStatus is IAggregatorOracle, Proof { transactionId = 0; } + function computeExpectedAuxDataPublic( + InclusionProof memory _proof, + InclusionVerifierData memory _verifierData + ) public pure returns (InclusionAuxData memory) { + return computeExpectedAuxData(_proof, _verifierData); + } + function submit(bytes memory _cid) external returns (uint256) { // Increment the transaction ID - transactionId++; + transactionId++; // Save _cid txIdToCid[transactionId] = _cid; @@ -36,7 +42,12 @@ contract DealStatus is IAggregatorOracle, Proof { return transactionId; } - function complete(uint256 _id, uint64 _dealId, InclusionProof memory _proof, InclusionVerifierData memory _verifierData) external returns (InclusionAuxData memory) { + function complete( + uint256 _id, + uint64 _dealId, + InclusionProof memory _proof, + InclusionVerifierData memory _verifierData + ) external returns (InclusionAuxData memory) { require(_id <= transactionId, "Delta.complete: invalid transaction id"); // Emit the event emit CompleteAggregatorRequest(_id, _dealId); @@ -45,14 +56,14 @@ contract DealStatus is IAggregatorOracle, Proof { bytes memory cid = txIdToCid[_id]; for (uint i = 0; i < cidToDealIds[cid].length; i++) { if (cidToDealIds[cid][i] == _dealId) { - return this.computeExpectedAuxData(_proof, _verifierData); + return this.computeExpectedAuxDataPublic(_proof, _verifierData); } } cidToDealIds[cid].push(_dealId); // Perform validation logic // return this.computeExpectedAuxDataWithDeal(_dealId, _proof, _verifierData); - return this.computeExpectedAuxData(_proof, _verifierData); + return this.computeExpectedAuxDataPublic(_proof, _verifierData); } // allDealIds should return all the deal ids created by the aggregator @@ -60,7 +71,7 @@ contract DealStatus is IAggregatorOracle, Proof { return cidToDealIds[_cid]; } - // getActiveDeals should return all the _cid's active dealIds + // getActiveDeals should return all the _cid's active dealIds function getActiveDeals(bytes memory _cid) external returns (uint64[] memory activeDealIDs) { // get all the deal ids for the cid activeDealIDs = this.getAllDeals(_cid); @@ -68,8 +79,9 @@ contract DealStatus is IAggregatorOracle, Proof { for (uint i = 0; i < activeDealIDs.length; i++) { uint64 dealID = activeDealIDs[i]; // get the deal's expiration epoch - MarketTypes.GetDealActivationReturn memory dealActivationStatus = MarketAPI.getDealActivation(dealID); - + MarketTypes.GetDealActivationReturn memory dealActivationStatus = MarketAPI + .getDealActivation(dealID); + if (dealActivationStatus.terminated > 0 || dealActivationStatus.activated == -1) { delete activeDealIDs[i]; } @@ -79,8 +91,11 @@ contract DealStatus is IAggregatorOracle, Proof { } // getExpiringDeals should return all the deals' dealIds if they are expiring within `epochs` - function getExpiringDeals(bytes memory _cid, uint64 epochs) external returns (uint64[] memory expiringDealIDs) { - // the logic is similar to the above, but use this api call: + function getExpiringDeals( + bytes memory _cid, + uint64 epochs + ) external returns (uint64[] memory expiringDealIDs) { + // the logic is similar to the above, but use this api call: // https://github.com/Zondax/filecoin-solidity/blob/master/contracts/v0.8/MarketAPI.sol#LL110C9-L110C9 expiringDealIDs = this.getAllDeals(_cid); @@ -88,7 +103,7 @@ contract DealStatus is IAggregatorOracle, Proof { uint64 dealID = expiringDealIDs[i]; // get the deal's expiration epoch MarketTypes.GetDealTermReturn memory dealTerm = MarketAPI.getDealTerm(dealID); - + if (block.timestamp < uint64(dealTerm.end) - epochs) { delete expiringDealIDs[i]; } @@ -96,4 +111,4 @@ contract DealStatus is IAggregatorOracle, Proof { emit ExpiringDeals(expiringDealIDs); } -} \ No newline at end of file +} diff --git a/contracts/data-segment/Cid.sol b/contracts/data-segment/Cid.sol index 07a045e..d70b527 100644 --- a/contracts/data-segment/Cid.sol +++ b/contracts/data-segment/Cid.sol @@ -1,5 +1,5 @@ // SPDX-License-Identifier: UNLICENSED -pragma solidity ^0.8.9; +pragma solidity ^0.8.17; // Uncomment this line to use console.log // import "hardhat/console.sol"; @@ -7,7 +7,7 @@ import "./Const.sol"; library Cid { // cidToPieceCommitment converts a CID to a piece commitment. - function cidToPieceCommitment(bytes memory _cb) public pure returns (bytes32) { + function cidToPieceCommitment(bytes memory _cb) internal pure returns (bytes32) { require( _cb.length == CID_COMMP_HEADER_LENGTH + MERKLE_TREE_NODE_SIZE, "wrong length of CID" @@ -25,7 +25,7 @@ library Cid { } // pieceCommitmentToCid converts a piece commitment to a CID. - function pieceCommitmentToCid(bytes32 _commp) public pure returns (bytes memory) { + function pieceCommitmentToCid(bytes32 _commp) internal pure returns (bytes memory) { bytes memory cb = abi.encodePacked(CID_COMMP_HEADER, _commp); return cb; } diff --git a/contracts/data-segment/Const.sol b/contracts/data-segment/Const.sol index 58f0c4a..df8835b 100644 --- a/contracts/data-segment/Const.sol +++ b/contracts/data-segment/Const.sol @@ -1,5 +1,5 @@ // SPDX-License-Identifier: UNLICENSED -pragma solidity ^0.8.9; +pragma solidity ^0.8.17; // Uncomment this line to use console.log // import "hardhat/console.sol"; diff --git a/contracts/data-segment/Proof.sol b/contracts/data-segment/Proof.sol index fb820db..9360e77 100644 --- a/contracts/data-segment/Proof.sol +++ b/contracts/data-segment/Proof.sol @@ -1,5 +1,5 @@ // SPDX-License-Identifier: UNLICENSED -pragma solidity ^0.8.9; +pragma solidity ^0.8.17; // Uncomment this line to use console.log // import "hardhat/console.sol"; @@ -18,7 +18,7 @@ contract Proof { function computeExpectedAuxData( InclusionProof memory ip, InclusionVerifierData memory verifierData - ) public pure returns (InclusionAuxData memory) { + ) internal pure returns (InclusionAuxData memory) { require( isPow2(uint64(verifierData.sizePc)), "Size of piece provided by verifier is not power of two" @@ -41,10 +41,7 @@ contract Proof { ); bytes32 enNode = truncatedHash(serialize(en)); bytes32 assumedCommPa2 = computeRoot(ip.proofIndex, enNode); - require( - assumedCommPa == assumedCommPa2, - "aggregator's data commitments don't match" - ); + require(assumedCommPa == assumedCommPa2, "aggregator's data commitments don't match"); (bool ok2, uint64 assumedSizePa2) = checkedMultiply( uint64(1) << uint64(ip.proofIndex.path.length), @@ -63,7 +60,7 @@ contract Proof { uint64 dealId, InclusionProof memory ip, InclusionVerifierData memory verifierData - ) public returns (InclusionAuxData memory) { + ) internal returns (InclusionAuxData memory) { InclusionAuxData memory inclusionAuxData = computeExpectedAuxData(ip, verifierData); validateInclusionAuxData(dealId, inclusionAuxData); return inclusionAuxData; @@ -102,10 +99,7 @@ contract Proof { } // computeRoot computes the root of a Merkle tree given a leaf and a Merkle proof. - function computeRoot( - ProofData memory d, - bytes32 subtree - ) public pure returns (bytes32) { + function computeRoot(ProofData memory d, bytes32 subtree) internal pure returns (bytes32) { require(d.path.length < 64, "merkleproofs with depths greater than 63 are not supported"); require(d.index >> d.path.length == 0, "index greater than width of the tree"); @@ -126,7 +120,7 @@ contract Proof { } // computeNode computes the parent node of two child nodes - function computeNode(bytes32 left, bytes32 right) public pure returns (bytes32) { + function computeNode(bytes32 left, bytes32 right) internal pure returns (bytes32) { bytes32 digest = sha256(abi.encodePacked(left, right)); return truncate(digest); } @@ -177,15 +171,12 @@ contract Proof { ProofData memory proof, bytes32 root, bytes32 leaf - ) public pure returns (bool) { + ) internal pure returns (bool) { return computeRoot(proof, leaf) == root; } // processProof computes the root of the merkle tree given the leaf and the inclusion proof. - function processProof( - ProofData memory proof, - bytes32 leaf - ) internal pure returns (bytes32) { + function processProof(ProofData memory proof, bytes32 leaf) internal pure returns (bytes32) { bytes32 computedHash = leaf; for (uint256 i = 0; i < proof.path.length; i++) { computedHash = hashNode(computedHash, proof.path[i]); @@ -194,14 +185,14 @@ contract Proof { } // hashNode hashes the given node with the given left child. - function hashNode(bytes32 left, bytes32 right) public pure returns (bytes32) { + function hashNode(bytes32 left, bytes32 right) internal pure returns (bytes32) { bytes32 truncatedData = sha256(abi.encodePacked(left, right)); truncatedData &= TRUNCATOR; return truncatedData; } // truncatedHash computes the truncated hash of the given data. - function truncatedHash(bytes memory data) public pure returns (bytes32) { + function truncatedHash(bytes memory data) internal pure returns (bytes32) { bytes32 truncatedData = sha256(abi.encodePacked(data)); truncatedData &= TRUNCATOR; return truncatedData; @@ -222,7 +213,7 @@ contract Proof { } // computeChecksum computes the checksum of the given segment description. - function computeChecksum(SegmentDesc memory _sd) public pure returns (bytes16) { + function computeChecksum(SegmentDesc memory _sd) internal pure returns (bytes16) { bytes memory serialized = serialize(_sd); bytes32 digest = sha256(serialized); digest &= hex"ffffffffffffffffffffffffffffff3f"; @@ -230,7 +221,7 @@ contract Proof { } // serialize serializes the given segment description. - function serialize(SegmentDesc memory sd) public pure returns (bytes memory) { + function serialize(SegmentDesc memory sd) internal pure returns (bytes memory) { bytes memory result = new bytes(ENTRY_SIZE); // Pad commDs diff --git a/contracts/data-segment/ProofTypes.sol b/contracts/data-segment/ProofTypes.sol index 5584ef1..731e413 100644 --- a/contracts/data-segment/ProofTypes.sol +++ b/contracts/data-segment/ProofTypes.sol @@ -1,5 +1,5 @@ // SPDX-License-Identifier: UNLICENSED -pragma solidity ^0.8.9; +pragma solidity ^0.8.17; // Uncomment this line to use console.log // import "hardhat/console.sol"; diff --git a/contracts/interfaces/IAggregatorOracle.sol b/contracts/interfaces/IAggregatorOracle.sol index 972f154..196f79b 100644 --- a/contracts/interfaces/IAggregatorOracle.sol +++ b/contracts/interfaces/IAggregatorOracle.sol @@ -1,5 +1,5 @@ // SPDX-License-Identifier: MIT -pragma solidity ^0.8.0; +pragma solidity ^0.8.17; import "../data-segment/Proof.sol"; @@ -14,7 +14,12 @@ interface IAggregatorOracle { function submit(bytes memory cid) external returns (uint256 id); // Callback function that is called by the aggregator - function complete(uint256 _id, uint64 _dealId, InclusionProof memory _proof, InclusionVerifierData memory _verifierData) external returns (InclusionAuxData memory); + function complete( + uint256 _id, + uint64 _dealId, + InclusionProof memory _proof, + InclusionVerifierData memory _verifierData + ) external returns (InclusionAuxData memory); // Get all deal IDs for a specified cid function getAllDeals(bytes memory _cid) external returns (uint64[] memory); @@ -24,4 +29,4 @@ interface IAggregatorOracle { // getExpiringDeals should return all the deals' dealIds if they are expiring within `epochs` function getExpiringDeals(bytes memory _cid, uint64 epochs) external returns (uint64[] memory); -} \ No newline at end of file +} diff --git a/hardhat.config.js b/hardhat.config.js index f7018f0..1076e52 100644 --- a/hardhat.config.js +++ b/hardhat.config.js @@ -10,14 +10,14 @@ module.exports = { solidity: { version: "0.8.17", settings: { - optimizer: { - enabled: true, - runs: 1000, - details: { yul: false }, - }, + optimizer: { + enabled: true, + runs: 200, + details: { yul: false }, + }, }, - }, - defaultNetwork: "localnet", + }, + defaultNetwork: "calibrationnet", networks: { localnet: { chainId: 31415926, From 889bf7302ecf2e641028235c8fc995776e1efee4 Mon Sep 17 00:00:00 2001 From: lordforever Date: Sun, 6 Aug 2023 18:07:46 +0530 Subject: [PATCH 2/6] conflicts resolved --- .gitignore | 4 +- contracts/DealStatus.sol | 2 +- contracts/data-segment/Cid.sol | 2 +- contracts/data-segment/Proof.sol | 58 +++++++++++++++----------- deploy/00_deploy.js | 71 ++++++++++++++------------------ 5 files changed, 72 insertions(+), 65 deletions(-) diff --git a/.gitignore b/.gitignore index 236d2d5..d433056 100644 --- a/.gitignore +++ b/.gitignore @@ -101,4 +101,6 @@ lint/tmp/ gas-report.txt -contracts/test/fuzzing/crytic-export \ No newline at end of file +contracts/test/fuzzing/crytic-export + +yarn.lock \ No newline at end of file diff --git a/contracts/DealStatus.sol b/contracts/DealStatus.sol index 1758729..bcc60b6 100644 --- a/contracts/DealStatus.sol +++ b/contracts/DealStatus.sol @@ -54,7 +54,7 @@ contract DealStatus is IAggregatorOracle, Proof { bytes memory cid = txIdToCid[_id]; for (uint256 i = 0; i < cidToDeals[cid].length; i++) { if (cidToDeals[cid][i].dealId == _dealId) { - return this.computeExpectedAuxData(_proof, _verifierData); + return this.computeExpectedAuxDataPublic(_proof, _verifierData); } } diff --git a/contracts/data-segment/Cid.sol b/contracts/data-segment/Cid.sol index f94fd04..d70b527 100644 --- a/contracts/data-segment/Cid.sol +++ b/contracts/data-segment/Cid.sol @@ -7,7 +7,7 @@ import "./Const.sol"; library Cid { // cidToPieceCommitment converts a CID to a piece commitment. - function cidToPieceCommitment(bytes memory _cb) public pure returns (bytes32) { + function cidToPieceCommitment(bytes memory _cb) internal pure returns (bytes32) { require( _cb.length == CID_COMMP_HEADER_LENGTH + MERKLE_TREE_NODE_SIZE, "wrong length of CID" diff --git a/contracts/data-segment/Proof.sol b/contracts/data-segment/Proof.sol index 46967cc..a53d171 100644 --- a/contracts/data-segment/Proof.sol +++ b/contracts/data-segment/Proof.sol @@ -23,28 +23,30 @@ contract Proof { isPow2(uint64(verifierData.sizePc)), "Size of piece provided by verifier is not power of two" ); - function computeExpectedAuxData(InclusionProof memory ip, InclusionVerifierData memory verifierData) - public - pure - returns (InclusionAuxData memory) - { - require(isPow2(uint64(verifierData.sizePc)), "Size of piece provided by verifier is not power of two"); bytes32 commPc = verifierData.commPc.cidToPieceCommitment(); bytes32 assumedCommPa = computeRoot(ip.proofSubtree, commPc); - (bool ok, uint64 assumedSizePa) = - checkedMultiply(uint64(1) << uint64(ip.proofSubtree.path.length), uint64(verifierData.sizePc)); + (bool ok, uint64 assumedSizePa) = checkedMultiply( + uint64(1) << uint64(ip.proofSubtree.path.length), + uint64(verifierData.sizePc) + ); require(ok, "assumedSizePa overflow"); uint64 dataOffset = ip.proofSubtree.index * uint64(verifierData.sizePc); - SegmentDesc memory en = makeDataSegmentIndexEntry(Fr32(commPc), dataOffset, uint64(verifierData.sizePc)); + SegmentDesc memory en = makeDataSegmentIndexEntry( + Fr32(commPc), + dataOffset, + uint64(verifierData.sizePc) + ); bytes32 enNode = truncatedHash(serialize(en)); bytes32 assumedCommPa2 = computeRoot(ip.proofIndex, enNode); require(assumedCommPa == assumedCommPa2, "aggregator's data commitments don't match"); - (bool ok2, uint64 assumedSizePa2) = - checkedMultiply(uint64(1) << uint64(ip.proofIndex.path.length), BYTES_IN_DATA_SEGMENT_ENTRY); + (bool ok2, uint64 assumedSizePa2) = checkedMultiply( + uint64(1) << uint64(ip.proofIndex.path.length), + BYTES_IN_DATA_SEGMENT_ENTRY + ); require(ok2, "assumedSizePau64 overflow"); require(assumedSizePa == assumedSizePa2, "aggregator's data size doesn't match"); @@ -65,28 +67,39 @@ contract Proof { } // validateInclusionAuxData validates that the deal is activated and not terminated. - function validateInclusionAuxData(uint64 dealId, InclusionAuxData memory inclusionAuxData) internal { + function validateInclusionAuxData( + uint64 dealId, + InclusionAuxData memory inclusionAuxData + ) internal { // check that the deal is not terminated - MarketTypes.GetDealActivationReturn memory dealActivation = MarketAPI.getDealActivation(dealId); + MarketTypes.GetDealActivationReturn memory dealActivation = MarketAPI.getDealActivation( + dealId + ); require(dealActivation.terminated <= 0, "Deal is terminated"); require(dealActivation.activated > 0, "Deal is not activated"); - MarketTypes.GetDealDataCommitmentReturn memory dealDataCommitment = MarketAPI.getDealDataCommitment(dealId); - require(keccak256(dealDataCommitment.data) == keccak256(inclusionAuxData.commPa), "Deal commD doesn't match"); + MarketTypes.GetDealDataCommitmentReturn memory dealDataCommitment = MarketAPI + .getDealDataCommitment(dealId); + require( + keccak256(dealDataCommitment.data) == keccak256(inclusionAuxData.commPa), + "Deal commD doesn't match" + ); require(dealDataCommitment.size == inclusionAuxData.sizePa, "Deal size doesn't match"); } // validateIndexEntry validates that the index entry is in the correct position in the index. function validateIndexEntry(InclusionProof memory ip, uint64 assumedSizePa2) internal pure { uint64 idxStart = indexAreaStart(assumedSizePa2); - (bool ok3, uint64 indexOffset) = checkedMultiply(ip.proofIndex.index, BYTES_IN_DATA_SEGMENT_ENTRY); + (bool ok3, uint64 indexOffset) = checkedMultiply( + ip.proofIndex.index, + BYTES_IN_DATA_SEGMENT_ENTRY + ); require(ok3, "indexOffset overflow"); require(indexOffset >= idxStart, "index entry at wrong position"); } // computeRoot computes the root of a Merkle tree given a leaf and a Merkle proof. function computeRoot(ProofData memory d, bytes32 subtree) internal pure returns (bytes32) { - function computeRoot(ProofData memory d, bytes32 subtree) public pure returns (bytes32) { require(d.path.length < 64, "merkleproofs with depths greater than 63 are not supported"); require(d.index >> d.path.length == 0, "index greater than width of the tree"); @@ -159,7 +172,6 @@ contract Proof { bytes32 root, bytes32 leaf ) internal pure returns (bool) { - function verify(ProofData memory proof, bytes32 root, bytes32 leaf) public pure returns (bool) { return computeRoot(proof, leaf) == root; } @@ -187,11 +199,11 @@ contract Proof { } // makeDataSegmentIndexEntry creates a new data segment index entry. - function makeDataSegmentIndexEntry(Fr32 memory commP, uint64 offset, uint64 size) - internal - pure - returns (SegmentDesc memory) - { + function makeDataSegmentIndexEntry( + Fr32 memory commP, + uint64 offset, + uint64 size + ) internal pure returns (SegmentDesc memory) { SegmentDesc memory en; en.commDs = bytes32(commP.value); en.offset = offset; diff --git a/deploy/00_deploy.js b/deploy/00_deploy.js index 7f743db..f9302d5 100644 --- a/deploy/00_deploy.js +++ b/deploy/00_deploy.js @@ -8,46 +8,39 @@ const wallet = new ethers.Wallet(private_key, ethers.provider) module.exports = async ({ deployments }) => { // ethers is available in the global scope - const [deployer] = await ethers.getSigners(); - console.log( - "Deploying the contracts with the account:", - await deployer.getAddress() - ); - - console.log("Account balance:", (await deployer.getBalance()).toString()); - - const accounts = await ethers.getSigners(); - //console.log(accounts[0]) - - console.log("Wallet Ethereum Address:", wallet.address); - const chainId = network.config.chainId; - - //deploy DealStatus - const Cid = await ethers.getContractFactory('Cid', accounts[0]); - console.log('Deploying Cid...'); - const cid = await Cid.deploy(); - await cid.deployed() - console.log('Cid deployed to:', cid.address); - - //deploy DealStatus - const Proof = await ethers.getContractFactory('Proof', { - libraries: { - Cid: cid.address, - }, - }); - console.log('Deploying Proof...'); - const proof = await Proof.deploy(); - await proof.deployed() - console.log('Proof deployed to:', proof.address); + const [deployer] = await ethers.getSigners() + console.log("Deploying the contracts with the account:", await deployer.getAddress()) + + console.log("Account balance:", (await deployer.getBalance()).toString()) + + const accounts = await ethers.getSigners() + console.log(accounts[0]) + + console.log("Wallet Ethereum Address:", wallet.address) + const chainId = network.config.chainId + + // //deploy DealStatus + // const Cid = await ethers.getContractFactory('Cid', accounts[0]); + // console.log('Deploying Cid...'); + // const cid = await Cid.deploy(); + // await cid.deployed() + // console.log('Cid deployed to:', cid.address); + + // //deploy DealStatus + // const Proof = await ethers.getContractFactory('Proof', { + // libraries: { + // Cid: cid.address, + // }, + // }); + // console.log('Deploying Proof...'); + // const proof = await Proof.deploy(); + // await proof.deployed() + // console.log('Proof deployed to:', proof.address); //deploy DealStatus - const dealStatus = await ethers.getContractFactory('DealStatus', { - libraries: { - Cid: cid.address, - }, - }); - console.log('Deploying DealStatus...'); - const dealstatus = await dealStatus.deploy(); + const dealStatus = await ethers.getContractFactory("DealStatus", accounts[0]) + console.log("Deploying DealStatus...") + const dealstatus = await dealStatus.deploy() await dealstatus.deployed() - console.log('DealStatus deployed to:', dealstatus.address); + console.log("DealStatus deployed to:", dealstatus.address) } From fe9a063e859d3a4353ebe7b0b2318a75de49ecf2 Mon Sep 17 00:00:00 2001 From: lordforever Date: Sun, 6 Aug 2023 18:15:40 +0530 Subject: [PATCH 3/6] runs reinstated --- hardhat.config.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hardhat.config.js b/hardhat.config.js index 1076e52..951a229 100644 --- a/hardhat.config.js +++ b/hardhat.config.js @@ -12,7 +12,7 @@ module.exports = { settings: { optimizer: { enabled: true, - runs: 200, + runs: 1000, details: { yul: false }, }, }, From 4f1ebbecd5d7363038aeb36d5ce8cee71ae87b1e Mon Sep 17 00:00:00 2001 From: Parva Jain Date: Fri, 3 Nov 2023 20:44:15 +0530 Subject: [PATCH 4/6] fixed getExpiringDeals --- contracts/DealStatus.sol | 5 ++++- contracts/mocks/DealStatusMock.sol | 5 ++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/contracts/DealStatus.sol b/contracts/DealStatus.sol index db369e6..e1d2ff1 100644 --- a/contracts/DealStatus.sol +++ b/contracts/DealStatus.sol @@ -117,7 +117,10 @@ contract DealStatus is IAggregatorOracle, Proof { // get the deal's expiration epoch MarketTypes.GetDealTermReturn memory dealTerm = MarketAPI.getDealTerm(dealId); - if (block.number < uint64(dealTerm.end) - epochs || block.number > uint64(dealTerm.end)) { + if ( + (block.number + epochs < uint64(dealTerm.start) + uint64(dealTerm.end)) || + (block.number > uint64(dealTerm.start) + uint64(dealTerm.end)) + ) { delete expiringDealIds[i]; } } diff --git a/contracts/mocks/DealStatusMock.sol b/contracts/mocks/DealStatusMock.sol index 854de95..c54f525 100644 --- a/contracts/mocks/DealStatusMock.sol +++ b/contracts/mocks/DealStatusMock.sol @@ -113,7 +113,10 @@ contract DealStatusMock is IAggregatorOracle, ProofMock { // get the deal's expiration epoch MarketTypes.GetDealTermReturn memory dealTerm = MarketAPI.getDealTerm(dealId); - if (block.number < uint64(dealTerm.end) - epochs || block.number > uint64(dealTerm.end)) { + if ( + (block.number + epochs < uint64(dealTerm.start) + uint64(dealTerm.end)) || + (block.number > uint64(dealTerm.start) + uint64(dealTerm.end)) + ) { delete expiringDealIds[i]; } } From d4e46428ff99f8df93af4fb822587dd0ab515038 Mon Sep 17 00:00:00 2001 From: lordforever Date: Sat, 4 Nov 2023 01:55:11 +0530 Subject: [PATCH 5/6] Deal Status refactored --- contracts/DealStatus.sol | 205 +++++++++++++----- contracts/data-segment/Proof.sol | 10 +- contracts/mocks/DealStatusMock.sol | 4 +- contracts/mocks/MarketAPIMock.sol | 4 +- contracts/mocks/ProofMock.sol | 6 +- deploy/00_deploy.js | 11 +- package.json | 4 +- .../{get-deal-status => get-deal-status.js} | 0 tasks/deal-status/get-deal-info.js | 39 ++++ tasks/index.js | 3 +- 10 files changed, 220 insertions(+), 66 deletions(-) rename tasks/deal-client/{get-deal-status => get-deal-status.js} (100%) create mode 100644 tasks/deal-status/get-deal-info.js diff --git a/contracts/DealStatus.sol b/contracts/DealStatus.sol index ff4edac..3540489 100644 --- a/contracts/DealStatus.sol +++ b/contracts/DealStatus.sol @@ -5,54 +5,95 @@ pragma solidity ^0.8.17; // import "hardhat/console.sol"; import "./interfaces/IAggregatorOracle.sol"; -import "./data-segment/Proof.sol"; +import {Proof} from "./data-segment/Proof.sol"; +import {MarketTypes} from "@zondax/filecoin-solidity/contracts/v0.8/types/MarketTypes.sol"; +import {MarketAPI} from "@zondax/filecoin-solidity/contracts/v0.8/MarketAPI.sol"; +import {CommonTypes} from "@zondax/filecoin-solidity/contracts/v0.8/types/CommonTypes.sol"; // Delta that implements the AggregatorOracle interface contract DealStatus is IAggregatorOracle, Proof { - uint256 private transactionId; - mapping(uint256 => bytes) private txIdToCid; - mapping(bytes => Deal[]) private cidToDeals; + /////////////////// + // State Variables + /////////////////// + uint256 private s_transactionId; + mapping(uint256 => bytes) private s_txIdToCid; + mapping(bytes => Deal[]) private s_cidToDeals; + + /////////////////// + // Functions + /////////////////// + + //constructor constructor() { - transactionId = 0; + s_transactionId = 0; } - function computeExpectedAuxDataPublic( - InclusionProof memory _proof, - InclusionVerifierData memory _verifierData - ) public pure returns (InclusionAuxData memory) { - return computeExpectedAuxData(_proof, _verifierData); - } + // external functions + + /** + * @notice Submits a new transaction with the given content identifier. + * @dev Increments the transaction ID, saves the content identifier, and emits a SubmitAggregatorRequest event. + * @param _cid The content identifier for the new transaction. + * @return The ID of the newly created transaction. + */ function submit(bytes memory _cid) external returns (uint256) { // Increment the transaction ID - transactionId++; + s_transactionId++; // Save _cid - txIdToCid[transactionId] = _cid; + s_txIdToCid[s_transactionId] = _cid; // Emit the event - emit SubmitAggregatorRequest(transactionId, _cid); - return transactionId; + emit SubmitAggregatorRequest(s_transactionId, _cid); + return s_transactionId; } + /** + * @notice Submits a new transaction with the given content identifier and RaaS parameters. + * @dev Increments the transaction ID, saves the content identifier, and emits a SubmitAggregatorRequestWithRaaS event. + * @param _cid The content identifier for the new transaction. + * @param _replication_target The number of replications of data needed. + * @param _repair_threshold The threshold to repair the deal if miner faults. + * @param _renew_threshold The threshold to renew the deal. + * @return The ID of the newly created transaction. + */ + function submitRaaS( bytes memory _cid, - uint256 _replication_target, + uint256 _replication_target, uint256 _repair_threshold, - uint256 _renew_threshold + uint256 _renew_threshold ) external returns (uint256) { // Increment the transaction ID - transactionId++; + s_transactionId++; // Save _cid - txIdToCid[transactionId] = _cid; + s_txIdToCid[s_transactionId] = _cid; // Emit the event - emit SubmitAggregatorRequestWithRaaS(transactionId, _cid, _replication_target, _repair_threshold, _renew_threshold); - return transactionId; + emit SubmitAggregatorRequestWithRaaS( + s_transactionId, + _cid, + _replication_target, + _repair_threshold, + _renew_threshold + ); + return s_transactionId; } + /** + * @notice Completes a transaction with the given transaction ID, deal ID, miner ID, inclusion proof, and inclusion verifier data. + * @dev Emits a CompleteAggregatorRequest event. + * @param _id The ID of the transaction to complete. + * @param _dealId The ID of the deal to complete. + * @param _minerId The ID of the miner that completed the deal. + * @param _proof The inclusion proof for the transaction. + * @param _verifierData The inclusion verifier data for the transaction. + * @return The inclusion auxiliary data proof for the given file proof and verifier data. + */ + function complete( uint256 _id, uint64 _dealId, @@ -60,41 +101,36 @@ contract DealStatus is IAggregatorOracle, Proof { InclusionProof memory _proof, InclusionVerifierData memory _verifierData ) external returns (InclusionAuxData memory) { - require(_id <= transactionId, "Delta.complete: invalid tx id"); + require(_id <= s_transactionId, "Delta.complete: invalid tx id"); // Emit the event emit CompleteAggregatorRequest(_id, _dealId); // save the _dealId if it is not already saved - bytes memory cid = txIdToCid[_id]; - for (uint256 i = 0; i < cidToDeals[cid].length; i++) { - if (cidToDeals[cid][i].dealId == _dealId) { - return this.computeExpectedAuxDataPublic(_proof, _verifierData); + bytes memory cid = s_txIdToCid[_id]; + for (uint256 i = 0; i < s_cidToDeals[cid].length; i++) { + if (s_cidToDeals[cid][i].dealId == _dealId) { + return computeExpectedAuxData(_proof, _verifierData); } } Deal memory deal = Deal(_dealId, _minerId); - cidToDeals[cid].push(deal); + s_cidToDeals[cid].push(deal); // Perform validation logic // return this.computeExpectedAuxDataWithDeal(_dealId, _proof, _verifierData); - return this.computeExpectedAuxDataPublic(_proof, _verifierData); + return computeExpectedAuxData(_proof, _verifierData); } - // allDealIds should return all the deal ids created by the aggregator - function getAllDeals(bytes memory _cid) external view returns (Deal[] memory) { - return cidToDeals[_cid]; - } + // View functions - function getAllCIDs() external view returns (bytes[] memory) { - bytes[] memory cids = new bytes[](transactionId); - for (uint256 i = 0; i < transactionId; i++) { - cids[i] = txIdToCid[i + 1]; - } - return cids; - } + /** + * @notice Retrieves all active deals associated with a given content identifier. + * @dev Iterates through all deals associated with the content identifier, checks their activation and termination status, and removes any inactive deals from the returned array. + * @param _cid The content identifier for which to retrieve active deals. + * @return An array of Deal structs representing all active deals associated with the given content identifier. + */ - // getActiveDeals should return all the _cid's active dealIds - function getActiveDeals(bytes memory _cid) external returns (Deal[] memory) { + function getActiveDeals(bytes memory _cid) external view returns (Deal[] memory) { // get all the deal ids for the cid Deal[] memory activeDealIds; activeDealIds = this.getAllDeals(_cid); @@ -102,10 +138,9 @@ contract DealStatus is IAggregatorOracle, Proof { for (uint256 i = 0; i < activeDealIds.length; i++) { uint64 dealID = activeDealIds[i].dealId; // get the deal's expiration epoch - MarketTypes.GetDealActivationReturn memory dealActivationStatus = MarketAPI - .getDealActivation(dealID); + (int64 activated, int64 terminated) = this.getDealActivationData(dealID); - if (dealActivationStatus.terminated > 0 || dealActivationStatus.activated == -1) { + if (terminated > 0 || activated == -1) { delete activeDealIds[i]; } } @@ -113,8 +148,18 @@ contract DealStatus is IAggregatorOracle, Proof { return activeDealIds; } - // getExpiringDeals should return all the deals' dealIds if they are expiring within `epochs` - function getExpiringDeals(bytes memory _cid, uint64 epochs) external returns (Deal[] memory) { + /** + * @notice Retrieves all expiring deals associated with a given content identifier. + * @dev Iterates through all deals associated with the content identifier, checks their expiration status, and removes any non-expiring deals from the returned array. + * @param _cid The content identifier for which to retrieve expiring deals. + * @param epochs The number of epochs before a deal's expiration to consider it expiring. + * @return An array of Deal structs representing all expiring deals associated with the given content identifier. + */ + + function getExpiringDeals( + bytes memory _cid, + uint64 epochs + ) external view returns (Deal[] memory) { // the logic is similar to the above, but use this api call: // https://github.com/Zondax/filecoin-solidity/blob/master/contracts/v0.8/MarketAPI.sol#LL110C9-L110C9 Deal[] memory expiringDealIds; @@ -123,13 +168,75 @@ contract DealStatus is IAggregatorOracle, Proof { for (uint256 i = 0; i < expiringDealIds.length; i++) { uint64 dealId = expiringDealIds[i].dealId; // get the deal's expiration epoch - MarketTypes.GetDealTermReturn memory dealTerm = MarketAPI.getDealTerm(dealId); - - if (block.number < uint64(dealTerm.end) - epochs || block.number > uint64(dealTerm.end)) { + (, int64 endEpoch) = this.getDealTermData(dealId); + if (block.number < uint64(endEpoch) - epochs) { delete expiringDealIds[i]; } } return expiringDealIds; } + + //Getter Functions + + /** + * @notice Retrieves the activation and termination data for a given deal. + * @dev Calls the MarketAPI to get the deal's activation status and then unwraps the activation and termination epochs. + * @param _dealId The ID of the deal for which to retrieve activation data. + * @return dealActivation The activation epoch of the deal or -1. + * @return dealTermination The termination epoch of the deal or -1. + */ + + function getDealActivationData( + uint64 _dealId + ) public view returns (int64 dealActivation, int64 dealTermination) { + MarketTypes.GetDealActivationReturn memory dealActivationStatus = MarketAPI + .getDealActivation(_dealId); + return ( + CommonTypes.ChainEpoch.unwrap(dealActivationStatus.activated), + CommonTypes.ChainEpoch.unwrap(dealActivationStatus.terminated) + ); + } + + /** + * @notice Retrieves the start and end epochs for a given deal. + * @dev Calls the MarketAPI to get the deal's start and end epochs and then unwraps them. + * @param _dealId The ID of the deal for which to retrieve term data. + * @return startEpoch The start epoch of the deal. + * @return endEpoch The end epoch of the deal. + */ + function getDealTermData( + uint64 _dealId + ) public view returns (int64 startEpoch, int64 endEpoch) { + MarketTypes.GetDealTermReturn memory dealTerm = MarketAPI.getDealTerm(_dealId); + return ( + CommonTypes.ChainEpoch.unwrap(dealTerm.start), + CommonTypes.ChainEpoch.unwrap(dealTerm.end) + ); + } + + /** + * @notice Retrieves all deals associated with a given content identifier. + * @dev Returns the array of deals associated with the given content identifier. + * @param _cid The content identifier for which to retrieve deals. + * @return An array of Deal structs representing all deals associated with the given content identifier. + */ + + function getAllDeals(bytes memory _cid) external view returns (Deal[] memory) { + return s_cidToDeals[_cid]; + } + + /** + * @notice Retrieves all content identifiers associated with the contract. + * @dev Returns the array of content identifiers associated with the aggregator. + * @return An array of bytes representing all content identifiers associated with the aggregator. + */ + + function getAllCIDs() external view returns (bytes[] memory) { + bytes[] memory cids = new bytes[](s_transactionId); + for (uint256 i = 0; i < s_transactionId; i++) { + cids[i] = s_txIdToCid[i + 1]; + } + return cids; + } } diff --git a/contracts/data-segment/Proof.sol b/contracts/data-segment/Proof.sol index a53d171..26f3cec 100644 --- a/contracts/data-segment/Proof.sol +++ b/contracts/data-segment/Proof.sol @@ -9,7 +9,7 @@ import {Cid} from "./Cid.sol"; import {ProofData, InclusionProof, InclusionVerifierData, InclusionAuxData, SegmentDesc, Fr32} from "./ProofTypes.sol"; import {MarketAPI} from "@zondax/filecoin-solidity/contracts/v0.8/MarketAPI.sol"; import {MarketTypes} from "@zondax/filecoin-solidity/contracts/v0.8/types/MarketTypes.sol"; - +import {CommonTypes} from "@zondax/filecoin-solidity/contracts/v0.8/types/CommonTypes.sol"; contract Proof { using Cid for bytes; using Cid for bytes32; @@ -60,7 +60,7 @@ contract Proof { uint64 dealId, InclusionProof memory ip, InclusionVerifierData memory verifierData - ) internal returns (InclusionAuxData memory) { + ) internal view returns (InclusionAuxData memory) { InclusionAuxData memory inclusionAuxData = computeExpectedAuxData(ip, verifierData); validateInclusionAuxData(dealId, inclusionAuxData); return inclusionAuxData; @@ -70,13 +70,13 @@ contract Proof { function validateInclusionAuxData( uint64 dealId, InclusionAuxData memory inclusionAuxData - ) internal { + ) internal view { // check that the deal is not terminated MarketTypes.GetDealActivationReturn memory dealActivation = MarketAPI.getDealActivation( dealId ); - require(dealActivation.terminated <= 0, "Deal is terminated"); - require(dealActivation.activated > 0, "Deal is not activated"); + require(CommonTypes.ChainEpoch.unwrap(dealActivation.terminated) <= 0, "Deal is terminated"); + require(CommonTypes.ChainEpoch.unwrap(dealActivation.activated )> 0, "Deal is not activated"); MarketTypes.GetDealDataCommitmentReturn memory dealDataCommitment = MarketAPI .getDealDataCommitment(dealId); diff --git a/contracts/mocks/DealStatusMock.sol b/contracts/mocks/DealStatusMock.sol index 854de95..cab805f 100644 --- a/contracts/mocks/DealStatusMock.sol +++ b/contracts/mocks/DealStatusMock.sol @@ -93,7 +93,7 @@ contract DealStatusMock is IAggregatorOracle, ProofMock { // get the deal's expiration epoch MarketTypes.GetDealActivationReturn memory dealActivationStatus = MarketAPI.getDealActivation(dealID); - if (dealActivationStatus.terminated > 0 || dealActivationStatus.activated == -1) { + if (CommonTypes.ChainEpoch.unwrap(dealActivationStatus.terminated) > 0 || CommonTypes.ChainEpoch.unwrap(dealActivationStatus.activated) == -1) { delete activeDealIds[i]; } } @@ -113,7 +113,7 @@ contract DealStatusMock is IAggregatorOracle, ProofMock { // get the deal's expiration epoch MarketTypes.GetDealTermReturn memory dealTerm = MarketAPI.getDealTerm(dealId); - if (block.number < uint64(dealTerm.end) - epochs || block.number > uint64(dealTerm.end)) { + if (block.number < uint64(CommonTypes.ChainEpoch.unwrap(dealTerm.end)) - epochs || block.number > uint64(CommonTypes.ChainEpoch.unwrap(dealTerm.end))) { delete expiringDealIds[i]; } } diff --git a/contracts/mocks/MarketAPIMock.sol b/contracts/mocks/MarketAPIMock.sol index 92049c2..67cb5ff 100644 --- a/contracts/mocks/MarketAPIMock.sol +++ b/contracts/mocks/MarketAPIMock.sol @@ -70,7 +70,7 @@ library MarketAPI { /// @notice Get the start epoch and duration(in epochs) of a deal proposal. /// @return the start epoch and duration (in epochs) of a deal proposal. function getDealTerm(uint64 dealID) internal pure returns (MarketTypes.GetDealTermReturn memory) { - return MarketTypes.GetDealTermReturn({start: 0, end: 1000}); + return MarketTypes.GetDealTermReturn({start: CommonTypes.ChainEpoch.wrap(0), end: CommonTypes.ChainEpoch.wrap(1000)}); } /// @notice get the total price that will be paid from the client to the provider for this deal. @@ -94,7 +94,7 @@ library MarketAPI { /// @notice This will be available from when the proposal is published until an undefined period after the deal finishes (either normally or by termination). /// @return USR_NOT_FOUND if the deal doesn't exist (yet), or EX_DEAL_EXPIRED if the deal has been removed from state. function getDealActivation(uint64 dealID) internal pure returns (MarketTypes.GetDealActivationReturn memory) { - return MarketTypes.GetDealActivationReturn({activated: 0, terminated: -1}); + return MarketTypes.GetDealActivationReturn({activated: CommonTypes.ChainEpoch.wrap(0), terminated: CommonTypes.ChainEpoch.wrap(-1)}); } /// @notice Publish a new set of storage deals (not yet included in a sector). diff --git a/contracts/mocks/ProofMock.sol b/contracts/mocks/ProofMock.sol index 5779e93..2d21d26 100644 --- a/contracts/mocks/ProofMock.sol +++ b/contracts/mocks/ProofMock.sol @@ -16,7 +16,7 @@ import { } from "../data-segment/ProofTypes.sol"; import {MarketAPI} from "./MarketAPIMock.sol"; import {MarketTypes} from "@zondax/filecoin-solidity/contracts/v0.8/types/MarketTypes.sol"; - +import {CommonTypes} from "@zondax/filecoin-solidity/contracts/v0.8/types/CommonTypes.sol"; contract ProofMock { using Cid for bytes; using Cid for bytes32; @@ -67,8 +67,8 @@ contract ProofMock { function validateInclusionAuxData(uint64 dealId, InclusionAuxData memory inclusionAuxData) internal { // check that the deal is not terminated MarketTypes.GetDealActivationReturn memory dealActivation = MarketAPI.getDealActivation(dealId); - require(dealActivation.terminated <= 0, "Deal is terminated"); - require(dealActivation.activated > 0, "Deal is not activated"); + require(CommonTypes.ChainEpoch.unwrap(dealActivation.terminated) <= 0, "Deal is terminated"); + require(CommonTypes.ChainEpoch.unwrap(dealActivation.activated) > 0, "Deal is not activated"); MarketTypes.GetDealDataCommitmentReturn memory dealDataCommitment = MarketAPI.getDealDataCommitment(dealId); require(keccak256(dealDataCommitment.data) == keccak256(inclusionAuxData.commPa), "Deal commD doesn't match"); diff --git a/deploy/00_deploy.js b/deploy/00_deploy.js index f9302d5..9761630 100644 --- a/deploy/00_deploy.js +++ b/deploy/00_deploy.js @@ -9,15 +9,20 @@ const wallet = new ethers.Wallet(private_key, ethers.provider) module.exports = async ({ deployments }) => { // ethers is available in the global scope const [deployer] = await ethers.getSigners() - console.log("Deploying the contracts with the account:", await deployer.getAddress()) + console.log( + "Deploying the contracts with the account:", + await deployer.getAddress(), + "on network", + network.name + ) console.log("Account balance:", (await deployer.getBalance()).toString()) const accounts = await ethers.getSigners() - console.log(accounts[0]) + // console.log(accounts[0]) console.log("Wallet Ethereum Address:", wallet.address) - const chainId = network.config.chainId + // const chainId = network.config.chainId // //deploy DealStatus // const Cid = await ethers.getContractFactory('Cid', accounts[0]); diff --git a/package.json b/package.json index 9d5d4d7..6a8bb73 100644 --- a/package.json +++ b/package.json @@ -45,7 +45,8 @@ "@nomicfoundation/hardhat-network-helpers": "^1.0.0", "@nomicfoundation/hardhat-toolbox": "^2.0.0", "@nomiclabs/hardhat-ethers": "^2.2.3", - "@openzeppelin/contracts": "^4.8.3", + "@openzeppelin/contracts": "^5.0.0", + "@openzeppelin/contracts-upgradeable": "^5.0.0", "@typechain/hardhat": "^6.1.2", "@zondax/filecoin-solidity": "^2.0.0-beta.1", "babel-eslint": "^10.1.0", @@ -58,6 +59,7 @@ "html-webpack-plugin": "^5.5.3", "multer": "^1.4.5-lts.1", "sinon": "^15.2.0", + "solidity-cborutils": "^2.0.0", "ts-node": "^10.9.1", "typescript": "^4.9.4", "webpack-cli": "^5.1.4", diff --git a/tasks/deal-client/get-deal-status b/tasks/deal-client/get-deal-status.js similarity index 100% rename from tasks/deal-client/get-deal-status rename to tasks/deal-client/get-deal-status.js diff --git a/tasks/deal-status/get-deal-info.js b/tasks/deal-status/get-deal-info.js new file mode 100644 index 0000000..acc7546 --- /dev/null +++ b/tasks/deal-status/get-deal-info.js @@ -0,0 +1,39 @@ +task("get-deal-info", "Gets a deal's info from deal id") + .addParam("contract", "The address of the DealRewarder contract") + .addParam("dealId", "The deal id of the deal you want the info of") + .setAction(async (taskArgs) => { + const contractAddr = taskArgs.contract + const networkId = network.name + const dealId = taskArgs.dealId + console.log("Running dealStatus on network", networkId) + + //create a new wallet instance + const wallet = new ethers.Wallet(network.config.accounts[0], ethers.provider) + + const DealStatus = await ethers.getContractFactory("DealStatus", wallet) + + const dealStatus = await DealStatus.attach(contractAddr) + + const dealActivationReturn = await dealStatus.getDealActivationData(dealId) + console.log("Deal Activation return data is: ", dealActivationReturn) + console.log("Which gets parsed to:") + printBigIntChainOutput(dealActivationReturn) + const dealTermReturn = await dealStatus.getDealTermData(dealId) + console.log("Deal Term return data is: ", dealTermReturn) + console.log("Which gets parsed to:") + printBigIntChainOutput(dealTermReturn) + + console.log("Complete!") + + // Converts the BigInt return data from a view function to a readable format + function printBigIntChainOutput(output) { + for (let i = 0; i < output.length; i++) { + console.log( + Object.keys(output)[i + output.length], + ":", + Number(Object.values(output)[i]._hex) + ) + } + } + }) +//sample contract 0xc3B1D57038BD4a2263e56c3bE8689d4B3Cc7C786 diff --git a/tasks/index.js b/tasks/index.js index b28bbe7..f0e41dd 100644 --- a/tasks/index.js +++ b/tasks/index.js @@ -9,4 +9,5 @@ exports.fund = require("./deal-rewarder/fund") exports.claimBounty = require("./deal-rewarder/claim-bounty") exports.makeDealProposal = require("./deal-client/make-deal-proposal") exports.getDealProposal = require("./deal-client/get-deal-proposal") -exports.getDealStatus = require("./deal-client/get-deal-status") \ No newline at end of file +exports.getDealStatus = require("./deal-client/get-deal-status") +exports.getDealInfo = require("./deal-status/get-deal-info") From 6e61531db029f42c6ac7182981fc920aa41c6229 Mon Sep 17 00:00:00 2001 From: lordforever Date: Sat, 4 Nov 2023 12:50:27 +0530 Subject: [PATCH 6/6] function name reinstated --- contracts/DealStatus.sol | 42 ++++++++++++++++++++-------------------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/contracts/DealStatus.sol b/contracts/DealStatus.sol index 3540489..06ded77 100644 --- a/contracts/DealStatus.sol +++ b/contracts/DealStatus.sol @@ -16,9 +16,9 @@ contract DealStatus is IAggregatorOracle, Proof { // State Variables /////////////////// - uint256 private s_transactionId; - mapping(uint256 => bytes) private s_txIdToCid; - mapping(bytes => Deal[]) private s_cidToDeals; + uint256 private transactionId; + mapping(uint256 => bytes) private txIdToCid; + mapping(bytes => Deal[]) private cidToDeals; /////////////////// // Functions @@ -26,7 +26,7 @@ contract DealStatus is IAggregatorOracle, Proof { //constructor constructor() { - s_transactionId = 0; + transactionId = 0; } // external functions @@ -40,14 +40,14 @@ contract DealStatus is IAggregatorOracle, Proof { function submit(bytes memory _cid) external returns (uint256) { // Increment the transaction ID - s_transactionId++; + transactionId++; // Save _cid - s_txIdToCid[s_transactionId] = _cid; + txIdToCid[transactionId] = _cid; // Emit the event - emit SubmitAggregatorRequest(s_transactionId, _cid); - return s_transactionId; + emit SubmitAggregatorRequest(transactionId, _cid); + return transactionId; } /** @@ -67,20 +67,20 @@ contract DealStatus is IAggregatorOracle, Proof { uint256 _renew_threshold ) external returns (uint256) { // Increment the transaction ID - s_transactionId++; + transactionId++; // Save _cid - s_txIdToCid[s_transactionId] = _cid; + txIdToCid[transactionId] = _cid; // Emit the event emit SubmitAggregatorRequestWithRaaS( - s_transactionId, + transactionId, _cid, _replication_target, _repair_threshold, _renew_threshold ); - return s_transactionId; + return transactionId; } /** @@ -101,20 +101,20 @@ contract DealStatus is IAggregatorOracle, Proof { InclusionProof memory _proof, InclusionVerifierData memory _verifierData ) external returns (InclusionAuxData memory) { - require(_id <= s_transactionId, "Delta.complete: invalid tx id"); + require(_id <= transactionId, "Delta.complete: invalid tx id"); // Emit the event emit CompleteAggregatorRequest(_id, _dealId); // save the _dealId if it is not already saved - bytes memory cid = s_txIdToCid[_id]; - for (uint256 i = 0; i < s_cidToDeals[cid].length; i++) { - if (s_cidToDeals[cid][i].dealId == _dealId) { + bytes memory cid = txIdToCid[_id]; + for (uint256 i = 0; i < cidToDeals[cid].length; i++) { + if (cidToDeals[cid][i].dealId == _dealId) { return computeExpectedAuxData(_proof, _verifierData); } } Deal memory deal = Deal(_dealId, _minerId); - s_cidToDeals[cid].push(deal); + cidToDeals[cid].push(deal); // Perform validation logic // return this.computeExpectedAuxDataWithDeal(_dealId, _proof, _verifierData); @@ -223,7 +223,7 @@ contract DealStatus is IAggregatorOracle, Proof { */ function getAllDeals(bytes memory _cid) external view returns (Deal[] memory) { - return s_cidToDeals[_cid]; + return cidToDeals[_cid]; } /** @@ -233,9 +233,9 @@ contract DealStatus is IAggregatorOracle, Proof { */ function getAllCIDs() external view returns (bytes[] memory) { - bytes[] memory cids = new bytes[](s_transactionId); - for (uint256 i = 0; i < s_transactionId; i++) { - cids[i] = s_txIdToCid[i + 1]; + bytes[] memory cids = new bytes[](transactionId); + for (uint256 i = 0; i < transactionId; i++) { + cids[i] = txIdToCid[i + 1]; } return cids; }