@@ -29,43 +29,23 @@ import { WormholeContract } from "./wormhole";
2929
3030/**
3131 * Returns the keccak256 digest of the contract bytecode at the given address after replacing
32- * any occurrences of the contract addr in the bytecode with 0 and removing the metadata hash.
33- * The bytecode stores the deployment address as an immutable variable. This behavior is inherited
34- * from OpenZeppelin's implementation of UUPSUpgradeable contract. You can read more about
35- * verification with immutable variables here: https://docs.sourcify.dev/docs/immutables/
36- *
37- * The metadata hash (last 53 bytes) is removed to allow comparison of functional bytecode only,
38- * as metadata can differ between builds even when the contract logic is identical.
39- *
32+ * any occurrences of the contract addr in the bytecode with 0.The bytecode stores the deployment
33+ * address as an immutable variable. This behavior is inherited from OpenZeppelin's implementation
34+ * of UUPSUpgradeable contract. You can read more about verification with immutable variables here:
35+ * https://docs.sourcify.dev/docs/immutables/
4036 * This function can be used to verify that the contract code is the same on all chains and matches
41- * with the deployedCode property generated by truffle builds (excluding metadata).
37+ * with the deployedCode property generated by truffle builds
4238 */
4339export async function getCodeDigestWithoutAddress (
4440 web3 : Web3 ,
4541 address : string ,
4642) : Promise < string > {
4743 const code = await web3 . eth . getCode ( address ) ;
48- // Remove 0x prefix for processing
49- const codeWithoutPrefix = code . replace ( "0x" , "" ) ;
50-
51- // Strip address occurrences (40 hex chars = 20 bytes)
52- const strippedCode = codeWithoutPrefix . replaceAll (
44+ const strippedCode = code . replaceAll (
5345 address . toLowerCase ( ) . replace ( "0x" , "" ) ,
5446 "0000000000000000000000000000000000000000" ,
5547 ) ;
56-
57- // Remove metadata hash (last 53 bytes = 106 hex characters)
58- // Metadata format: 0xa2 0x64 'i' 'p' 'f' 's' 0x58 0x20 <32 bytes hash>
59- // Total: 53 bytes including CBOR encoding
60- // Only remove if bytecode is long enough (at least 106 hex chars = 53 bytes)
61- const METADATA_LENGTH_HEX = 106 ; // 53 bytes * 2 hex chars per byte
62- const functionalBytecode =
63- strippedCode . length > METADATA_LENGTH_HEX
64- ? strippedCode . slice ( 0 , - METADATA_LENGTH_HEX )
65- : strippedCode ;
66-
67- // Add 0x prefix back for keccak256
68- return Web3 . utils . keccak256 ( `0x${ functionalBytecode } ` ) ;
48+ return Web3 . utils . keccak256 ( strippedCode ) ;
6949}
7050
7151export class EvmWormholeContract extends WormholeContract {
@@ -1082,4 +1062,4 @@ export class EvmLazerContract extends Storable {
10821062 ) ;
10831063 console . log ( `Transaction hash: ${ tx . transactionHash } ` ) ;
10841064 }
1085- }
1065+ }
0 commit comments