Skip to content

feat(DVM) Add arbitrary data to price requests#2229

Merged
chrismaree merged 15 commits intomasterfrom
chrismaree/arbitary-dvm-data
Nov 29, 2020
Merged

feat(DVM) Add arbitrary data to price requests#2229
chrismaree merged 15 commits intomasterfrom
chrismaree/arbitary-dvm-data

Conversation

@chrismaree
Copy link
Copy Markdown
Member

@chrismaree chrismaree commented Nov 27, 2020

Motivation

issue: #2234

This PR adds the ability for the DVM to accept any arbitrary data as part of a price request.

Summary

Briefly summarize what changes were made to accomplish the motivation above.

Details

This is done by accepting an bytes ancillaryData into the dvm price requests.

Issue(s)

Fixes 2234

Signed-off-by: Christopher Maree <christopher.maree@gmail.com>
Signed-off-by: Christopher Maree <christopher.maree@gmail.com>
Signed-off-by: Christopher Maree <christopher.maree@gmail.com>
Signed-off-by: Christopher Maree <christopher.maree@gmail.com>
{ t: "int", v: request.salt },
{ t: "address", v: request.account },
{ t: "uint", v: request.time },
{ t: "bytes", v: "0x" },
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

This change makes all downstream usages of EncryptionHelper work be default; with nothing other than this blank ancillary data.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

For now, we will simply not support ancillary data in the voter dapp.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

SGTM

OracleAncillaryInterface,
VotingInterface,
VotingAncillaryInterface
{
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

the Voting contract now considers the two new interfaces that define the Ancillary voting data.

Signed-off-by: Christopher Maree <christopher.maree@gmail.com>
Signed-off-by: Christopher Maree <christopher.maree@gmail.com>
Signed-off-by: Christopher Maree <christopher.maree@gmail.com>
Comment thread packages/cli/src/admin.js

async function decodeAllActiveGovernorProposals(artifacts, web3) {
const Voting = artifacts.require("Voting");
const voting = await Voting.deployed();
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

This is basically the ripple change throughout the repo to force Truffle to use the overloaded methods (without the ancillary data prop).

To remove this we need to make all downstream tests and infrastructure consider only the ancillary methods and then we can desperate the overloaded method. This will enable us to roll back these test changes.

* @return roundId defined as a function of the currentTime and `phaseLength` from `data`.
*/
function computeCurrentRoundId(Data storage data, uint256 currentTime) internal view returns (uint256) {
uint256 roundLength = data.phaseLength.mul(uint256(VotingInterface.Phase.NUM_PHASES_PLACEHOLDER));
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Unfortunately, some state had to move to the VotingAncillaryInterface to get the inheritance tree to compile correctly with truffle.

* @param commits array of structs that encapsulate an `identifier`, `time`, `hash` and optional `encryptedVote`.
*/
function batchCommit(Commitment[] calldata commits) external virtual;
function batchCommit(Commitment[] memory commits) public virtual;
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

this needed to become public to enable calling internally for the override method.

***********************************/

console.log("0. SETUP PHASE");
const voting = await Voting.deployed();
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

this was not added to the umip upgrade scripts clearly but is added to the vote related ones.

);
}

function computeVoteHashAncillary(request) {
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

however, I did add a method and tests to verify the behavior works as expected.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

+1

Copy link
Copy Markdown
Member

@mrice32 mrice32 left a comment

Choose a reason for hiding this comment

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

@chrismaree, this is awesome! Big +1. Contracts/prod code all look great! I left a few pretty minor comments -- more as just mental notes for us to think about down the road.

Will move on to the tests, etc.

// The index in the `pendingPriceRequests` that references this PriceRequest. A value of UINT_MAX means that
// this PriceRequest is resolved and has been cleaned up from `pendingPriceRequests`.
uint256 index;
bytes ancillaryData;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

In some later version, we should probably think about ways to redesign our DVM to not rely on any of this being stored on chain, and instead only using an initial event emission + hash stored on chain.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I agree. ideally, emit the ancillaryData and just refer to a hash of it on-chain. This is a complexity trade-off that I think we leave for later though.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Agreed.

* @param reveals array of the Reveal struct which contains an identifier, time, price and salt.
*/
function batchReveal(Reveal[] calldata reveals) external override {
function batchReveal(RevealAncillary[] memory reveals) public override {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Wow, I forgot about all of these methods.

);
}

function computeVoteHashAncillary(request) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

+1

{ t: "int", v: request.salt },
{ t: "address", v: request.account },
{ t: "uint", v: request.time },
{ t: "bytes", v: "0x" },
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

SGTM

{ t: "int", v: request.salt },
{ t: "address", v: request.account },
{ t: "uint", v: request.time },
{ t: "bytes", v: "0x" },
Copy link
Copy Markdown
Member

@mrice32 mrice32 Nov 29, 2020

Choose a reason for hiding this comment

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

Do the following hashes match?

// pseudocode
sha3(uint(5), uint(6));
sha3(uint(5), byes(0), uint(6));

If not, we need to be careful about releasing the common package as it will likely break compatibility with the current voting contract, right?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Update: they do seem to match (although someone else should verify :)). Very cool. In that case, is the "0x" element here basically just documentation to show that we're not leaving the value out?

Copy link
Copy Markdown
Member Author

@chrismaree chrismaree Nov 29, 2020

Choose a reason for hiding this comment

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

yup, it shows we are leaving it out. it also mimics exactly how the hash is generated on-chain in revealVote(identifier, time, price, "", salt); with the blank string for the bytes type. When decoded this "" translates to 0x

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

It's really really nice that a 0 length data is perfectly backwards compatible when doing tight packing 👌

Signed-off-by: Christopher Maree <christopher.maree@gmail.com>
Signed-off-by: Christopher Maree <christopher.maree@gmail.com>
@chrismaree chrismaree marked this pull request as ready for review November 29, 2020 20:36
Copy link
Copy Markdown
Member

@mrice32 mrice32 left a comment

Choose a reason for hiding this comment

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

Tests look awesome. A few very minor comments/nits

Comment thread packages/core/test/oracle/Voting.js Outdated
Comment thread packages/core/test/oracle/Voting.js
Comment thread packages/core/test/oracle/Voting.js Outdated
Comment on lines +1816 to +1818
const identifier2 = web3.utils.utf8ToHex("request-retrieval2");
const time2 = "2000";
const ancillaryData2 = web3.utils.utf8ToHex(`callerAddress:${account4}`); // ancillary data should be able to store addresses
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

nit: I think it would make this test slightly better if we made the identifier and timestamp match between both requests and only have the data differ. Then, this test would verify that the DVM correctly differentiates.

Thoughts? I think it would only require us to set identifier2 and time2 to identifier1 and time1 on these lines.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

good call. Have updated the tests accordingly and added a comment to explain why.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

+1 -- thanks @chrismaree!

Co-authored-by: Matt Rice <matthewcrice32@gmail.com>
Signed-off-by: Christopher Maree <christopher.maree@gmail.com>
@coveralls
Copy link
Copy Markdown

Coverage Status

Coverage increased (+0.1%) to 93.525% when pulling cdfba88 on chrismaree/arbitary-dvm-data into e6b63e5 on master.

@chrismaree chrismaree merged commit 551ab99 into master Nov 29, 2020
@chrismaree chrismaree deleted the chrismaree/arbitary-dvm-data branch November 29, 2020 22:23
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.

3 participants