bandada-infra / bandada

A system for managing privacy-preserving groups.
https://bandada.pse.dev
MIT License
64 stars 53 forks source link

Throw an error when trying to create a group with tree depth < 16 or > 32 #579

Open vplasencia opened 18 hours ago

vplasencia commented 18 hours ago

Description

The Bandada off-chain groups support tree depth >= 16 and <=32. It would be nice to add a check to the api sdk so that devs receive a clearer error when they try to create a group with a tree depth that is not supported.

The error could be: The tree depth must be between 16 and 32.

It would also be nice to return a better error message in the API when creating a group.

(Feedback from @sripwoud)

sanieni6 commented 15 hours ago

I am applying to this issue via OnlyDust platform.

My background and how it can be leveraged

Hi, there I am Luis Sanchez, a 3 years experienced FrontEnd dev, with some experience whitin the backend development (Nest.js and FastAPI). Glad to contribute!!!

How I plan on tackling this issue

This is my aproach to add the validation and throw the error:

async createGroup(
    groupCreationDetails: GroupCreationDetails,
    apiKey: string
): Promise<Group> {
    // Validate treeDepth
    if (groupCreationDetails.treeDepth < 16 || groupCreationDetails.treeDepth > 32) {
        throw new Error('The tree depth must be between 16 and 32.');
    }
    const groups = await this.createGroups(
        [groupCreationDetails],
        apiKey
    );

    return groups[0];
}
SIDHARTH20K4 commented 9 hours ago

I am applying to this issue via OnlyDust platform.

My background and how it can be leveraged

I would like to work on this issue could you assign this to me

How I plan on tackling this issue

?

Tchisom17 commented 6 hours ago

I am applying to this issue via OnlyDust platform.

My background and how it can be leveraged

I have experience working with Solidity for smart contract development and TypeScript for building backend and API services. In previous projects, I've dealt with validating user inputs, error handling, and integrating off-chain services with blockchain networks. My expertise in building decentralized applications (dApps) has equipped me with the ability to design clear and informative error messaging for APIs, ensuring developers have a smooth experience. This background enables me to contribute effectively to improving the Bandada API SDK by enforcing constraints and providing meaningful feedback to developers.

How I plan on tackling this issue

To address the issue of tree depth validation, I would start by updating the API SDK in TypeScript to include a check for the treeDepth parameter when a developer attempts to create a group. Before any API call is made, the SDK can validate that the provided treeDepth falls between 16 and 32. If the value is outside this range, I would throw an error with the message: "The tree depth must be between 16 and 32." This ensures that the developer receives immediate feedback, improving the user experience.

For the API side, I would modify the endpoint that handles group creation to return a more descriptive error message if an invalid treeDepth is provided. By performing the same validation server-side, we ensure consistency. If the value is outside the valid range, the API would respond with a 400 status code and the error message: "The tree depth must be between 16 and 32." This way, even if the SDK is bypassed, the API still enforces the rule effectively