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

Gas misspricing between CMUX+COMPARISON vs MAX/MIN #69

Open
jatZama opened this issue Jan 26, 2024 · 1 comment
Open

Gas misspricing between CMUX+COMPARISON vs MAX/MIN #69

jatZama opened this issue Jan 26, 2024 · 1 comment
Assignees

Comments

@jatZama
Copy link
Member

jatZama commented Jan 26, 2024

I noticed from the documentation that cmux cost + comparison operator cost was lesser than TFHE.max and TFHE.min which does not make sense.
I have just confirmed with a simple experiment on Remix using this contract :

contract CmuxComp {
    uint32 public maximum;
    constructor() {}
    function cmuxcomp(uint32 x, uint32 y) external {
        euint32 xx = TFHE.asEuint32(x);
        euint32 yy = TFHE.asEuint32(y);
        ebool comp = TFHE.gt(xx,yy);
        euint32 maxx = TFHE.cmux(comp,xx,yy);
        maximum = TFHE.decrypt(maxx);
    }
    function max(uint32 x, uint32 y) external {
        euint32 xx = TFHE.asEuint32(x);
        euint32 yy = TFHE.asEuint32(y);
        euint32 maxx = TFHE.max(xx,yy);
        maximum = TFHE.decrypt(maxx);
    }
}

Calling max here costs me almost 25% more than calling cmuxcomp which shows that we have either :
1/ Misspriced the fhevm operators in gas .
2/ Found a bug or an inefficiency in tfhe-rs library

@immortal-tofu
Copy link
Contributor

Maybe simply reduce the price by 2 on release/0.1.x branch

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

No branches or pull requests

4 participants