From 254b7e9a90c12de25af20d0dec7746fb9564d876 Mon Sep 17 00:00:00 2001 From: Martin Kersner Date: Tue, 12 Nov 2024 13:20:40 +0900 Subject: [PATCH] Review of superseded feature (#2315) * chore: superseeded review * fix: fix test --------- Co-authored-by: nick --- contracts/v0.2/src/SubmissionProxy.sol | 62 ++++++++++++++++++++++---- contracts/v0.2/test/SubmitStrict.t.sol | 2 +- 2 files changed, 55 insertions(+), 9 deletions(-) diff --git a/contracts/v0.2/src/SubmissionProxy.sol b/contracts/v0.2/src/SubmissionProxy.sol index 30bc57b4d..2afc5bfac 100644 --- a/contracts/v0.2/src/SubmissionProxy.sol +++ b/contracts/v0.2/src/SubmissionProxy.sol @@ -397,7 +397,16 @@ contract SubmissionProxy is Ownable { } } - function submitStrict( + /** + * @notice Submit a batch of answers to multiple feeds. If any + * of the answers do not meet required conditions the + * whole batch is reverted. + * @param _feedHashes The hashes of the feeds + * @param _answers The submissions + * @param _timestamps The unixmilli timestamps of the proofs + * @param _proofs The proofs + */ + function submitStrictBatch( bytes32[] calldata _feedHashes, int256[] calldata _answers, uint256[] calldata _timestamps, @@ -412,16 +421,26 @@ contract SubmissionProxy is Ownable { uint256 feedsLength_ = _feedHashes.length; for (uint256 i = 0; i < feedsLength_; i++) { - submitSingle(_feedHashes[i], _answers[i], _timestamps[i], _proofs[i]); + submitStrictSingle(_feedHashes[i], _answers[i], _timestamps[i], _proofs[i]); } } - function submitSingle(bytes32 _feedHash, int256 _answer, uint256 _timestamp, bytes calldata _proof) public { - if (_timestamp <= (block.timestamp - dataFreshness) * 1000 ) { + /** + * @notice Submit a single answer to a feed. The answer is + * reverted if any of the required conditions are not met. + * @param _feedHash The hash of the feed + * @param _answer The submission + * @param _timestamp The unixmilli timestamp of the proof + * @param _proof The proof + */ + function submitStrictSingle(bytes32 _feedHash, int256 _answer, uint256 _timestamp, bytes calldata _proof) public { + if (_timestamp <= (block.timestamp - dataFreshness) * 1000) { + // answer is not fresh -> do not submit! revert AnswerOutdated(); } if (lastSubmissionTimes[_feedHash] >= _timestamp) { + // answer is superseeded -> do not submit! revert AnswerSuperseded(); } @@ -450,8 +469,21 @@ contract SubmissionProxy is Ownable { } } - // works same as submit, but will only return error if the proof is invalid, ignore if answer is superseded - function updatePrices(bytes32[] calldata _feedHashes, int256[] calldata _answers, uint256[] calldata _timestamps, bytes[] calldata _proofs) public { + /** + * @notice Submit a batch of answers to multiple feeds. The answers are + * ignored if they have been superseeded. If any of the answers do not + * meet the rest of required conditions the whole batch is reverted. + * @param _feedHashes The hashes of the feeds + * @param _answers The submissions + * @param _timestamps The unixmilli timestamps of the proofs + * @param _proofs The proofs + */ + function updatePrices( + bytes32[] calldata _feedHashes, + int256[] calldata _answers, + uint256[] calldata _timestamps, + bytes[] calldata _proofs + ) public { if ( _feedHashes.length != _answers.length || _answers.length != _proofs.length || _proofs.length != _timestamps.length || _feedHashes.length > maxSubmission @@ -465,9 +497,23 @@ contract SubmissionProxy is Ownable { } } - + /** + * @notice Submit a single submission to a feed. The submission is + * ignored if it has been superseeded. If the submission does not + * meet the rest of required conditions the submission is reverted. + * @param _feedHash The hash of the feed + * @param _answer The submission + * @param _timestamp The unixmilli timestamp of the proof + * @param _proof The proof + */ function updatePrice(bytes32 _feedHash, int256 _answer, uint256 _timestamp, bytes calldata _proof) public { - if (_timestamp <= (block.timestamp - dataFreshness) * 1000 ) { + if (lastSubmissionTimes[_feedHash] >= _timestamp) { + // answer is superseeded -> skip submission + return; + } + + if (_timestamp <= (block.timestamp - dataFreshness) * 1000) { + // answer is not fresh -> do not submit! revert AnswerOutdated(); } diff --git a/contracts/v0.2/test/SubmitStrict.t.sol b/contracts/v0.2/test/SubmitStrict.t.sol index 898edfdc2..54ad41146 100644 --- a/contracts/v0.2/test/SubmitStrict.t.sol +++ b/contracts/v0.2/test/SubmitStrict.t.sol @@ -27,7 +27,7 @@ contract SubmitStrictTest is Test { console.logBytes(proofs[0]); SubmissionProxy sp = SubmissionProxy(0x3a251c738e19806A546815eb6065e139A8D65B4b); - sp.submitStrict( + sp.submitStrictBatch( feedHashes, valuesInt, timestampsInt,