-
Notifications
You must be signed in to change notification settings - Fork 83
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #658 from zama-ai/custom-errors-tfhe
refactor: add custom errors for TFHE
- Loading branch information
Showing
4 changed files
with
137 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
// SPDX-License-Identifier: BSD-3-Clause-Clear | ||
pragma solidity ^0.8.24; | ||
|
||
import "../../lib/TFHE.sol"; | ||
import "../FHEVMConfig.sol"; | ||
|
||
contract TFHERevertTest { | ||
constructor() { | ||
TFHE.setFHEVM(FHEVMConfig.defaultConfig()); | ||
} | ||
|
||
function padToBytes64(bytes memory input) public pure { | ||
TFHE.padToBytes64(input); | ||
} | ||
|
||
function padToBytes128(bytes memory input) public pure { | ||
TFHE.padToBytes128(input); | ||
} | ||
|
||
function padToBytes256(bytes memory input) public pure { | ||
TFHE.padToBytes256(input); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import { expect } from 'chai'; | ||
import { randomBytes } from 'crypto'; | ||
import { ethers } from 'hardhat'; | ||
|
||
import { getSigners, initSigners } from '../signers'; | ||
|
||
describe('TFHE revert paths', function () { | ||
before(async function () { | ||
await initSigners(1); | ||
this.signers = await getSigners(); | ||
|
||
const contractFactory = await ethers.getContractFactory('TFHERevertTest'); | ||
const contract = await contractFactory.connect(this.signers.alice).deploy(); | ||
await contract.waitForDeployment(); | ||
|
||
this.contract = contract; | ||
}); | ||
|
||
it('padToBytes64 reverts if input > 64 bytes', async function () { | ||
const numberBytes = 65; | ||
const input = randomBytes(numberBytes); | ||
|
||
await expect(this.contract.padToBytes64(input)) | ||
.to.be.revertedWithCustomError(this.contract, 'InputLengthAbove64Bytes') | ||
.withArgs(numberBytes); | ||
}); | ||
|
||
it('padToBytes128 reverts if input > 128 bytes', async function () { | ||
const numberBytes = 129; | ||
const input = randomBytes(numberBytes); | ||
|
||
await expect(this.contract.padToBytes128(input)) | ||
.to.be.revertedWithCustomError(this.contract, 'InputLengthAbove128Bytes') | ||
.withArgs(numberBytes); | ||
}); | ||
|
||
it('padToBytes256 reverts if input > 256 bytes', async function () { | ||
const numberBytes = 257; | ||
const input = randomBytes(numberBytes); | ||
|
||
await expect(this.contract.padToBytes256(input)) | ||
.to.be.revertedWithCustomError(this.contract, 'InputLengthAbove256Bytes') | ||
.withArgs(numberBytes); | ||
}); | ||
}); |