Skip to content
This repository has been archived by the owner on Dec 23, 2024. It is now read-only.

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 subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants