Skip to content

Commit

Permalink
Review of superseded feature (#2315)
Browse files Browse the repository at this point in the history
* chore: superseeded review

* fix: fix test

---------

Co-authored-by: nick <[email protected]>
  • Loading branch information
martinkersner and nick-bisonai authored Nov 12, 2024
1 parent 72f7c1f commit 254b7e9
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 9 deletions.
62 changes: 54 additions & 8 deletions contracts/v0.2/src/SubmissionProxy.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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();
}

Expand Down Expand Up @@ -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
Expand All @@ -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();
}

Expand Down
2 changes: 1 addition & 1 deletion contracts/v0.2/test/SubmitStrict.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ contract SubmitStrictTest is Test {
console.logBytes(proofs[0]);

SubmissionProxy sp = SubmissionProxy(0x3a251c738e19806A546815eb6065e139A8D65B4b);
sp.submitStrict(
sp.submitStrictBatch(
feedHashes,
valuesInt,
timestampsInt,
Expand Down

0 comments on commit 254b7e9

Please sign in to comment.