Skip to content

Commit

Permalink
fix: update based on feedbacks
Browse files Browse the repository at this point in the history
  • Loading branch information
nick-bisonai committed May 10, 2024
1 parent 7f160fa commit 0789894
Show file tree
Hide file tree
Showing 8 changed files with 102 additions and 17 deletions.
8 changes: 4 additions & 4 deletions contracts/v0.2/src/Feed.sol
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {IFeed} from "./interfaces/IFeed.sol";
*/
contract Feed is Ownable, IFeed {
uint8 public immutable decimals;
string public description;
string public name;
address public submitter;

struct Round {
Expand Down Expand Up @@ -45,12 +45,12 @@ contract Feed is Ownable, IFeed {
* @notice Construct a new `Feed` contract.
* @dev The deployer of the contract will become the owner.
* @param _decimals The number of decimals for the feed
* @param _description The description of the feed
* @param _name The name of the feed
* @param _submitter The address of the submitter
*/
constructor(uint8 _decimals, string memory _description, address _submitter) Ownable(msg.sender) {
constructor(uint8 _decimals, string memory _name, address _submitter) Ownable(msg.sender) {
decimals = _decimals;
description = _description;
name = _name;
submitter = _submitter;
}

Expand Down
4 changes: 2 additions & 2 deletions contracts/v0.2/src/FeedProxy.sol
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ contract FeedProxy is Ownable, IFeedProxy {
/**
* @inheritdoc IFeed
*/
function description() external view returns (string memory) {
return feed.description();
function name() external view returns (string memory) {
return feed.name();
}

/**
Expand Down
4 changes: 2 additions & 2 deletions contracts/v0.2/src/FeedRouter.sol
Original file line number Diff line number Diff line change
Expand Up @@ -170,8 +170,8 @@ contract FeedRouter is Ownable, IFeedRouter {
/**
* @inheritdoc IFeedRouter
*/
function description(string calldata _feedName) external view validFeed(_feedName) returns (string memory) {
return IFeedProxy(feedToProxies[_feedName]).description();
function name(string calldata _feedName) external view validFeed(_feedName) returns (string memory) {
return IFeedProxy(feedToProxies[_feedName]).name();
}

/**
Expand Down
2 changes: 1 addition & 1 deletion contracts/v0.2/src/SubmissionProxy.sol
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,7 @@ contract SubmissionProxy is Ownable {
continue;
}

if (keccak256(abi.encodePacked(feeds[_feedHashes[i]].description())) != _feedHashes[i]) {
if (keccak256(abi.encodePacked(feeds[_feedHashes[i]].name())) != _feedHashes[i]) {
// feedHash not matching with registered feed -> do not submit!
continue;
}
Expand Down
6 changes: 3 additions & 3 deletions contracts/v0.2/src/interfaces/IFeed.sol
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ interface IFeed {
function decimals() external view returns (uint8);

/**
* @notice Get description of the feed.
* @return description The description of the feed.
* @notice Get name of the feed.
* @return name The name of the feed.
*/
function description() external view returns (string memory);
function name() external view returns (string memory);

/**
* @notice Get version and type of the feed.
Expand Down
6 changes: 3 additions & 3 deletions contracts/v0.2/src/interfaces/IFeedRouter.sol
Original file line number Diff line number Diff line change
Expand Up @@ -135,11 +135,11 @@ interface IFeedRouter {
function typeAndVersion(string calldata feedName) external view returns (string memory);

/**
* @notice Get description of the feed given a feed name.
* @notice Get name of the feed given a feed name.
* @param feedName The feed name.
* @return description The description of the feed.
* @return name The name of the feed.
*/
function description(string calldata feedName) external view returns (string memory);
function name(string calldata feedName) external view returns (string memory);

/**
* @notice Get supported feed names.
Expand Down
2 changes: 1 addition & 1 deletion contracts/v0.2/src/interfaces/IFeedSubmit.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ pragma solidity ^0.8.20;
interface IFeed {
function submit(int256 answer) external;

function description() external view returns (string memory);
function name() external view returns (string memory);
}
87 changes: 86 additions & 1 deletion contracts/v0.2/test/SubmissionProxy.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import {IFeed} from "../src/interfaces/IFeed.sol";
contract SubmissionProxyTest is Test {
SubmissionProxy submissionProxy;
uint8 DECIMALS = 18;
string DESCRIPTION = "Test Feed";
string[] SAMPLE_NAMES = [
"BTC-USDT",
"ETH-USDT",
Expand Down Expand Up @@ -343,6 +342,67 @@ contract SubmissionProxyTest is Test {
submissionProxy.submit(feedHashes_, submissions_, timestamps_, proofs_);
}

function test_SubmitUnregisteredFeed() public {
(address alice_, uint256 aliceSk_) = makeAddrAndKey("alice");
(address bob_, uint256 bobSk_) = makeAddrAndKey("bob");
(address celine_, uint256 celineSk_) = makeAddrAndKey("celine");
(, uint256 dummySk_) = makeAddrAndKey("dummy");

submissionProxy.addOracle(alice_);
submissionProxy.addOracle(bob_);
submissionProxy.addOracle(celine_);

uint256 numOracles_ = 1;
int256 submissionValue_ = 10;
(
bytes32[] memory feedHashes_,
int256[] memory submissions_,
bytes[] memory proofs_,
uint256[] memory timestamps_,
address[] memory feeds_
) = prepareFeedsSubmissions(numOracles_, submissionValue_, dummySk_);
bytes32 hash_ = keccak256(abi.encodePacked(submissions_[0], timestamps_[0], feedHashes_[0]));
proofs_[0] =
abi.encodePacked(createProof(aliceSk_, hash_), createProof(bobSk_, hash_), createProof(celineSk_, hash_));

submissionProxy.setProofThreshold(feedHashes_[0], 100); // 100 % of the oracles must submit a valid proof
submissionProxy.removeFeed(feedHashes_[0]);
submissionProxy.submit(feedHashes_, submissions_, timestamps_, proofs_);

vm.expectRevert(Feed.NoDataPresent.selector);
IFeed(feeds_[0]).latestRoundData();
}

function test_SubmitUnmatchedNameFeed() public {
(address alice_, uint256 aliceSk_) = makeAddrAndKey("alice");
(address bob_, uint256 bobSk_) = makeAddrAndKey("bob");
(address celine_, uint256 celineSk_) = makeAddrAndKey("celine");
(, uint256 dummySk_) = makeAddrAndKey("dummy");

submissionProxy.addOracle(alice_);
submissionProxy.addOracle(bob_);
submissionProxy.addOracle(celine_);

uint256 numOracles_ = 1;
int256 submissionValue_ = 10;
(
bytes32[] memory feedHashes_,
int256[] memory submissions_,
bytes[] memory proofs_,
uint256[] memory timestamps_,
address[] memory feeds_
) = prepareFeedsSubmissionsWrongName(numOracles_, submissionValue_, dummySk_);
bytes32 hash_ = keccak256(abi.encodePacked(submissions_[0], timestamps_[0], feedHashes_[0]));
proofs_[0] =
abi.encodePacked(createProof(aliceSk_, hash_), createProof(bobSk_, hash_), createProof(celineSk_, hash_));

submissionProxy.setProofThreshold(feedHashes_[0], 100); // 100 % of the oracles must submit a valid proof
submissionProxy.submit(feedHashes_, submissions_, timestamps_, proofs_);

vm.expectRevert(Feed.NoDataPresent.selector);
IFeed(feeds_[0]).latestRoundData();
}

function test_SubmitCorrectProof() public {
(address alice_, uint256 aliceSk_) = makeAddrAndKey("alice");
(address bob_, uint256 bobSk_) = makeAddrAndKey("bob");
Expand Down Expand Up @@ -398,6 +458,31 @@ contract SubmissionProxyTest is Test {
return (feedHashes_, submissions_, proofs_, timestamps_, feeds_);
}

function prepareFeedsSubmissionsWrongName(uint256 _numOracles, int256 _submissionValue, uint256 _oracleSk)
private
returns (bytes32[] memory, int256[] memory, bytes[] memory, uint256[] memory, address[] memory)
{
(
bytes32[] memory feedHashes_,
int256[] memory submissions_,
bytes[] memory proofs_,
uint256[] memory timestamps_
) = createSubmitParameters(_numOracles);
address[] memory feeds_ = new address[](_numOracles);
for (uint256 i = 0; i < _numOracles; i++) {
Feed feed_ = new Feed(DECIMALS, "wrong-name", address(submissionProxy));
feeds_[i] = address(feed_);
feedHashes_[i] = keccak256(abi.encodePacked(SAMPLE_NAMES[i]));
submissions_[i] = _submissionValue;
timestamps_[i] = block.timestamp;
proofs_[i] =
createProof(_oracleSk, keccak256(abi.encodePacked(timestamps_[i], submissions_[i], feedHashes_[i])));
submissionProxy.updateFeed(feedHashes_[i], address(feeds_[i]));
}

return (feedHashes_, submissions_, proofs_, timestamps_, feeds_);
}

function createSubmitParameters(uint256 numSubmissions)
private
pure
Expand Down

0 comments on commit 0789894

Please sign in to comment.