Skip to content

Commit

Permalink
fix() correct the way we fetch blockchain public key for CLI
Browse files Browse the repository at this point in the history
  • Loading branch information
immortal-tofu committed Jan 31, 2024
1 parent 199d8c7 commit 75c0062
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions bin/fhevm.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
#!/usr/bin/env node
'use strict';

import { JsonRpcProvider } from 'ethers';
import { JsonRpcProvider, AbiCoder } from 'ethers';
import { program } from 'commander';
import { toHexString, prependHttps, throwError } from './utils.js';
import { createInstance } from '../lib/node.cjs';

const FHE_LIB_ADDRESS = '0x000000000000000000000000000000000000005d';

let _instance;
const getInstance = async (provider) => {
if (_instance) return _instance;
Expand All @@ -18,14 +20,15 @@ const getInstance = async (provider) => {
throwError('Network is unreachable');
}
const chainId = +network.chainId.toString();

// Get blockchain public key
const publicKey = await provider.call({
to: '0x0000000000000000000000000000000000000044',
const ret = await provider.call({
to: FHE_LIB_ADDRESS,
// first four bytes of keccak256('fhePubKey(bytes1)') + 1 byte for library
data: '0xd9d47bb001',
});
const decoded = AbiCoder.defaultAbiCoder().decode(['bytes'], ret);
const publicKey = decoded[0];
_instance = await createInstance({ chainId, publicKey });

// Create instance
_instance = createInstance({ chainId, publicKey });
return _instance;
};

Expand Down

0 comments on commit 75c0062

Please sign in to comment.