Skip to content

Commit 24c965c

Browse files
committed
Revised event spec
1 parent 449b4c2 commit 24c965c

File tree

4 files changed

+259
-6
lines changed

4 files changed

+259
-6
lines changed

target_chains/ethereum/contracts/contracts/entropy/Entropy.sol

Lines changed: 56 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,8 @@ abstract contract Entropy is IEntropy, EntropyState {
150150

151151
provider.sequenceNumber += 1;
152152

153-
emit Registered(EntropyStructConverter.toV1ProviderInfo(provider));
153+
emit EntropyEvents.Registered(EntropyStructConverter.toV1ProviderInfo(provider));
154+
emit EntropyEventsV2.Registered(msg.sender, bytes(""));
154155
}
155156

156157
// Withdraw a portion of the accumulated fees for the provider msg.sender.
@@ -172,7 +173,8 @@ abstract contract Entropy is IEntropy, EntropyState {
172173
(bool sent, ) = msg.sender.call{value: amount}("");
173174
require(sent, "withdrawal to msg.sender failed");
174175

175-
emit Withdrawal(msg.sender, msg.sender, amount);
176+
emit EntropyEvents.Withdrawal(msg.sender, msg.sender, amount);
177+
emit EntropyEventsV2.Withdrawal(msg.sender, msg.sender, amount, bytes(""));
176178
}
177179

178180
function withdrawAsFeeManager(
@@ -202,7 +204,8 @@ abstract contract Entropy is IEntropy, EntropyState {
202204
(bool sent, ) = msg.sender.call{value: amount}("");
203205
require(sent, "withdrawal to msg.sender failed");
204206

205-
emit Withdrawal(provider, msg.sender, amount);
207+
emit EntropyEvents.Withdrawal(provider, msg.sender, amount);
208+
emit EntropyEventsV2.Withdrawal(provider, msg.sender, amount, bytes(""));
206209
}
207210

208211
// requestHelper allocates and returns a new request for the given provider.
@@ -349,6 +352,13 @@ abstract contract Entropy is IEntropy, EntropyState {
349352
userRandomNumber,
350353
EntropyStructConverter.toV1Request(req)
351354
);
355+
emit EntropyEventsV2.Requested(
356+
provider,
357+
req.requester,
358+
req.sequenceNumber,
359+
userRandomNumber,
360+
bytes("")
361+
);
352362
return req.sequenceNumber;
353363
}
354364

