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

Implement the TACo API module #263

Merged
merged 9 commits into from
Sep 12, 2023
Merged

Implement the TACo API module #263

merged 9 commits into from
Sep 12, 2023

Conversation

piotr-roslaniec
Copy link
Contributor

@piotr-roslaniec piotr-roslaniec commented Aug 11, 2023

Type of PR:

  • Feature

Required reviews:

  • 3

What this does:

  • Implements a simplified API version for TACo

Issues fixed/closed:

Why it's needed:

Explain how this PR fits in the greater context of the NuCypher Network.
E.g., if this PR address a nucypher/productdev issue, let reviewers know!

Notes for reviewers:

@codecov-commenter
Copy link

codecov-commenter commented Aug 14, 2023

Codecov Report

Merging #263 (1dba09f) into alpha (c18f996) will decrease coverage by 0.01%.
The diff coverage is 72.09%.

@@            Coverage Diff             @@
##            alpha     #263      +/-   ##
==========================================
- Coverage   81.37%   81.36%   -0.01%     
==========================================
  Files          36       37       +1     
  Lines        1036     1068      +32     
  Branches      110      112       +2     
==========================================
+ Hits          843      869      +26     
- Misses        185      191       +6     
  Partials        8        8              
Files Changed Coverage Δ
src/conditions/context/context.ts 96.82% <ø> (ø)
src/agents/coordinator.ts 24.48% <10.00%> (-2.79%) ⬇️
src/sdk/strategy/cbd-strategy.ts 93.33% <66.66%> (ø)
src/dkg.ts 33.33% <80.00%> (+5.12%) ⬆️
src/taco.ts 95.83% <95.83%> (ø)
src/characters/cbd-recipient.ts 92.72% <100.00%> (ø)

@nucypher nucypher deleted a comment from github-actions bot Aug 14, 2023
Base automatically changed from set-default-variant to alpha August 14, 2023 14:04
@nucypher nucypher deleted a comment from github-actions bot Aug 16, 2023
@nucypher nucypher deleted a comment from github-actions bot Aug 16, 2023
@nucypher nucypher deleted a comment from github-actions bot Aug 16, 2023
@nucypher nucypher deleted a comment from github-actions bot Aug 24, 2023
@piotr-roslaniec piotr-roslaniec changed the base branch from alpha to nucypher-core-0.12.0 August 28, 2023 08:53
src/taco.ts Outdated Show resolved Hide resolved
@piotr-roslaniec piotr-roslaniec marked this pull request as ready for review August 28, 2023 10:35
Copy link
Contributor

@theref theref left a comment

Choose a reason for hiding this comment

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

This looks great, exactly what adopters want to use

Base automatically changed from nucypher-core-0.12.0 to alpha August 28, 2023 15:25
@nucypher nucypher deleted a comment from github-actions bot Aug 28, 2023
src/characters/cbd-recipient.ts Outdated Show resolved Hide resolved
src/conditions/condition-expr.ts Outdated Show resolved Hide resolved
src/taco.ts Outdated Show resolved Hide resolved
src/taco.ts Outdated
Comment on lines 14 to 18
// TODO: How do we get rid of these two fields? We need them for decrypting
// We ritualId in order to fetch the DKG participants and create DecryptionRequests for them
ritualId: number;
// We need to know the threshold in order to create DecryptionRequests
threshold: number;
Copy link
Contributor Author

@piotr-roslaniec piotr-roslaniec Sep 4, 2023

Choose a reason for hiding this comment

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

Is there anything we can do to get rid of these parameters in the user-facing API?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Do we want to expose class TacoMessageKit.requireSigner so that decrypting users can detect when they need to pass signer in?

Copy link
Member

Choose a reason for hiding this comment

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

Given my comment above, I question whether this TacoMesageKit object is needed at all.

conditionExpr is in the ACP in the ThresholdMessageKit, and I don't believe ritualId and threshold are needed because they can be obtained from the Coordinator contract along with the ThresholdMessageKit.

My concern lies in returning objects that aren't subject to versioning, and the caller potentially serializing them. Ideally, encrypt would return a ThresholdMessageKit just like python.

Of course, if additional information is actually needed in the ThresholdMessageKit itself we can explore that.

Copy link
Member

@derekpierre derekpierre left a comment

Choose a reason for hiding this comment

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

See comment about TacoMessageKit.

Copy link
Member

@derekpierre derekpierre left a comment

Choose a reason for hiding this comment

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

Needs another rebase over #286.

Comment on lines 123 to 124
word0: dkgPublicKeyBytes.slice(0, 16),
word1: dkgPublicKeyBytes.slice(16, 32),
Copy link
Member

@derekpierre derekpierre Sep 8, 2023

Choose a reason for hiding this comment

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

A G1Point is 48 bytes and defined as follows.

Shouldn't word0 by (0,32) and word1 (32,48)?

Copy link
Member

Choose a reason for hiding this comment

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

I think we need to start thinking about "acceptance" tests in nucypher-ts that interact with actual contracts (cc @cygnusv , @KPrasch ).

