-
Notifications
You must be signed in to change notification settings - Fork 196
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
fix(common): kms correctly serializes transactions #2721
Conversation
|
Name | Type |
---|---|
@latticexyz/common | Patch |
@latticexyz/block-logs-stream | Patch |
@latticexyz/cli | Patch |
@latticexyz/config | Patch |
@latticexyz/dev-tools | Patch |
@latticexyz/faucet | Patch |
@latticexyz/protocol-parser | Patch |
@latticexyz/query | Patch |
@latticexyz/store-indexer | Patch |
@latticexyz/store-sync | Patch |
@latticexyz/store | Patch |
@latticexyz/world-modules | Patch |
@latticexyz/world | Patch |
mock-game-contracts | Patch |
@latticexyz/react | Patch |
@latticexyz/abi-ts | Patch |
create-mud | Patch |
@latticexyz/gas-report | Patch |
@latticexyz/recs | Patch |
@latticexyz/schema-type | Patch |
@latticexyz/services | Patch |
solhint-config-mud | Patch |
solhint-plugin-mud | Patch |
@latticexyz/utils | Patch |
Click here to learn what changesets are, and how to add one.
Click here if you're a maintainer who wants to add a changeset to this PR
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type | ||
const signableTransaction = (() => { | ||
// For EIP-4844 Transactions, we want to sign the transaction payload body (tx_payload_body) without the sidecars (ie. without the network wrapper). | ||
// See: https://github.com/ethereum/EIPs/blob/e00f4daa66bd56e2dbd5f1d36d09fd613811a48b/EIPS/eip-4844.md#networking | ||
if (transaction.type === "eip4844") | ||
return { | ||
...transaction, | ||
sidecars: false, | ||
}; | ||
return transaction; | ||
})(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ooc why this and not
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type | |
const signableTransaction = (() => { | |
// For EIP-4844 Transactions, we want to sign the transaction payload body (tx_payload_body) without the sidecars (ie. without the network wrapper). | |
// See: https://github.com/ethereum/EIPs/blob/e00f4daa66bd56e2dbd5f1d36d09fd613811a48b/EIPS/eip-4844.md#networking | |
if (transaction.type === "eip4844") | |
return { | |
...transaction, | |
sidecars: false, | |
}; | |
return transaction; | |
})(); | |
// For EIP-4844 Transactions, we want to sign the transaction payload body (tx_payload_body) without the sidecars (ie. without the network wrapper). | |
// See: https://github.com/ethereum/EIPs/blob/e00f4daa66bd56e2dbd5f1d36d09fd613811a48b/EIPS/eip-4844.md#networking | |
const signableTransaction = transaction.type === "eip4844" ? { ...transaction, sidecars: false } : transaction; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Copied verbatim from the Viem function! It could be more encapsulated imo: https://github.com/wevm/viem/blob/main/src/accounts/utils/signTransaction.ts#L53-L62
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ahh got it!
maybe worth a note above about keeping this logic aligned with viem internals?
address, | ||
}); | ||
|
||
return signature; | ||
return serializer(transaction, signature); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just to confirm, we don't want to use signableTransaction
here?
I see now we're following viem
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nope, again this is from viem. I think it's because the data you sign should (or shouldn't, idk) include some fields that are in the full transaction data.
import { signWithKms } from "./signWithKms"; | ||
import { getAddressFromKms } from "./getAddressFromKms"; | ||
|
||
export type kmsKeyToAccountOptions = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
export type kmsKeyToAccountOptions = { | |
export type KmsKeyToAccountOptions = { |
packages/common/src/exports/kms.ts
Outdated
@@ -1 +1 @@ | |||
export { createKmsAccount, type CreateKmsAccountOptions, type KMSAccount } from "../account/kms/createKmsAccount"; | |||
export { kmsKeyToAccount, type kmsKeyToAccountOptions, type KMSAccount } from "../account/kms/kmsKeyToAddress"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
export { kmsKeyToAccount, type kmsKeyToAccountOptions, type KMSAccount } from "../account/kms/kmsKeyToAddress"; | |
export { KmsKeyToAccount, type kmsKeyToAccountOptions, type KmsAccount } from "../account/kms/kmsKeyToAddress"; |
client?: KMSClient; | ||
}; | ||
|
||
export type KMSAccount = LocalAccount<"aws-kms">; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
export type KMSAccount = LocalAccount<"aws-kms">; | |
export type KmsAccount = LocalAccount<"aws-kms">; |
export async function kmsKeyToAccount({ | ||
keyId, | ||
client = new KMSClient(), | ||
}: kmsKeyToAccountOptions): Promise<KMSAccount> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
}: kmsKeyToAccountOptions): Promise<KMSAccount> { | |
}: kmsKeyToAccountOptions): Promise<KmsAccount> { |
let balance = await getBalance(adminClient, { address: account.address }); | ||
expect(balance).toEqual(0n); | ||
|
||
let tx = await adminClient.sendTransaction({ to: account.address, value: parseEther("1") }); | ||
await waitForTransaction(tx); | ||
|
||
balance = await getBalance(adminClient, { address: account.address }); | ||
expect(balance).toEqual(1000000000000000000n); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we're using a mix of tree shakable and not-tree shakable actions, would be nice to consolidate (ideally on tree shakable)
and if we're doing all tree shakable, might make sense to just use createClient
not createWalletClient
const adminClient = createWalletClient({ | ||
chain: foundry, | ||
transport: http(anvilRpcUrl), | ||
account: privateKeyToAccount("0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80"), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
wanna make a note here about this being a default anvil user?
can also use testClient
to set balance of ~any account
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
testClient
would be more intuitive, the funding stuff is a means to an end
While testing the KMS deployer in #2704 I realised that it's transactions were rejected by the RPC because they were not serialised properly. This PR fixes the KMS account by more closely mirroring the Viem
signTransaction
logic.