@@ -570,6 +580,15 @@ abstract contract Entropy is IEntropy, EntropyState {
570580
providerRevelation,
571581
randomNumber
572582
);
583+
emit EntropyEventsV2.Revealed(
584+
provider,
585+
req.requester,
586+
req.sequenceNumber,
587+
randomNumber,
588+
false,
589+
bytes(""),
590+
bytes("")
591+
);
573592
clearRequest(provider, sequenceNumber);
574593
} else if (
575594
ret.length > 0 ||
@@ -590,6 +609,15 @@ abstract contract Entropy is IEntropy, EntropyState {
590609
randomNumber,
591610
ret
592611
);
612+
emit EntropyEventsV2.Revealed(
613+
provider,
614+
req.requester,
615+
sequenceNumber,
616+
randomNumber,
617+
true,
618+
ret,
619+
bytes("")
620+
);
593621
req.callbackStatus = EntropyStatusConstants.CALLBACK_FAILED;
594622
} else {
595623
// Callback reverted by (potentially) running out of gas, but the calling context did not have enough gas
@@ -608,6 +636,15 @@ abstract contract Entropy is IEntropy, EntropyState {
608636
providerRevelation,
609637
randomNumber
610638
);
639+
emit EntropyEventsV2.Revealed(
640+
provider,
641+
req.requester,
642+
req.sequenceNumber,
643+
randomNumber,
644+
false,
645+
bytes(""),
646+
bytes("")
647+
);
611648

612649
clearRequest(provider, sequenceNumber);
613650

@@ -732,6 +769,7 @@ abstract contract Entropy is IEntropy, EntropyState {
732769
uint128 oldFeeInWei = provider.feeInWei;
733770
provider.feeInWei = newFeeInWei;
734771
emit ProviderFeeUpdated(msg.sender, oldFeeInWei, newFeeInWei);
772+
emit EntropyEventsV2.ProviderFeeUpdated(msg.sender, oldFeeInWei, newFeeInWei, bytes(""));
735773
}
736774

737775
function setProviderFeeAsFeeManager(
@@ -754,6 +792,7 @@ abstract contract Entropy is IEntropy, EntropyState {
754792
providerInfo.feeInWei = newFeeInWei;
755793

756794
emit ProviderFeeUpdated(provider, oldFeeInWei, newFeeInWei);
795+
emit EntropyEventsV2.ProviderFeeUpdated(provider, oldFeeInWei, newFeeInWei, bytes(""));
757796
}
758797

759798
// Set provider uri. It will revert if provider is not registered.
@@ -767,6 +806,7 @@ abstract contract Entropy is IEntropy, EntropyState {
767806
bytes memory oldUri = provider.uri;
768807
provider.uri = newUri;
769808
emit ProviderUriUpdated(msg.sender, oldUri, newUri);
809+
emit EntropyEventsV2.ProviderUriUpdated(msg.sender, oldUri, newUri, bytes(""));
770810
}
771811

772812
function setFeeManager(address manager) external override {
@@ -780,6 +820,7 @@ abstract contract Entropy is IEntropy, EntropyState {
780820
address oldFeeManager = provider.feeManager;
781821
provider.feeManager = manager;
782822
emit ProviderFeeManagerUpdated(msg.sender, oldFeeManager, manager);
823+
emit EntropyEventsV2.ProviderFeeManagerUpdated(msg.sender, oldFeeManager, manager, bytes(""));
783824
}
784825

785826
// Set the maximum number of hashes to record in a request. This should be set according to the maximum gas limit
@@ -799,6 +840,12 @@ abstract contract Entropy is IEntropy, EntropyState {
799840
oldMaxNumHashes,
800841
maxNumHashes
801842
);
843+
emit EntropyEventsV2.ProviderMaxNumHashesAdvanced(
844+
msg.sender,
845+
oldMaxNumHashes,
846+
maxNumHashes,
847+
bytes("")
848+
);
802849
}
803850

804851
// Set the default gas limit for a request.
@@ -817,6 +864,12 @@ abstract contract Entropy is IEntropy, EntropyState {
817864
uint32 oldGasLimit = provider.defaultGasLimit;
818865
provider.defaultGasLimit = gasLimit;
819866
emit ProviderDefaultGasLimitUpdated(msg.sender, oldGasLimit, gasLimit);
867+
emit EntropyEventsV2.ProviderDefaultGasLimitUpdated(
868+
msg.sender,
869+
oldGasLimit,
870+
gasLimit,
871+
bytes("")
872+
);
820873
}
821874

822875
function constructUserCommitment(

target_chains/ethereum/contracts/forge-test/Entropy.t.sol

Lines changed: 144 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,11 @@ import "@openzeppelin/contracts/proxy/ERC1967/ERC1967Proxy.sol";
1212
import "./utils/EntropyTestUtils.t.sol";
1313
import "../contracts/entropy/EntropyUpgradable.sol";
1414
import "@pythnetwork/entropy-sdk-solidity/EntropyStatusConstants.sol";
15+
import "@pythnetwork/entropy-sdk-solidity/EntropyEventsV2.sol";
1516

1617
// TODO
1718
// - fuzz test?
18-
contract EntropyTest is Test, EntropyTestUtils, EntropyEvents {
19+
contract EntropyTest is Test, EntropyTestUtils, EntropyEvents, EntropyEventsV2 {
1920
ERC1967Proxy public proxy;
2021
EntropyUpgradable public random;
2122

@@ -742,7 +743,7 @@ contract EntropyTest is Test, EntropyTestUtils, EntropyEvents {
742743
random.withdraw(providerOneBalance);
743744
}
744745

745-
function testgetProviderInfoV2() public {
746+
function testGetProviderInfoV2() public {
746747
EntropyStructsV2.ProviderInfo memory providerInfo1 = random
747748
.getProviderInfoV2(provider1);
748749
// These two fields aren't used by the Entropy contract itself -- they're just convenient info to store
@@ -818,6 +819,14 @@ contract EntropyTest is Test, EntropyTestUtils, EntropyEvents {
818819
isRequestWithCallback: true
819820
})
820821
);
822+
vm.expectEmit(false, false, false, true, address(random));
823+
emit EntropyEventsV2.Requested(
824+
provider1,
825+
user1,
826+
providerInfo.sequenceNumber,
827+
userRandomNumber,
828+
bytes("")
829+
);
821830
vm.roll(1234);
822831
uint64 assignedSequenceNumber = random.requestWithCallback{value: fee}(
823832
provider1,
@@ -868,6 +877,20 @@ contract EntropyTest is Test, EntropyTestUtils, EntropyEvents {
868877
0
869878
)
870879
);
880+
vm.expectEmit(false, false, false, true, address(random));
881+
emit EntropyEventsV2.Revealed(
882+
provider1,
883+
req.requester,
884+
req.sequenceNumber,
885+
random.combineRandomValues(
886+
userRandomNumber,
887+
provider1Proofs[assignedSequenceNumber],
888+
0
889+
),
890+
false,
891+
bytes(""),
892+
bytes("")
893+
);
871894
vm.prank(user1);
872895
random.revealWithCallback(
873896
provider1,
@@ -921,6 +944,20 @@ contract EntropyTest is Test, EntropyTestUtils, EntropyEvents {
921944
0
922945
)
923946
);
947+
vm.expectEmit(false, false, false, true, address(random));
948+
emit EntropyEventsV2.Revealed(
949+
provider1,
950+
req.requester,
951+
req.sequenceNumber,
952+
random.combineRandomValues(
953+
userRandomNumber,
954+
provider1Proofs[assignedSequenceNumber],
955+
0
956+
),
957+
false,
958+
bytes(""),
959+
bytes("")
960+
);
924961
random.revealWithCallback(
925962
provider1,
926963
assignedSequenceNumber,
@@ -1004,6 +1041,20 @@ contract EntropyTest is Test, EntropyTestUtils, EntropyEvents {
10041041
0
10051042
)
10061043
);
1044+
vm.expectEmit(false, false, false, true, address(random));
1045+
emit EntropyEventsV2.Revealed(
1046+
provider1,
1047+
req.requester,
1048+
req.sequenceNumber,
1049+
random.combineRandomValues(
1050+
userRandomNumber,
1051+
provider1Proofs[assignedSequenceNumber],
1052+
0
1053+
),
1054+
false,
1055+
bytes(""),
1056+
bytes("")
1057+
);
10071058
random.revealWithCallback(
10081059
provider1,
10091060
assignedSequenceNumber,
@@ -1062,6 +1113,20 @@ contract EntropyTest is Test, EntropyTestUtils, EntropyEvents {
10621113
),
10631114
revertReason
10641115
);
1116+
vm.expectEmit(false, false, false, true, address(random));
1117+
emit EntropyEventsV2.Revealed(
1118+
provider1,
1119+
address(consumer),
1120+
assignedSequenceNumber,
1121+
random.combineRandomValues(
1122+
userRandomNumber,
1123+
provider1Proofs[assignedSequenceNumber],
1124+
0
1125+
),
1126+
true,
1127+
revertReason,
1128+
bytes("")
1129+
);
10651130
random.revealWithCallback(
10661131
provider1,
10671132
assignedSequenceNumber,
@@ -1113,6 +1178,20 @@ contract EntropyTest is Test, EntropyTestUtils, EntropyEvents {
11131178
0
11141179
)
11151180
);
1181+
vm.expectEmit(false, false, false, true, address(random));
1182+
emit EntropyEventsV2.Revealed(
1183+
provider1,
1184+
reqAfterFailure.requester,
1185+
reqAfterFailure.sequenceNumber,
1186+
random.combineRandomValues(
1187+
userRandomNumber,
1188+
provider1Proofs[assignedSequenceNumber],
1189+
0
1190+
),
1191+
false,
1192+
bytes(""),
1193+
bytes("")
1194+
);
11161195
random.revealWithCallback(
11171196
provider1,
11181197
assignedSequenceNumber,
@@ -1179,6 +1258,20 @@ contract EntropyTest is Test, EntropyTestUtils, EntropyEvents {
11791258
// out-of-gas reverts have an empty bytes array as the return value.
11801259
""
11811260
);
1261+
vm.expectEmit(false, false, false, true, address(random));
1262+
emit EntropyEventsV2.Revealed(
1263+
provider1,
1264+
address(consumer),
1265+
assignedSequenceNumber,
1266+
random.combineRandomValues(
1267+
userRandomNumber,
1268+
provider1Proofs[assignedSequenceNumber],
1269+
0
1270+
),
1271+
true,
1272+
"",
1273+
""
1274+
);
11821275
random.revealWithCallback(
11831276
provider1,
11841277
assignedSequenceNumber,
@@ -1229,6 +1322,20 @@ contract EntropyTest is Test, EntropyTestUtils, EntropyEvents {
12291322
0
12301323
)
12311324
);
1325+
vm.expectEmit(false, false, false, true, address(random));
1326+
emit EntropyEventsV2.Revealed(
1327+
provider1,
1328+
address(consumer),
1329+
assignedSequenceNumber,
1330+
random.combineRandomValues(
1331+
userRandomNumber,
1332+
provider1Proofs[assignedSequenceNumber],
1333+
0
1334+
),
1335+
false,
1336+
"",
1337+
""
1338+
);
12321339
random.revealWithCallback(
12331340
provider1,
12341341
assignedSequenceNumber,
@@ -1471,6 +1578,13 @@ contract EntropyTest is Test, EntropyTestUtils, EntropyEvents {
14711578
vm.prank(provider1);
14721579
vm.expectEmit(false, false, false, true, address(random));
14731580
emit ProviderDefaultGasLimitUpdated(provider1, 0, newGasLimit);
1581+
vm.expectEmit(false, false, false, true, address(random));
1582+
emit EntropyEventsV2.ProviderDefaultGasLimitUpdated(
1583+
provider1,
1584+
0,
1585+
newGasLimit,
1586+
bytes("")
1587+
);
14741588
random.setDefaultGasLimit(newGasLimit);
14751589

14761590
EntropyStructsV2.ProviderInfo memory info = random.getProviderInfoV2(
@@ -1688,6 +1802,20 @@ contract EntropyTest is Test, EntropyTestUtils, EntropyEvents {
16881802
// out-of-gas reverts have an empty bytes array as the return value.
16891803
""
16901804
);
1805+
vm.expectEmit(false, false, false, true, address(random));
1806+
emit EntropyEventsV2.Revealed(
1807+
provider1,
1808+
address(consumer),
1809+
sequenceNumber,
1810+
random.combineRandomValues(
1811+
userRandomNumber,
1812+
provider1Proofs[sequenceNumber],
1813+
0
1814+
),
1815+
true,
1816+
bytes(""),
1817+
bytes("")
1818+
);
16911819
random.revealWithCallback(
16921820
provider1,
16931821
sequenceNumber,
@@ -1715,6 +1843,20 @@ contract EntropyTest is Test, EntropyTestUtils, EntropyEvents {
17151843
0
17161844
)
17171845
);
1846+
vm.expectEmit(false, false, false, true, address(random));
1847+
emit EntropyEventsV2.Revealed(
1848+
provider1,
1849+
req.requester,
1850+
req.sequenceNumber,
1851+
random.combineRandomValues(
1852+
userRandomNumber,
1853+
provider1Proofs[sequenceNumber],
1854+
0
1855+
),
1856+
false,
1857+
bytes(""),
1858+
bytes("")
1859+
);
17181860
random.revealWithCallback(
17191861
provider1,
17201862
sequenceNumber,

0 commit comments

Comments
 (0)