Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

micro-eth-signer issue when deploying local accounts #6017

Merged
merged 5 commits into from
Dec 9, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 37 additions & 12 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 8 additions & 1 deletion v-next/hardhat-errors/src/descriptors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ Please double check whether you have multiple versions of the same plugin instal
ENV_VAR_NOT_FOUND: {
number: 7,
messageTemplate: `Configuration Variable '{name}' not found.

You can define it using a plugin like hardhat-keystore, or set it as an environment variable.`,
websiteTitle: "Configuration variable not found",
websiteDescription: `A configuration variable was expected to be set as an environment variable, but it wasn't.`,
Expand Down Expand Up @@ -678,6 +678,13 @@ Try using another mnemonic or deriving less keys.`,
websiteTitle: "Invalid network type",
websiteDescription: `The network manager only supports the network types 'http' and 'edr'.`,
},
DATA_FIELD_CANNOT_BE_NULL_WITH_NULL_ADDRESS: {
number: 721,
messageTemplate: `The "to" field is undefined, and the "data" field is also undefined; however, a transaction to the null address cannot have an undefined "data" field.`,
websiteTitle: "Transaction to null address cannot have undefined data",
websiteDescription:
"The transaction to the null address cannot have undefined data",
},
},
KEYSTORE: {
INVALID_KEYSTORE_FILE_FORMAT: {
Expand Down
2 changes: 1 addition & 1 deletion v-next/hardhat/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@
"debug": "^4.1.1",
"enquirer": "^2.3.0",
"ethereum-cryptography": "^2.2.1",
"micro-eth-signer": "^0.12.0",
"micro-eth-signer": "^0.13.0",
"p-map": "^7.0.2",
"semver": "^7.6.3",
"solc": "^0.8.27",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -276,15 +276,22 @@ export class LocalAccountsHandler extends ChainId implements RequestHandler {
};
});

// TODO: Fix after the alpha release
ChristopherDedominici marked this conversation as resolved.
Show resolved Hide resolved
assertHardhatInvariant(
txData.to !== undefined,
"The alpha version doesn't support deploying contracts with local accounts yet",
);
if (txData.to === undefined && txData.data === undefined) {
throw new HardhatError(
HardhatError.ERRORS.NETWORK.DATA_FIELD_CANNOT_BE_NULL_WITH_NULL_ADDRESS,
);
}

const checksummedAddress = addr.addChecksum(
bytesToHexString(txData.to).toLowerCase(),
);
let checksummedAddress;
if (txData.to === undefined) {
// This scenario arises during contract deployment. The npm package "micro-eth-signer" does not support
// undefined addresses. Therefore, these values must be converted to "0x", the expected format.
checksummedAddress = "0x";
} else {
checksummedAddress = addr.addChecksum(
bytesToHexString(txData.to).toLowerCase(),
);
}

assertHardhatInvariant(
txData.nonce !== undefined,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -451,6 +451,62 @@ describe("LocalAccountsHandler", () => {
});

describe("modifyRequest", () => {
describe("sending transactions to the null address", () => {
it("should succeed when the data field is not empty", async () => {
const tx = {
// null address: the "to" field is not required
ChristopherDedominici marked this conversation as resolved.
Show resolved Hide resolved
from: "0xb5bc06d4548a3ac17d72b372ae1e416bf65b8ead",
gas: numberToHexString(30000),
nonce: numberToHexString(0),
value: numberToHexString(1),
chainId: numberToHexString(MOCK_PROVIDER_CHAIN_ID),
maxFeePerGas: numberToHexString(12),
maxPriorityFeePerGas: numberToHexString(2),
data: "0x01",
};

const jsonRpcRequest = getJsonRpcRequest(1, "eth_sendTransaction", [
tx,
]);

await localAccountsHandler.handle(jsonRpcRequest);

assert.ok(
Array.isArray(jsonRpcRequest.params),
"params should be an array",
);

const rawTransaction = hexStringToBytes(jsonRpcRequest.params[0]);
// The tx type is encoded in the first byte, and it must be the EIP-1559 one
assert.equal(rawTransaction[0], 2);
});

it("should throw when the data field is undefined", async () => {
const tx = {
// null address: the "to" field is not required.
// Also, in this test scenario, the "data" field is omitted
from: "0xb5bc06d4548a3ac17d72b372ae1e416bf65b8ead",
gas: numberToHexString(30000),
nonce: numberToHexString(0),
value: numberToHexString(1),
chainId: numberToHexString(MOCK_PROVIDER_CHAIN_ID),
maxFeePerGas: numberToHexString(12),
maxPriorityFeePerGas: numberToHexString(2),
};

const jsonRpcRequest = getJsonRpcRequest(1, "eth_sendTransaction", [
tx,
]);

assertRejectsWithHardhatError(
() => localAccountsHandler.handle(jsonRpcRequest),
HardhatError.ERRORS.NETWORK
.DATA_FIELD_CANNOT_BE_NULL_WITH_NULL_ADDRESS,
{},
);
});
});

it("should, given two identical tx, return the same raw transaction", async () => {
const jsonRpcRequest = getJsonRpcRequest(1, "eth_sendTransaction", [
{
Expand Down
Loading