Copy link
Contributor Author

@piotr-roslaniec piotr-roslaniec Sep 8, 2023

Choose a reason for hiding this comment

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

IMHO acceptance tests with contracts are unnecessary. We're only supporting read operations (at this point), and setting those up is not different than existing mocks (so, just having simple pass-through facades for mock values). Yes, this is a bug that went unnoticed. But it would have been caught easily by QA which we do on every release.

I think the better solution to this particular problem is to enhance the BLS12381.G1PointStructOutput generated type with a wrapper that performs validation. The word0 and word fields are represented as strings by typechain in generated typings, which also prevented the TS compiler from catching this issue.

Copy link
Member

@derekpierre derekpierre Sep 8, 2023

Choose a reason for hiding this comment

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

But it would have been caught easily by QA which we do on every release.

The goal of the "acceptance" tests is to catch these things before live QA. It is inefficient to catch these kind of bugs during live QA on a testnet. Doesn't mean we will catch everything in those tests, but it does reduce the need for subsequent fixes/releases after bugs are found during live testing.

My typescript philosophy knowledge is admittedly limited and I don't know what specifically the "acceptance" tests would entail and what it would require from the codebase to be set up, but having everything tested with mocks limits the breadth of testing and bugs that we can find in tests - who's testing the mocks is essentially the argument.

"Acceptance" tests is a broad term, and maybe there is more appropriate term here, but we should investigate how we can perform tests closer to what the actual testnet/production environment would be.

Copy link
Contributor Author

@piotr-roslaniec piotr-roslaniec Sep 8, 2023

Choose a reason for hiding this comment

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

I understand the advantages of acceptance testing, I just don't think they are necessary at this point. We should probably get them before the release, but not until we're done with the monorepo or adapting viem: #271

That being said, I'd be happy to accept a PR that implements acceptance testing if anyone wants to chip in.

Copy link
Member

Choose a reason for hiding this comment

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

Definitely not something needed for this PR or this instant - but something we should nonetheless investigate. Filed #295 .

aggregationMismatch: boolean;
accessController: string;
publicKey: BLS12381.G1PointStructOutput;
aggregatedTranscript: string;
}
Copy link
Member

Choose a reason for hiding this comment

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

Are participants not stored in this struct? I guess maybe not needed...?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The contents of this struct are taken from types generated from contracts by typechain. I can trim them down to a size.

const decrypter = ThresholdDecrypter.create(
porterUri,
dkgRitual.id,
dkgRitual.dkgParams.threshold
Copy link
Member

Choose a reason for hiding this comment

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

Is threshold still needed, even though it is now part of the ritual struct?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The client needs to know how many shares to fetch from the nodes (/cbd_decrypt responses)

Copy link
Member

Choose a reason for hiding this comment

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

Yes, but now if you have the ritual id, you can get the value of the threshold from the Coordinator agent when doing the retrieve, or am I misunderstanding.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Member

Choose a reason for hiding this comment

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

Right 👍 . I mixed up my layers.

Side question: any reason we need the DkgRitualParameters object? This line could look nice as:

    const decrypter = ThresholdDecrypter.create(
      porterUri,
      dkgRitual.id,
      dkgRitual.threshold

? Anyways, just something to think about.

return await encryptLight(message, condition, dkgRitual.dkgPublicKey);
};

export const encryptLight = async (
Copy link
Member

Choose a reason for hiding this comment

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

Not sure how I feel about Light as the term 😅 . Can this just be an overloaded function with the same name?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There is no support function overloading in JS/TS. I didn't have better ideas for an appropriate name, maybe we could use the blockchainy naming from the original TACo API issue.

Copy link
Member

Choose a reason for hiding this comment

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

^ cc @cygnusv , @KPrasch, @jMyles (naming things).

Copy link
Member

Choose a reason for hiding this comment

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

I don't have a good name for it, but I would prefer something like

export const encryptWithDKG = async (

than the original one

test/unit/conditions/context.test.ts Show resolved Hide resolved
test/unit/conditions/context.test.ts Show resolved Hide resolved
@derekpierre derekpierre dismissed their stale review September 8, 2023 16:43

TacoMessageKit was removed.

test/unit/conditions/context.test.ts Outdated Show resolved Hide resolved
test/unit/conditions/context.test.ts Outdated Show resolved Hide resolved
Copy link
Member

@manumonti manumonti left a comment

Choose a reason for hiding this comment

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

LGTM. Great work! 👏

return encrypter.encryptMessageCbd(toBytes(message), conditionExpr);
};

export const decrypt = async (
Copy link
Member

Choose a reason for hiding this comment

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

This simplicity is great!

Copy link
Member

@derekpierre derekpierre left a comment

Choose a reason for hiding this comment

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

🎸 - nice work

@piotr-roslaniec piotr-roslaniec merged commit ca9e163 into alpha Sep 12, 2023
10 of 12 checks passed
@piotr-roslaniec piotr-roslaniec deleted the taco-api branch September 12, 2023 13:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Completed
Development

Successfully merging this pull request may close these issues.

5 participants