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

feat: merkle verification and changes implemented #59

Merged

Conversation

SamAg19
Copy link
Member

@SamAg19 SamAg19 commented Dec 18, 2023

Problem statement:

The current implementation requires the signed Oracle block to be sent to the result manager to update collection values. This is not scalable and updating will become expensive as we add more collections to the Razor Oracle.

Solution:

We will be shifting to a Merkle tree implementation for updation in which the Merkle leaves will hold the result of each collection and the clients will receive signed result, Merkle root, and Merkle proof along with the signature for each collection depending on the collection data they require

To update the values of each collection, clients will need to query the Merkle tree for each collection off-chain which will be exposed through an API, and send the data received through their contracts to update the values. The clients will only need to update the collections they require for their application.

The functions exposed to clients will be:

  • fetchResult():- this function is responsible for updating the collection data and receiving the latest collection result. The result will only be updated if the lastUpdatedTimestamp for a particular collection in the contracts precedes the one that is being sent over, else the result won't be updated and the client will receive the stored result in the contracts
  • getResult():- this is a view function where you will just receive the collection data stored in the contracts. It does not deal with updation and the results retrieved may be stale
  • validateResult(): this is a view function that allows people to validate whether the data they are receiving from the API is valid or not

Copy link

netlify bot commented Dec 18, 2023

Deploy Preview for razor-bridge-mainnet canceled.

Name Link
🔨 Latest commit 45493e6
🔍 Latest deploy log https://app.netlify.com/sites/razor-bridge-mainnet/deploys/6581343b3eaa7e0008816adb

contracts/Forwarder.sol Outdated Show resolved Hide resolved
contracts/Forwarder.sol Outdated Show resolved Hide resolved
contracts/ResultManager.sol Outdated Show resolved Hide resolved
yohanelly95
yohanelly95 previously approved these changes Dec 18, 2023
merkle-tree.json Outdated Show resolved Hide resolved
@SamAg19 SamAg19 merged commit 8967987 into master Dec 19, 2023
4 checks passed
Copy link
Member

@hrishikeshio hrishikeshio left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changes requested

bytes memory signature
) external onlyRole(FORWARDER_ROLE) returns (uint256, int8, uint256) {
if (result.lastUpdatedTimestamp > _collectionResults[result.name].lastUpdatedTimestamp) {
bytes memory resultBytes = abi.encode(result);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not required

if (result.lastUpdatedTimestamp > _collectionResults[result.name].lastUpdatedTimestamp) {
bytes memory resultBytes = abi.encode(result);
bytes32 messageHash = keccak256(
abi.encodePacked(merkleRoot, resultBytes)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just sign merkle root

) != signerAddress) revert InvalidSignature();

bytes32 leaf = keccak256(
bytes.concat(keccak256(abi.encode(resultBytes)))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

result not resultbytes

emit ResultUpdated(result);
}

return _getResult(result.name);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In future optimization, add multiproof support.


emit BlockReceived(messageBlock);
return true;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

code repetition.

@@ -3,80 +3,31 @@ pragma solidity ^0.8.0;

interface IDelegator {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

change name to iforwarder

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants