Skip to content
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
5 changes: 5 additions & 0 deletions .changeset/popular-ligers-taste.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"thirdweb": patch
---

bytes32 salt for deterministic deployment
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { type Hex, encodePacked } from "viem";
import { getAddress } from "../address.js";
import { ensureBytecodePrefix } from "../bytecode/prefix.js";
import { isHex } from "../encoding/hex.js";
import { keccak256 } from "../hashing/keccak256.js";
import { getSaltHash } from "./get-salt-hash.js";
import { keccakId } from "./keccak-id.js";
Expand Down Expand Up @@ -33,7 +34,9 @@
) {
const bytecode = ensureBytecodePrefix(options.bytecode);
const saltHash = options.salt
? keccakId(options.salt)
? isHex(options.salt) && options.salt.length === 66
? options.salt

Check warning on line 38 in packages/thirdweb/src/utils/any-evm/compute-deployment-address.ts

View check run for this annotation

Codecov / codecov/patch

packages/thirdweb/src/utils/any-evm/compute-deployment-address.ts#L38

Added line #L38 was not covered by tests
: keccakId(options.salt)
: getSaltHash(bytecode);

// 1. create init bytecode hash with contract's bytecode and encoded args
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,5 +96,6 @@ export async function computeDeploymentInfoFromBytecode(args: {
initBytecodeWithsalt,
encodedArgs,
create2FactoryAddress,
salt,
};
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { encodePacked } from "viem/utils";
import { ensureBytecodePrefix } from "../bytecode/prefix.js";
import { type Hex, uint8ArrayToHex } from "../encoding/hex.js";
import { type Hex, isHex, uint8ArrayToHex } from "../encoding/hex.js";
import { getSaltHash } from "./get-salt-hash.js";
import { keccakId } from "./keccak-id.js";

Expand Down Expand Up @@ -29,8 +29,11 @@
options: GetInitiBytecodeWithSaltOptions,
): Hex {
const bytecode = ensureBytecodePrefix(options.bytecode);

const saltHash = options.salt
? keccakId(options.salt)
? isHex(options.salt) && options.salt.length === 66
? options.salt

Check warning on line 35 in packages/thirdweb/src/utils/any-evm/get-init-bytecode-with-salt.ts

View check run for this annotation

Codecov / codecov/patch

packages/thirdweb/src/utils/any-evm/get-init-bytecode-with-salt.ts#L35

Added line #L35 was not covered by tests
: keccakId(options.salt)
: getSaltHash(bytecode);

const encodedArgs =
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { Address } from "../../address.js";
import type { Hex } from "../../encoding/hex.js";
import { type Hex, isHex } from "../../encoding/hex.js";
import { keccakId } from "../keccak-id.js";
import { create2Address } from "./create2Address.js";

Expand All @@ -13,7 +13,11 @@
export function computeDeploymentAddress(
options: ComputeDeploymentAddressOptions,
) {
const saltHash = options.salt ? keccakId(options.salt) : keccakId("thirdweb");
const saltHash = options.salt
? isHex(options.salt) && options.salt.length === 66
? options.salt
: keccakId(options.salt)

Check warning on line 19 in packages/thirdweb/src/utils/any-evm/zksync/computeDeploymentAddress.ts

View check run for this annotation

Codecov / codecov/patch

packages/thirdweb/src/utils/any-evm/zksync/computeDeploymentAddress.ts#L17-L19

Added lines #L17 - L19 were not covered by tests
: keccakId("thirdweb");

return create2Address({
sender: options.create2FactoryAddress,
Expand Down
Loading