Skip to content

Commit e193ca9

Browse files
committed
bytes32 salt for deterministic deployment
1 parent 942d20a commit e193ca9

File tree

4 files changed

+16
-5
lines changed

4 files changed

+16
-5
lines changed

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { type Hex, encodePacked } from "viem";
22
import { getAddress } from "../address.js";
33
import { ensureBytecodePrefix } from "../bytecode/prefix.js";
4+
import { isHex } from "../encoding/hex.js";
45
import { keccak256 } from "../hashing/keccak256.js";
56
import { getSaltHash } from "./get-salt-hash.js";
67
import { keccakId } from "./keccak-id.js";
@@ -33,7 +34,9 @@ export function computeDeploymentAddress(
3334
) {
3435
const bytecode = ensureBytecodePrefix(options.bytecode);
3536
const saltHash = options.salt
36-
? keccakId(options.salt)
37+
? isHex(options.salt) && options.salt.length === 66
38+
? options.salt
39+
: keccakId(options.salt)
3740
: getSaltHash(bytecode);
3841

3942
// 1. create init bytecode hash with contract's bytecode and encoded args

packages/thirdweb/src/utils/any-evm/compute-published-contract-deploy-info.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,5 +96,6 @@ export async function computeDeploymentInfoFromBytecode(args: {
9696
initBytecodeWithsalt,
9797
encodedArgs,
9898
create2FactoryAddress,
99+
salt,
99100
};
100101
}

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { encodePacked } from "viem/utils";
22
import { ensureBytecodePrefix } from "../bytecode/prefix.js";
3-
import { type Hex, uint8ArrayToHex } from "../encoding/hex.js";
3+
import { type Hex, isHex, uint8ArrayToHex } from "../encoding/hex.js";
44
import { getSaltHash } from "./get-salt-hash.js";
55
import { keccakId } from "./keccak-id.js";
66

@@ -29,8 +29,11 @@ export function getInitBytecodeWithSalt(
2929
options: GetInitiBytecodeWithSaltOptions,
3030
): Hex {
3131
const bytecode = ensureBytecodePrefix(options.bytecode);
32+
3233
const saltHash = options.salt
33-
? keccakId(options.salt)
34+
? isHex(options.salt) && options.salt.length === 66
35+
? options.salt
36+
: keccakId(options.salt)
3437
: getSaltHash(bytecode);
3538

3639
const encodedArgs =

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type { Address } from "../../address.js";
2-
import type { Hex } from "../../encoding/hex.js";
2+
import { type Hex, isHex } from "../../encoding/hex.js";
33
import { keccakId } from "../keccak-id.js";
44
import { create2Address } from "./create2Address.js";
55

@@ -13,7 +13,11 @@ type ComputeDeploymentAddressOptions = {
1313
export function computeDeploymentAddress(
1414
options: ComputeDeploymentAddressOptions,
1515
) {
16-
const saltHash = options.salt ? keccakId(options.salt) : keccakId("thirdweb");
16+
const saltHash = options.salt
17+
? isHex(options.salt) && options.salt.length === 66
18+
? options.salt
19+
: keccakId(options.salt)
20+
: keccakId("thirdweb");
1721

1822
return create2Address({
1923
sender: options.create2FactoryAddress,

0 commit comments

Comments
 (0)