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

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

@jatZama

Description

@jatZama

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

Metadata

Metadata

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions