Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Fix] Increment nextVersionIndexToCommit in unrequested commit flow #100

Merged
merged 2 commits into from
Sep 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/perennial-oracle/contracts/pyth/PythOracle.sol
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@ contract PythOracle is IPythOracle, Instance, Kept {
if (oracleVersion <= minVersion || oracleVersion >= maxVersion) revert PythOracleVersionOutsideRangeError();

_recordPrice(oracleVersion, pythPrice);
nextVersionIndexToCommit = versionIndex;
_latestVersion = oracleVersion;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ const VAA_AFTER_EXPIRATION =
const VAA_WAY_AFTER_EXPIRATION =
'0x01000000030d00759894dd446d5bbb720d73f32fea0c728cfecc474369fd46de94c1ee3d4f6a326eafdaa907c8b4c2fd027d7047af501103f513d9ed7cbde0a404516c7fa866c80001a2c0276919ba58edea3f3f395fbeaac7a8c3e0a8688f9e5d5c925396b503e90b4e652bd85e8672878a0960ff65515226651f12ad49721a0665f0bb2e5c28fb0c0102dde9e7d36aaef1a7528bed0f95f7d52d6ca33169afee85604669115454b90bbf36eb6de59decdcc4517cdb849efaef0626c83b318efbdf34b5373fd9e2a7c7f6000479d697d129cd515036eb19dfc17e08dd6628073204f5177042636682f9c268350abb39ee46dd119dd3dca48324f43bd72e8be84afa6ccde91c5d7d76ef7dd56e010ac6c6d3d4d7ed37747282478a628a7208e45aa609323ee54af0ab974755e3bdcc1e0fc45de741a3f629591a8f465e99de5b0670943bb1e74e7661d668fae491a5010b13f2c4cd06b86ad65495ab9b16b1ba8605a4a30207ab65a36a7e207f576983c50b3a06351c4acacac5d0b6c6491a575bc265ce4f58cd882fa2df4e1179730830000cfb174a0ce4426bff92f9b98387ec915f2f799ede09e75ccf916ddfa2e6b9da162fdc215ee99b02885468c23a36e66e2ce4265d222e0435cdc464239406021605010dc6e6437bd2395449d08890ee69b20451ae2b8b9ef33d5589c031d00164a824aa749dc420f1d7404441c79be128bf5cab830404b6efa2210d1a823a18479bf342000eeebc6b5b1ae0d9bec0b78e629b8548bcc37ec455bb99f6d2d312c37bbccc043716860daa6c998614ca9d67a3a6336b5da352d7dfd4b99a44034df0e4c8d90bd7000f363aa0eaa28bf27f5e7faab756500a57fb5a2b2eceea02b574586d12b73504fc035f863a497d8a3ed23e2383ca05272df7f1dd01989fc0113b9aef9eeef371990010ad23fcf0262170cb429491de2d34e2591733eee440d4067657e233a5c83dcf647d1b8c9bccd06bde731bad3726957d067422ff327f71cab36402e8f677268cf100119f33cd0d885b9ae579753c8c24b2f2a322053588c1e0b081eaa51341f7bda7df252330808b0d3a042da1a4cc45a6627cf61127cc153dfd47f7197cf97ef52c7f0112ac663714bf20c6d0dcbd53f7cb816b3dd3d730301605a0e710241c663e0023933b64337001cb6faad9c1f7b368af993a7004dace776de4400c2e27dfd33cb83f0064815b6a00000000001af8cd23c2ab91237730770bbea08d61005cdda0984348f3f6eecb559638c0bba0000000001b8420db0150325748000300010001020005009d04028fba493a357ecde648d51375a445ce1cb9681da1ea11e562b53522a5d3877f981f906d7cfe93f618804f1de89e0199ead306edc022d3230b3e8305f391b00000002aa2158047000000000df3561dfffffff80000002a9d293958000000000f470500010000000a0000000c0000000064815b6a0000000064815b6a0000000064815b690000002aa2063e07000000000e02985d0000000064815b69e6c020c1a15366b779a8c870e065023657c88c82b82d58a9fe856896a4034b0415ecddd26d49e1a8f1de9376ebebc03916ede873447c1255d2d5891b92ce57170000002c59e152a00000000009c186cafffffff80000002c56052dc8000000000a631ce80100000007000000080000000064815b6a0000000064815b6a0000000064815b690000002c59e152a00000000009c186ca0000000064815b69c67940be40e0cc7ffaa1acb08ee3fab30955a197da1ec297ab133d4d43d86ee6ff61491a931112ddf1bd8147cd1b641375f79f5825126d665480874634fd0ace0000002ac802c09000000000060e60dbfffffff80000002ac4d3008800000000045ee4460100000018000000200000000064815b6a0000000064815b6a0000000064815b690000002ac802c09000000000060e60db0000000064815b698d7c0971128e8a4764e757dedb32243ed799571706af3a68ab6a75479ea524ff846ae1bdb6300b817cee5fdee2a6da192775030db5615b94a465f53bd40850b50000002abfdc1ce0000000001a634b48fffffff80000002abc79db28000000001abdd5ca01000000090000000a0000000064815b6a0000000064815b6a0000000064815b690000002abfdc1ce0000000001a634b480000000064815b69543b71a4c292744d3fcf814a2ccda6f7c00f283d457f83aa73c41e9defae034ba0255134973f4fdf2f8f7808354274a3b1ebc6ee438be898d045e8b56ba1fe1300000000000000000000000000000000fffffff8000000000000000000000000000000000000000000000000080000000064815b6a0000000064815b690000000000000000000000000000000000000000000000000000000000000000'

// This VAA has timestamp 1686199144 (STARTING_TIME + 163)
const VAA_WAY_AFTER_EXPIRATION_2 =
'0x01000000030d0016a8538d039204fa3b895c03f81bc0de779b449778f63b548a9146801fd967b75cf37489758f3e9323deb8839c60e5fee0d42530c1c4bcdfcb254182f0cf892b0001fedf5f3808a676c9e1c1344d8b18c498afa94898c0c40475b4d06ed0fcf08b3c6fb8383836718f03155438351ad74cf513be309aff3fe93aa2e8e5edbc5c1c6500026cc4c14afcbecc04bcb0d902e2ca3c99c59b270099b7c6be393d4c4c7a01490f5c4361e42dc1ca62711a01cdb92f9ed7b165a575511d180a4daa3e6eeab583070104b855ba806034e37ba6490a75ef5f017cf4c2c7fae847e6c38fc9a5df0e1e82a5202d6ef3a4071ba9f83050fb79887f2eb634ca7f539c3db143dc7bf182d6725500092f7661e5bcbf0c164afb73d7f32f7e64095fee08e9b26f69410d4779e2823f106da644e8525f3bd2641e4228f732b1ff32e6405fdc8c63d345cf91c62da1eefe000a720d6615cabed45415251032aa6b0bc46c0300ded46fcda7d8f26455da7378b90fea772ea53b7fe643af889bcf89ec6c83f6801bbe6c754d960dade3797f5989010b0dc69db9ce4e7b07f4d093e021319b42c59ede4c0a3bb453c2a936bb91602cd8080b16974fcdb29e18645a42b4aa878e3fc976f07127073a7c344a2629855d02000c1d1ad20603607605d7b90b29714b8ce8de9e05ed27f6dcbfd00c2f30db4c3c9f6979e2ed067d2a8df7d98ca7881f318491a1abcf0f9000321d4f4d8719fce48b000da9886945ebb35f9d1c46d35920e189e1ca6373e4e9c75acfc5be11995aacea715b72ac976e62f6d486e386a42b74d0300e863c5d729622a6a5a7ac89604316bb010f4eeae045c765afba2de2d403f83b9b7b89dd41f473539f42240bd33c964d01227419376fc927fd55f529ac9e8e6de3c647af85d7b6c12f457fb18f00c30730fc0110ad9523a46603aaf4c92aa1c2af6abcbad35391141f3401e3ee6921841f4856702c61781ad12420f1a183bd99c7bc39ca171b7116961a19999d05b6ce15f7bb4f001104bbe229048262ae8cfd85b469159351b76bd4071b297e9029254ba5ad58b55d515661f2ea3ea658a2bdbab1038366c16a8b95209a5ef62b084e66d7d237a14000120b359cc5d334711f221fcee33c91392e6370d43c430875b8f30ff00b23b0119f6269916ede997c3aad51a389c40bbd044a3c26bdac7b52c751d5d7309b34519d0064815b6800000000001af8cd23c2ab91237730770bbea08d61005cdda0984348f3f6eecb559638c0bba0000000001b8420b80150325748000300010001020005009d04028fba493a357ecde648d51375a445ce1cb9681da1ea11e562b53522a5d3877f981f906d7cfe93f618804f1de89e0199ead306edc022d3230b3e8305f391b00000002aa1eb4e89000000000e792677fffffff80000002a9d288990000000000f472d93010000000a0000000c0000000064815b680000000064815b680000000064815b670000002aa1eb4e89000000000e7926770000000064815b67e6c020c1a15366b779a8c870e065023657c88c82b82d58a9fe856896a4034b0415ecddd26d49e1a8f1de9376ebebc03916ede873447c1255d2d5891b92ce57170000002c59d2106000000000091aad52fffffff80000002c560481e8000000000a633e580100000007000000080000000064815b680000000064815b680000000064815b670000002c59c3b2a400000000092907260000000064815b67c67940be40e0cc7ffaa1acb08ee3fab30955a197da1ec297ab133d4d43d86ee6ff61491a931112ddf1bd8147cd1b641375f79f5825126d665480874634fd0ace0000002ac7de1359000000000558f5effffffff80000002ac4d2932800000000045edb310100000018000000200000000064815b680000000064815b680000000064815b670000002ac80a7056000000000618276a0000000064815b678d7c0971128e8a4764e757dedb32243ed799571706af3a68ab6a75479ea524ff846ae1bdb6300b817cee5fdee2a6da192775030db5615b94a465f53bd40850b50000002abfdc1ce0000000001a634b48fffffff80000002abc79a090000000001abde11401000000090000000a0000000064815b680000000064815b680000000064815b670000002abfdc1ce0000000001a634b480000000064815b67543b71a4c292744d3fcf814a2ccda6f7c00f283d457f83aa73c41e9defae034ba0255134973f4fdf2f8f7808354274a3b1ebc6ee438be898d045e8b56ba1fe1300000000000000000000000000000000fffffff8000000000000000000000000000000000000000000000000080000000064815b680000000064815b670000000000000000000000000000000000000000000000000000000000000000'

// New Multi-Update payload w/ Publish Time: 1693407490
const VAA_WITH_MULTIPLE_UPDATES =
'0x504e41550100000003b801000000030d00082c2243d3fa525d51bc3b3bbe2016c427e53753326e7223e21438b5411eb59103aba9fee9c4537113bfb38706ce0d1f1d10bbd5e7d947c78f7f7c883857bfa7000284f291f05f5652dde66ee6489787a61e282ff6c201e0ab9452f50b53e434f2ae2239700e071906d30ee4fe2b9e5958a1523b876bb672a19765b4ac53e580fb4501035734dd99903dd74d7bec4b47a3aa36ddfd78a8d06e974810e77f19fd9f9578d43d1fe71fe75dea33151a92e5987664e3654566ff9f24948d9b6d9eff32908df30004c16f14f7cf686e32381cc518f530a0030ef1d8f12428f9391ce743aae4de9cec5455fd42520c0c3850b6cf8c60f48738f79b2bd36621ea392ac83bc897f4c6ff010665531930c4684bc042461c1c8fdb36a6db67fdb19625cc83cc7d884da09b173d15c4605e122905f28298dfa2e5d8a3e2b565cdba851b1d228224b9bd52cf2fa500090ac3b0b7602d06f3afca318a65d343012cce4d56adb1c9a66853290dbb2e4b49389ec5d2dcf4b1ce4f8c6f57a883a1fa74ea6d4c58923e9fce3597afeed7671c000a1478cdd918941c9ee16a309373f00301c770134ee55f4def3fb120b4c7c935c445df29623127be0e10e5030f246e41ed682ba93c05209095b0b61ea7d47a0422010b3e5801e17768884398cb8ab6a1a42b4c7843068744d12e46f65682351d571d180c3a477af5126148c6291f3654c50cec1f7a73e9ef0a5d312a31b93f172c63d0000ebf74e1c3e5b490fdaddc24a78b24a248313a4dc878ae5b7b98512a5473c5c69809aa906f04a08b1e03f4cd706a9b0983201b6f095060337fc3ac638f3d356cac010f3ca2405569e08444a4a90dc5f616ad4476e8f71ce5a766a5083311baa676928d30f52624ae733326fbec70b6e8833373680624d152edc9c0080711db69db809f0010e7bf1f7359520372c48f6c7745853de313716eb4fc4bb134f9c3bd2b01c3f8ae6ed7c703ea7551521171c3768ecb91b49f0177762a5cf03ffb9f10d0050ea5ca011124ec81adb4688547fbc190f2673491159de676a8d348bd8f0fd2f715643fca093d01c944cd423eff20fa2a77b259b917e319e6822b8b4bd8e1f896af69d064b701123067c9eb31326b3021e70002cb0a222d943fa876a4ee1afa97ea55dbfdfebc341033e302857a4625419d2cb8bbeceea89489531daefb4d74c8b688fdb587468f0064ef590400000000001ae101faedac5851e32b9b23b5f9411a8c2bac4aae3ed4dd7b811dd1a72ea4aa71000000000085aae00141555756000000000005861808000027105453884a96124ee00a9e46bcfd854f58a139537902005500ff61491a931112ddf1bd8147cd1b641375f79f5825126d665480874634fd0ace00000027a3a9356000000000063c479bfffffff80000000064ef59020000000064ef590100000027ea4388b800000000059d66a809fd052ff1a1f0fd3638fc34ad246bc2b004ec0e67a8a1180177cf30b2c0bebbb1adfe8f7985d051d205a01e2504d9f0c06e7e7cb0cf24116098ca202ac5f6ade2e8f5a12ec006b16d46be1f0228b94d95485aa0e4df2967e9353738ab1ee8ac694f05c9f93090789120e39302b12a1330f05c8f71c0f5a883e79ce8949e3992bd353598ed5ff2f09be708bf76dd38f0da18fcb0f7ead4d1de56db6c0442b9488350275717d4ebee942ea448bc9f492c881aef590a005500e62df6c8b4a85fe1a67db44dc12de5db330f7ac66b72dc658afedf0f4a415b43000002775a71feff000000004d4744cdfffffff80000000064ef59020000000064ef59010000027c169ba7a0000000003d7557a009fb953b6bdba977da858e45c514b3b2f01a03ba7a3cca00578b83239a81c37f7a18474e8563d3c530fa371b7db694a82e6d9b8afe758ef024eae8bedac96c3218b1c3915d0914dfada4e50b43cfcc1c010e61ac7cc3f171452564d92964915c67c40cffae8b4613f97247c357de9270a7201ad298af334c7f77ae5a6c4556c660208f5f41b3ec8cbb1b9b7329dd38f0da18fcb0f7ead4d1de56db6c0442b9488350275717d4ebee942ea448bc9f492c881aef590a'
Expand Down Expand Up @@ -497,7 +501,7 @@ testOracles.forEach(testOracle => {
value: 1,
})
expect((await pythOracle.latest()).timestamp).to.equal(STARTING_TIME + 60)
expect(await pythOracle.nextVersionIndexToCommit()).to.equal(0)
expect(await pythOracle.nextVersionIndexToCommit()).to.equal(1)

expect(
pythOracle.connect(user).commit(0, STARTING_TIME, VAA, {
Expand All @@ -520,6 +524,31 @@ testOracles.forEach(testOracle => {
}),
).to.revertedWithCustomError(pythOracle, 'PythOracleNonIncreasingPublishTimes')
})

it('increases nextVersionIndexToCommit to disallow out of order commits', async () => {
await pythOracle.connect(oracleSigner).request(user.address)
expect(await pythOracle.nextVersionIndexToCommit()).to.equal(0)

await time.increaseTo(1686199138)
await pythOracle.connect(oracleSigner).request(user.address) // 1686199139
await time.increase(4)
await pythOracle.connect(oracleSigner).request(user.address) // 1686199144
expect(await pythOracle.nextVersionIndexToCommit()).to.equal(0)
expect(await pythOracle.versionListLength()).to.equal(3)

await time.increase(60)
await pythOracle.connect(user).commit(2, 1686199140, VAA_WAY_AFTER_EXPIRATION_2, {
value: 1,
})
expect((await pythOracle.latest()).timestamp).to.equal(1686199140)

await expect(
pythOracle.connect(user).commit(1, 1686199139, VAA_WAY_AFTER_EXPIRATION, {
value: 1,
}),
).to.be.revertedWithCustomError(pythOracle, 'PythOracleVersionIndexTooLowError')
// expect((await pythOracle.latest()).timestamp).to.equal(1686199139)
})
})

describe('#status', async () => {
Expand Down