@@ -148,20 +148,21 @@ contract ProofMarketTest is Test {
148
148
);
149
149
}
150
150
151
- function fulfillRequest (ProvingRequest memory request , bytes memory journal )
151
+ function fulfillRequest (ProvingRequest memory request , bytes memory journal , address prover )
152
152
internal
153
153
returns (Fulfillment memory , bytes memory assessorSeal )
154
154
{
155
155
ProvingRequest[] memory requests = new ProvingRequest [](1 );
156
156
requests[0 ] = request;
157
157
bytes [] memory journals = new bytes [](1 );
158
158
journals[0 ] = journal;
159
- (Fulfillment[] memory fills , bytes memory seal ) = fulfillRequestBatch (requests, journals);
159
+ (Fulfillment[] memory fills , bytes memory seal ) = fulfillRequestBatch (requests, journals, prover );
160
160
return (fills[0 ], seal);
161
161
}
162
162
163
- function createFills (ProvingRequest[] memory requests , bytes [] memory journals )
163
+ function createFills (ProvingRequest[] memory requests , bytes [] memory journals , address prover )
164
164
internal
165
+ view
165
166
returns (Fulfillment[] memory fills , bytes memory assessorSeal , bytes32 root )
166
167
{
167
168
// initialize the fullfillments; one for each request;
@@ -179,7 +180,7 @@ contract ProofMarketTest is Test {
179
180
180
181
// compute the assessor claim
181
182
ReceiptClaim memory assessorClaim =
182
- TestUtils.mockAssessor (fills, ASSESSOR_IMAGE_ID, proofMarket.eip712DomainSeparator ());
183
+ TestUtils.mockAssessor (fills, ASSESSOR_IMAGE_ID, proofMarket.eip712DomainSeparator (), prover );
183
184
// compute the batchRoot of the batch Merkle Tree (without the assessor)
184
185
(bytes32 batchRoot , bytes32 [][] memory tree ) = TestUtils.mockSetBuilder (fills);
185
186
@@ -193,12 +194,12 @@ contract ProofMarketTest is Test {
193
194
return (fills, assessorSeal, root);
194
195
}
195
196
196
- function fulfillRequestBatch (ProvingRequest[] memory requests , bytes [] memory journals )
197
+ function fulfillRequestBatch (ProvingRequest[] memory requests , bytes [] memory journals , address prover )
197
198
internal
198
199
returns (Fulfillment[] memory fills , bytes memory assessorSeal )
199
200
{
200
201
bytes32 root;
201
- (fills, assessorSeal, root) = createFills (requests, journals);
202
+ (fills, assessorSeal, root) = createFills (requests, journals, prover );
202
203
// submit the root to the set verifier
203
204
publishRoot (root);
204
205
return (fills, assessorSeal);
@@ -428,8 +429,8 @@ contract ProofMarketTest is Test {
428
429
429
430
vm.startPrank (PROVER_WALLET.addr);
430
431
proofMarket.lockin (request, clientSignature);
431
- (Fulfillment memory fill , bytes memory assessorSeal ) = fulfillRequest (request, APP_JOURNAL);
432
- proofMarket.fulfill (fill, assessorSeal);
432
+ (Fulfillment memory fill , bytes memory assessorSeal ) = fulfillRequest (request, APP_JOURNAL, PROVER_WALLET.addr );
433
+ proofMarket.fulfill (fill, assessorSeal, PROVER_WALLET.addr );
433
434
// console2.log("fulfill - Gas used:", vm.gasUsed());
434
435
vm.stopPrank ();
435
436
@@ -473,8 +474,8 @@ contract ProofMarketTest is Test {
473
474
474
475
// Note that this does not come from any particular address.
475
476
proofMarket.lockinWithSig (request, clientSignature, proverSignature);
476
- (Fulfillment memory fill , bytes memory assessorSeal ) = fulfillRequest (request, APP_JOURNAL);
477
- proofMarket.fulfill (fill, assessorSeal);
477
+ (Fulfillment memory fill , bytes memory assessorSeal ) = fulfillRequest (request, APP_JOURNAL, PROVER_WALLET.addr );
478
+ proofMarket.fulfill (fill, assessorSeal, PROVER_WALLET.addr );
478
479
479
480
// Check that the proof was submitted
480
481
assertTrue (proofMarket.requestIsFulfilled (fill.id), "Request should have fulfilled status " );
@@ -523,9 +524,9 @@ contract ProofMarketTest is Test {
523
524
}
524
525
}
525
526
526
- (Fulfillment[] memory fills , bytes memory assessorSeal ) = fulfillRequestBatch (requests, journals);
527
-
528
- proofMarket.fulfillBatch (fills, assessorSeal);
527
+ (Fulfillment[] memory fills , bytes memory assessorSeal ) =
528
+ fulfillRequestBatch (requests, journals, PROVER_WALLET.addr);
529
+ proofMarket.fulfillBatch (fills, assessorSeal, PROVER_WALLET.addr );
529
530
530
531
for (uint256 i = 0 ; i < fills.length ; i++ ) {
531
532
// Check that the proof was submitted
@@ -539,18 +540,68 @@ contract ProofMarketTest is Test {
539
540
checkProofMarketBalance ();
540
541
}
541
542
543
+ // Test that when the prover that produces the assessor receipt and the one that locked the
544
+ // request are different, the one that locked the request gets paid.
545
+ function testFulfillDistinctProvers () public {
546
+ Vm.Wallet memory client = createClient (1 );
547
+
548
+ ProvingRequest memory request = defaultRequest (client.addr, 3 );
549
+
550
+ bytes memory clientSignature = signRequest (client, request);
551
+ bytes memory proverSignature = signRequest (PROVER_WALLET, request);
552
+
553
+ uint256 balanceBefore = proofMarket.balanceOf (PROVER_WALLET.addr);
554
+ console2.log ("Prover balance before: " , balanceBefore);
555
+
556
+ // Note that this does not come from any particular address.
557
+ proofMarket.lockinWithSig (request, clientSignature, proverSignature);
558
+ // address(3) is just a standin for some other address.
559
+ address mockOtherProverAddr = address (uint160 (3 ));
560
+ (Fulfillment memory fill , bytes memory assessorSeal ) = fulfillRequest (request, APP_JOURNAL, mockOtherProverAddr);
561
+ proofMarket.fulfill (fill, assessorSeal, mockOtherProverAddr);
562
+
563
+ // Check that the proof was submitted
564
+ assertTrue (proofMarket.requestIsFulfilled (fill.id), "Request should have fulfilled status " );
565
+
566
+ uint256 balanceAfter = proofMarket.balanceOf (PROVER_WALLET.addr);
567
+ console2.log ("Prover balance after: " , balanceAfter);
568
+ assertEq (balanceBefore + 1 ether, balanceAfter);
569
+
570
+ checkProofMarketBalance ();
571
+ }
572
+
573
+ function testFulfillFulfillProverAddrDoesNotMatchAssessorReceipt () public {
574
+ Vm.Wallet memory client = createClient (1 );
575
+
576
+ ProvingRequest memory request = defaultRequest (client.addr, 3 );
577
+
578
+ bytes memory clientSignature = signRequest (client, request);
579
+ bytes memory proverSignature = signRequest (PROVER_WALLET, request);
580
+
581
+ uint256 balanceBefore = proofMarket.balanceOf (PROVER_WALLET.addr);
582
+ console2.log ("Prover balance before: " , balanceBefore);
583
+
584
+ // Note that this does not come from any particular address.
585
+ proofMarket.lockinWithSig (request, clientSignature, proverSignature);
586
+ // address(3) is just a standin for some other address.
587
+ address mockOtherProverAddr = address (uint160 (3 ));
588
+ (Fulfillment memory fill , bytes memory assessorSeal ) = fulfillRequest (request, APP_JOURNAL, PROVER_WALLET.addr);
589
+
590
+ vm.expectRevert ();
591
+ proofMarket.fulfill (fill, assessorSeal, mockOtherProverAddr);
592
+ }
593
+
542
594
function testFulfillAlreadyFulfilled () public {
543
595
// Submit request and fulfill it
544
596
Vm.Wallet memory client = createClient (1 );
545
597
ProvingRequest memory request = defaultRequest (client.addr, 1 );
546
598
testFulfill ();
547
599
548
- (Fulfillment memory fill , bytes memory assessorSeal ) = fulfillRequest (request, APP_JOURNAL);
600
+ (Fulfillment memory fill , bytes memory assessorSeal ) = fulfillRequest (request, APP_JOURNAL, PROVER_WALLET.addr );
549
601
// Attempt to fulfill a request already fulfilled
550
602
// should revert with "RequestIsFulfilled({requestId: request.id})"
551
603
vm.expectRevert (abi.encodeWithSelector (IProofMarket.RequestIsFulfilled.selector , request.id));
552
- vm.prank (PROVER_WALLET.addr);
553
- proofMarket.fulfill (fill, assessorSeal);
604
+ proofMarket.fulfill (fill, assessorSeal, PROVER_WALLET.addr);
554
605
555
606
checkProofMarketBalance ();
556
607
}
@@ -559,13 +610,12 @@ contract ProofMarketTest is Test {
559
610
// Attempt to prove a non-existent request
560
611
Vm.Wallet memory client = createClient (1 );
561
612
ProvingRequest memory request = defaultRequest (client.addr, 1 );
562
- (Fulfillment memory fill , bytes memory assessorSeal ) = fulfillRequest (request, APP_JOURNAL);
613
+ (Fulfillment memory fill , bytes memory assessorSeal ) = fulfillRequest (request, APP_JOURNAL, PROVER_WALLET.addr );
563
614
564
615
// Attempt to fulfill a request not lockeed
565
616
// should revert with "RequestIsNotLocked({requestId: request.id})"
566
617
vm.expectRevert (abi.encodeWithSelector (IProofMarket.RequestIsNotLocked.selector , request.id));
567
- vm.prank (PROVER_WALLET.addr);
568
- proofMarket.fulfill (fill, assessorSeal);
618
+ proofMarket.fulfill (fill, assessorSeal, PROVER_WALLET.addr);
569
619
570
620
checkProofMarketBalance ();
571
621
}
@@ -585,7 +635,7 @@ contract ProofMarketTest is Test {
585
635
586
636
vm.startPrank (PROVER_WALLET.addr);
587
637
proofMarket.lockin (request, clientSignature);
588
- (Fulfillment memory fill , bytes memory assessorSeal ) = fulfillRequest (request, APP_JOURNAL);
638
+ (Fulfillment memory fill , bytes memory assessorSeal ) = fulfillRequest (request, APP_JOURNAL, PROVER_WALLET.addr );
589
639
590
640
vm.roll (2 );
591
641
@@ -594,7 +644,7 @@ contract ProofMarketTest is Test {
594
644
vm.expectRevert (
595
645
abi.encodeWithSelector (IProofMarket.RequestIsExpired.selector , request.id, request.offer.deadline ())
596
646
);
597
- proofMarket.fulfill (fill, assessorSeal);
647
+ proofMarket.fulfill (fill, assessorSeal, PROVER_WALLET.addr );
598
648
vm.stopPrank ();
599
649
600
650
checkProofMarketBalance ();
@@ -709,10 +759,11 @@ contract ProofMarketTest is Test {
709
759
710
760
function benchFulfillBatch (uint256 batchSize ) public {
711
761
(ProvingRequest[] memory requests , bytes [] memory journals ) = newBatch (batchSize);
712
- (Fulfillment[] memory fills , bytes memory assessorSeal ) = fulfillRequestBatch (requests, journals);
762
+ (Fulfillment[] memory fills , bytes memory assessorSeal ) =
763
+ fulfillRequestBatch (requests, journals, PROVER_WALLET.addr);
713
764
714
765
uint256 gasBefore = gasleft ();
715
- proofMarket.fulfillBatch (fills, assessorSeal);
766
+ proofMarket.fulfillBatch (fills, assessorSeal, PROVER_WALLET.addr );
716
767
uint256 gasAfter = gasleft ();
717
768
// Calculate the gas used
718
769
uint256 gasUsed = gasBefore - gasAfter;
@@ -761,11 +812,12 @@ contract ProofMarketTest is Test {
761
812
762
813
function testsubmitRootAndFulfillBatch () public {
763
814
(ProvingRequest[] memory requests , bytes [] memory journals ) = newBatch (2 );
764
- (Fulfillment[] memory fills , bytes memory assessorSeal , bytes32 root ) = createFills (requests, journals);
815
+ (Fulfillment[] memory fills , bytes memory assessorSeal , bytes32 root ) =
816
+ createFills (requests, journals, PROVER_WALLET.addr);
765
817
766
818
bytes memory seal =
767
819
verifier.mockProve (SET_BUILDER_IMAGE_ID, sha256 (abi.encodePacked (SET_BUILDER_IMAGE_ID, root))).seal;
768
- proofMarket.submitRootAndFulfillBatch (root, seal, fills, assessorSeal);
820
+ proofMarket.submitRootAndFulfillBatch (root, seal, fills, assessorSeal, PROVER_WALLET.addr );
769
821
770
822
for (uint256 j = 0 ; j < fills.length ; j++ ) {
771
823
assertTrue (proofMarket.requestIsFulfilled (fills[j].id), "Request should have fulfilled status " );
0 commit comments