
Security News
vlt Launches "reproduce": A New Tool Challenging the Limits of Package Provenance
vlt's new "reproduce" tool verifies npm packages against their source code, outperforming traditional provenance adoption in the JavaScript ecosystem.
@primitivefi/hardhat-marmite
Advanced tools
Flexible Hardhat plugin to run gas cost comparisons among different Solidity code snippets
Flexible Hardhat plugin to run gas cost comparisons among different Solidity code snippets.
PUT LIVE EXAMPLE HERE
First thing to do is to install the plugin in your Hardhat project:
# Using yarn
yarn add @primitivefi/hardhat-marmite
# Or using npm
npm i @primitivefi/hardhat-marmite
Next step is simply to include the plugin into your hardhat.config.js
or hardhat.config.ts
file:
// Using JavaScript
require('@primitivefi/hardhat-marmite');
// Using ES6 or TypeScript
import '@primitivefi/hardhat-marmite';
Marmite is extremely simple to use and only requires you to perform a couple of steps:
"Implementations" are referring to the snippets of Solidity code that you want to compare. They are declared using the following tags @start:Name-of-your-implementation
and @end
.
Let's say that you want to know if it's cheaper to check if a variable is "different from 0" or "higher than 0", inside of your Solidity contract, you can write:
// SPDX-License-Identifier: WTFPL
pragma solidity 0.8.9;
contract Foo {
uint256 public bar;
function set(uint256 newBar) external {
// Declaring our first implementation
@start:Different-from
if (newBar != 0) {
bar = newBar;
}
@end
// Declaring our second implementation
@start:Greater-than
if (newBar > 0) {
bar = newBar;
}
@end
}
}
The last step is simply to write your deployment script and to tell Marmite what it should compare. You can do that by:
marmite
context function from the @primitivefi/hardhat-marmite
packagehre
object, the name of your different implementations in an array and a function deploying your contractsflag
function to signal the transactions you want to Marmite to track measureimport hre, { ethers } from 'hardhat';
import { ContractTransaction } from 'ethers';
// Imports the `marmite` context function
import marmite from '@primitivefi/hardhat-marmite';
async function main() {
await marmite(
// Passes the global `hre` Hardhat object to Marmite
hre,
// Declares your different implementations
['Different-from', 'Greater-than'],
// Deployment function
async (flag) => {
// Deploys the contract `Foo`
const Foo = await ethers.getContractFactory('Foo');
const foo = await Foo.deploy();
// Calls the function `set` from the `Foo` contract
const tx = await foo.set(42) as ContractTransaction;
// Flags the transaction
await flag('set', tx);
},
);
}
main()
.then(() => process.exit(0))
.catch((error) => {
console.error(error);
process.exit(1);
});
Now that everything is set up, you can run Marmite in your terminal with:
npx hardhat marmite --script ./yourScript.js
Marmite will then compile your contracts, deploy them and measure your flagged transactions using all your different implementations. Once finished, you'll get the following table with the results:
Feel free to open an issue if you need help or if you encounter a problem! Here are some already known problems though:
constructor
might create a JavaScript issue, thus avoid writing await flag('constructor', tx);
for nowFAQs
Hassle-free Hardhat plugin to compare gas cost among different Solidity code snippets
The npm package @primitivefi/hardhat-marmite receives a total of 15 weekly downloads. As such, @primitivefi/hardhat-marmite popularity was classified as not popular.
We found that @primitivefi/hardhat-marmite demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 3 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
vlt's new "reproduce" tool verifies npm packages against their source code, outperforming traditional provenance adoption in the JavaScript ecosystem.
Research
Security News
Socket researchers uncovered a malicious PyPI package exploiting Deezer’s API to enable coordinated music piracy through API abuse and C2 server control.
Research
The Socket Research Team discovered a malicious npm package, '@ton-wallet/create', stealing cryptocurrency wallet keys from developers and users in the TON ecosystem.