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

native: The executor fails with BAD_INPUT_CIPHERTEXT error #209

Open
goshawk-3 opened this issue Dec 23, 2024 · 1 comment · May be fixed by #208
Open

native: The executor fails with BAD_INPUT_CIPHERTEXT error #209

goshawk-3 opened this issue Dec 23, 2024 · 1 comment · May be fixed by #208
Assignees
Labels
bug Something isn't working

Comments

@goshawk-3
Copy link
Contributor

Description

Upon running a simple fheAdd operation, the Executor always returns BAD_INPUT_CIPHERTEXT error.

function fheAdd(uint256 lhs, uint256 rhs) external virtual returns (uint256 result) {
        lhs = this.trivialEncrypt(lhs, 0x03);
        rhs = this.trivialEncrypt(rhs, 0x03);
        result = this.fheAdd(lhs, rhs, 0x00); 
    }

Log

DEBUG[12-23|11:38:31.187] Add operation                            fhevm=sync_compute     op=FHE_TRIVIAL_ENCRYPT handle=59b4f9..500300
DEBUG[12-23|11:38:31.187] Add operation                            fhevm=sync_compute     op=FHE_TRIVIAL_ENCRYPT handle=444e98..4c0300
DEBUG[12-23|11:38:31.187] Add operation                            fhevm=sync_compute     op=FHE_ADD             handle=ce2439..0e0300
INFO [12-23|11:38:31.187] Sending grpc request                     fhevm=sync_compute     computations=3 "compressed ciphertexts"=2
DEBUG[12-23|11:38:31.187] Request with compressed ciphertext       fhevm=sync_compute     handle=59b4f9..500300 "compCt len"=0
DEBUG[12-23|11:38:31.187] Request with compressed ciphertext       fhevm=sync_compute     handle=444e98..4c0300 "compCt len"=0
ERROR[12-23|11:38:31.188] Executor failed                          fhevm=commit           block=24 error=BAD_INPUT_CIPHERTEXT
@goshawk-3 goshawk-3 added the bug Something isn't working label Dec 23, 2024
@goshawk-3 goshawk-3 self-assigned this Dec 23, 2024
@goshawk-3
Copy link
Contributor Author

goshawk-3 commented Dec 23, 2024

Culprit:

Empty ciphertexts of the fheAdd operands are sent to the Executor.

Details

When any FHE operation is called with non-Scalar operands, the ciphertexts of the operands are hydrated from the EVM/Host state. However, if the operand handle is being computed prior to the FHE operation (as it's the case with the above example) then the ciphertexts cannot be hydrated. Therefore, no ciphertexts should be sent to the executor.

See also: 634ebc9

Log after the change

DEBUG[12-23|15:08:35.154] Add computation to Cache                 fhevm=evm_store        "commit block"=21 handle=59b4f9..500300 "cache length"=1
DEBUG[12-23|15:08:35.154] Add computation to Cache                 fhevm=evm_store        "commit block"=21 handle=444e98..4c0300 "cache length"=2
INFO [12-23|15:08:35.154] Hydrate computation                      fhevm=evm_store        handle=ce2439..0e0300 operand_handle=59b4f9..500300 "ciphertext len"=0
INFO [12-23|15:08:35.154] Hydrate computation                      fhevm=evm_store        handle=ce2439..0e0300 operand_handle=444e98..4c0300 "ciphertext len"=0
DEBUG[12-23|15:08:35.154] Add computation to Cache                 fhevm=evm_store        "commit block"=21 handle=ce2439..0e0300 "cache length"=3
DEBUG[12-23|15:08:35.154] Processing block                         fhevm=sync_compute     "commit block"=21 computations=3
DEBUG[12-23|15:08:35.154] Add operation                            fhevm=sync_compute     op=FHE_TRIVIAL_ENCRYPT handle=59b4f9..500300
DEBUG[12-23|15:08:35.154] Add operation                            fhevm=sync_compute     op=FHE_TRIVIAL_ENCRYPT handle=444e98..4c0300
DEBUG[12-23|15:08:35.154] Add operation                            fhevm=sync_compute     op=FHE_ADD             handle=ce2439..0e0300
INFO [12-23|15:08:35.154] Sending grpc request                     fhevm=sync_compute     computations=3 "compressed ciphertexts"=0
DEBUG[12-23|15:08:35.158] Computations completed                   fhevm=sync_compute     duration=3.667254ms
INFO [12-23|15:08:35.158] Response                                 fhevm=sync_compute     "ciphertexts count"=3
DEBUG[12-23|15:08:35.158] Response ciphertext                      fhevm=sync_compute     handle=59b4f9..500300 len=1866
DEBUG[12-23|15:08:35.158] Response ciphertext                      fhevm=sync_compute     handle=444e98..4c0300 len=1866
DEBUG[12-23|15:08:35.158] Response ciphertext                      fhevm=sync_compute     handle=ce2439..0e0300 len=1866
DEBUG[12-23|15:08:35.158] Flush ciphertexts                        fhevm=flush            "block number"=21 "count addr"=000000..000015 count=3
DEBUG[12-23|15:08:35.158] Reset computation LateCommit queue       fhevm=flush            "block number"=21 handle=59b4f9..500300
DEBUG[12-23|15:08:35.158] Reset computation LateCommit queue       fhevm=flush            "block number"=21 handle=444e98..4c0300
DEBUG[12-23|15:08:35.158] Reset computation LateCommit queue       fhevm=flush            "block number"=21 handle=ce2439..0e0300
DEBUG[12-23|15:08:35.158] Reset count addr                         fhevm=flush            "block number"=21 "count addr"=000000..000015 count=3
INFO [12-23|15:08:35.158] Persist ciphertext to state              fhevm=materialize      "block number"=21 handle=59b4f9..500300 "ciphertext length"=1866
INFO [12-23|15:08:35.158] Persist ciphertext to state              fhevm=materialize      "block number"=21 handle=444e98..4c0300 "ciphertext length"=1866
INFO [12-23|15:08:35.158] Persist ciphertext to state              fhevm=materialize      "block number"=21 handle=ce2439..0e0300 "ciphertext length"=1866

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant