1
0
Fork 0
mirror of synced 2025-09-24 04:40:05 +00:00

Link library properly in integration tests

This commit is contained in:
Leo Alt 2021-07-16 12:50:51 +02:00
parent 4e290c77a3
commit 034fbaf080

View file

@ -6,9 +6,8 @@ const proofPath = process.argv[3]
const format = process.argv[4]
const web3 = new Web3(new Web3.providers.HttpProvider('http://localhost:8545'));
// -----Compile contract-----
const source = fs.readFileSync(contractPath, 'UTF-8');
let jsonContractSource = JSON.stringify({
let jsonContractSource = {
language: 'Solidity',
sources: {
[contractPath]: {
@ -20,29 +19,36 @@ let jsonContractSource = JSON.stringify({
enabled: true
},
outputSelection: {
'*': {
'*': ['abi', "evm.bytecode"],
[contractPath]: {
"Verifier": ['abi', "evm.bytecode"],
},
},
},
});
};
let jsonInterface = JSON.parse(solc.compile(jsonContractSource));
console.log(jsonInterface);
(async () => {
const accounts = await web3.eth.getAccounts();
let abi = jsonInterface.contracts[contractPath]["Verifier"].abi;
let bytecode = jsonInterface.contracts[contractPath]["Verifier"].evm.bytecode;
//There is a solc issue, that for unknown reasons wont link the BN256G2 Library automatically for gm17 v1 and v2 contracts. I dont know why this is happening,
//the contracts compile and deploy without any issue on remix. To fix this, the the BN256G2 Library must be compiled and deployed by itself, after that,
//the library placeholder must be replaced with the library address in the contracts bytecode
// The BN256G2 library needs to be deployed and linked separately
// because it has `public` functions.
// This is not needed for the Pairing library because all its functions
// are `internal` and therefore are compiled into the contract that uses it.
if (format == "gm17") {
let library = await deployLibrary();
//replace lib placeholder with lib address in bytecode
bytecode.object = bytecode.object.replace(/\_\_\$[a-f0-9]{34}\$\_\_/g, library["_address"].replace("0x", ""));
jsonContractSource.settings.libraries = {
[contractPath]: {
BN256G2: library["_address"]
}
}
}
// -----Compile contract-----
let jsonInterface = JSON.parse(solc.compile(JSON.stringify(jsonContractSource)));
console.log(jsonInterface);
let abi = jsonInterface.contracts[contractPath]["Verifier"].abi;
let bytecode = jsonInterface.contracts[contractPath]["Verifier"].evm.bytecode;
let contract = new web3.eth.Contract(abi)
.deploy({
data: '0x' + bytecode.object
@ -123,6 +129,9 @@ console.log(jsonInterface);
},
},
settings: {
optimizer: {
enabled: true
},
outputSelection: {
'*': {
'*': ['abi', "evm.bytecode"],