@@ -6,14 +6,12 @@ import {Cid} from "./Cid.sol";
66import {TRUNCATOR} from "./Const.sol " ;
77import {DataAttestation} from "./Oracles.sol " ;
88
9-
109// Adapted from https://github.com/lighthouse-web3/raas-starter-kit/blob/main/contracts/data-segment/Proof.sol
1110// adapted rather than imported to
1211// 1) avoid build issues
13- // 2) avoid npm deps
12+ // 2) avoid npm deps
1413//3) avoid use of deprecated @zondax/filecoin-solidity
1514contract PODSIVerifier {
16-
1715 // ProofData is a Merkle proof
1816 struct ProofData {
1917 uint64 index;
@@ -30,9 +28,18 @@ contract PODSIVerifier {
3028 }
3129
3230 // computeRoot computes the root of a Merkle tree given a leaf and a Merkle proof.
33- function computeRoot (ProofData memory d , bytes32 subtree ) internal pure returns (bytes32 ) {
34- require (d.path.length < 64 , "merkleproofs with depths greater than 63 are not supported " );
35- require (d.index >> d.path.length == 0 , "index greater than width of the tree " );
31+ function computeRoot (
32+ ProofData memory d ,
33+ bytes32 subtree
34+ ) internal pure returns (bytes32 ) {
35+ require (
36+ d.path.length < 64 ,
37+ "merkleproofs with depths greater than 63 are not supported "
38+ );
39+ require (
40+ d.index >> d.path.length == 0 ,
41+ "index greater than width of the tree "
42+ );
3643
3744 bytes32 carry = subtree;
3845 uint64 index = d.index;
@@ -51,7 +58,10 @@ contract PODSIVerifier {
5158 }
5259
5360 // computeNode computes the parent node of two child nodes
54- function computeNode (bytes32 left , bytes32 right ) internal pure returns (bytes32 ) {
61+ function computeNode (
62+ bytes32 left ,
63+ bytes32 right
64+ ) internal pure returns (bytes32 ) {
5565 bytes32 digest = sha256 (abi.encodePacked (left, right));
5666 return truncate (digest);
5767 }
@@ -63,17 +73,16 @@ contract PODSIVerifier {
6373 }
6474}
6575
66-
6776contract OnRampContract is PODSIVerifier {
68- struct Offer {
77+ struct Offer {
6978 bytes commP;
7079 uint64 size;
7180 string location;
7281 uint256 amount;
7382 IERC20 token;
7483 }
7584 // Possible rearrangement:
76- // struct Hint {string location, uint64 size} ?
85+ // struct Hint {string location, uint64 size} ?
7786 // struct Payment {uint256 amount, IERC20 token}?
7887
7988 event DataReady (Offer offer , uint64 id );
@@ -86,7 +95,6 @@ contract OnRampContract is PODSIVerifier {
8695 mapping (uint64 => bool ) public provenAggregations;
8796 mapping (bytes => uint64 ) public commPToAggregateID;
8897
89-
9098 function setOracle (address oracle_ ) external {
9199 if (dataProofOracle == address (0 )) {
92100 dataProofOracle = oracle_;
@@ -96,7 +104,10 @@ contract OnRampContract is PODSIVerifier {
96104 }
97105
98106 function offerData (Offer calldata offer ) external payable returns (uint64 ) {
99- require (offer.token.transferFrom (msg .sender , address (this ), offer.amount), "Payment transfer failed " );
107+ require (
108+ offer.token.transferFrom (msg .sender , address (this ), offer.amount),
109+ "Payment transfer failed "
110+ );
100111
101112 uint64 id = nextOfferId++ ;
102113 offers[id] = offer;
@@ -105,39 +116,66 @@ contract OnRampContract is PODSIVerifier {
105116 return id;
106117 }
107118
108- function commitAggregate (bytes calldata aggregate , uint64 [] calldata claimedIDs , ProofData[] calldata inclusionProofs , address payoutAddr ) external {
119+ function commitAggregate (
120+ bytes calldata aggregate ,
121+ uint64 [] calldata claimedIDs ,
122+ ProofData[] calldata inclusionProofs ,
123+ address payoutAddr
124+ ) external {
109125 uint64 [] memory offerIDs = new uint64 [](claimedIDs.length );
110126 uint64 aggId = nextAggregateID++ ;
111- // Prove all offers are committed by aggregate commP
127+ // Prove all offers are committed by aggregate commP
112128 for (uint64 i = 0 ; i < claimedIDs.length ; i++ ) {
113129 uint64 offerID = claimedIDs[i];
114130 offerIDs[i] = offerID;
115- require (verify (inclusionProofs[i], Cid.cidToPieceCommitment (aggregate), Cid.cidToPieceCommitment (offers[offerID].commP)), "Proof verification failed " );
131+ require (
132+ verify (
133+ inclusionProofs[i],
134+ Cid.cidToPieceCommitment (aggregate),
135+ Cid.cidToPieceCommitment (offers[offerID].commP)
136+ ),
137+ "Proof verification failed "
138+ );
116139 }
117140 aggregations[aggId] = offerIDs;
118141 aggregationPayout[aggId] = payoutAddr;
119142 commPToAggregateID[aggregate] = aggId;
120143 }
121144
122- function verifyDataStored (uint64 aggID , uint idx , uint64 offerID ) external view returns (bool ) {
145+ function verifyDataStored (
146+ uint64 aggID ,
147+ uint idx ,
148+ uint64 offerID
149+ ) external view returns (bool ) {
123150 require (provenAggregations[aggID], "Provided aggregation not proven " );
124- require (aggregations[aggID][idx] == offerID, "Aggregation does not include offer " );
151+ require (
152+ aggregations[aggID][idx] == offerID,
153+ "Aggregation does not include offer "
154+ );
125155
126156 return true ;
127157 }
128158
129159 // Called by oracle to prove the data is stored
130- function proveDataStored ( DataAttestation calldata attestation ) external {
131- require (msg .sender == dataProofOracle, "Only oracle can prove data stored " );
160+ function proveDataStored (DataAttestation calldata attestation ) external {
161+ require (
162+ msg .sender == dataProofOracle,
163+ "Only oracle can prove data stored "
164+ );
132165 uint64 aggID = commPToAggregateID[attestation.commP];
133166 require (aggID != 0 , "Aggregate not found " );
134167
135168 // transfer payment to the receiver
136169 for (uint i = 0 ; i < aggregations[aggID].length ; i++ ) {
137170 uint64 offerID = aggregations[aggID][i];
138- require (offers[offerID].token.transfer (aggregationPayout[aggID], offers[offerID].amount), "Payment transfer failed " );
139- }
171+ require (
172+ offers[offerID].token.transfer (
173+ aggregationPayout[aggID],
174+ offers[offerID].amount
175+ ),
176+ "Payment transfer failed "
177+ );
178+ }
140179 provenAggregations[aggID] = true ;
141180 }
142181}
143-
0 commit comments