mirror of
https://github.com/zama-ai/fhevm-solidity.git
synced 2026-01-08 20:18:02 -05:00
* feat: use latest core contracts, updated lib API, renamed to fhevm and fhe chore: add dummy addresses for CI test: add tests for makePubliclyDecryptable method * chore: update package-lock.json for linux * chore: update package-lock.json * fix: solidity comments (#746) * chore: update oracle version * chore: update fhevm core-contracts version * feat: update fhevm sdk and mocked userDecrypt * chore: fix coverage
58 lines
2.3 KiB
TypeScript
58 lines
2.3 KiB
TypeScript
import dotenv from 'dotenv';
|
|
import { ethers } from 'ethers';
|
|
import * as fs from 'fs';
|
|
import { ProviderWrapper } from 'hardhat/plugins';
|
|
|
|
class CustomProvider extends ProviderWrapper {
|
|
public lastBlockSnapshot: number;
|
|
public lastCounterRand: number;
|
|
public lastBlockSnapshotForDecrypt: number;
|
|
|
|
constructor(protected readonly _wrappedProvider: any) {
|
|
super(_wrappedProvider);
|
|
this.lastBlockSnapshot = 0; // Initialize the variable
|
|
this.lastCounterRand = 0;
|
|
this.lastBlockSnapshotForDecrypt = 0;
|
|
}
|
|
|
|
async request(args: { method: string; params?: any[] }) {
|
|
if (args.method === 'eth_estimateGas') {
|
|
const estimatedGasLimit = BigInt(await this._wrappedProvider.request(args));
|
|
const increasedGasLimit = ethers.toBeHex((estimatedGasLimit * 120n) / 100n); // override estimated gasLimit by 120%, to avoid some edge case with ethermint gas estimation
|
|
return increasedGasLimit;
|
|
}
|
|
if (args.method === 'evm_revert') {
|
|
const result = await this._wrappedProvider.request(args);
|
|
const blockNumberHex = await this._wrappedProvider.request({ method: 'eth_blockNumber' });
|
|
this.lastBlockSnapshot = parseInt(blockNumberHex);
|
|
this.lastBlockSnapshotForDecrypt = parseInt(blockNumberHex);
|
|
const coprocAdd = dotenv.parse(
|
|
fs.readFileSync(require.resolve('./fhevmTemp/addresses/.env.exec')),
|
|
).FHEVM_EXECUTOR_CONTRACT_ADDRESS;
|
|
this.lastCounterRand = await this._wrappedProvider.request({
|
|
method: 'eth_getStorageAt',
|
|
params: [coprocAdd, '0xa436a06f0efce5ea38c956a21e24202a59b3b746d48a23fb52b4a5bc33fe3e00', 'latest'],
|
|
});
|
|
return result;
|
|
}
|
|
if (args.method === 'get_lastBlockSnapshot') {
|
|
return [this.lastBlockSnapshot, this.lastCounterRand];
|
|
}
|
|
if (args.method === 'get_lastBlockSnapshotForDecrypt') {
|
|
return this.lastBlockSnapshotForDecrypt;
|
|
}
|
|
if (args.method === 'set_lastBlockSnapshot') {
|
|
this.lastBlockSnapshot = args.params![0];
|
|
return this.lastBlockSnapshot;
|
|
}
|
|
if (args.method === 'set_lastBlockSnapshotForDecrypt') {
|
|
this.lastBlockSnapshotForDecrypt = args.params![0];
|
|
return this.lastBlockSnapshotForDecrypt;
|
|
}
|
|
const result = this._wrappedProvider.request(args);
|
|
return result;
|
|
}
|
|
}
|
|
|
|
export default CustomProvider;
|