From 9046637dbdafa311eef43a19177d4ae194ba713e Mon Sep 17 00:00:00 2001 From: huyhuynh3103 Date: Thu, 8 Jan 2026 11:41:51 +0700 Subject: [PATCH 1/2] Enhance artifact generation and validation in generate-artifact.sh; remove tracing in LibArtifact and LibDeploy --- generate-artifact.sh | 41 ++++++++++++++++++++++++++++++++ run.sh | 5 +--- script/libraries/LibArtifact.sol | 4 ---- script/libraries/LibDeploy.sol | 2 -- 4 files changed, 42 insertions(+), 10 deletions(-) diff --git a/generate-artifact.sh b/generate-artifact.sh index 5039f14..cfc8a1e 100755 --- a/generate-artifact.sh +++ b/generate-artifact.sh @@ -68,6 +68,8 @@ fi source_name=$(basename $absolute_path) # Remove .json or .sol extension source_name=${source_name%.*} +# +echo "source_name: $source_name" # Generate the artifact abi=$(forge inspect $source_name abi --json) @@ -78,6 +80,45 @@ storage_layout=$(forge inspect $source_name storageLayout --json) bytecode=$(forge inspect $source_name bytecode) deployed_bytecode=$(forge inspect $source_name deployedBytecode) +sanitize_json_field() { + local name="$1" + local value="$2" + + if [[ -z "$value" || "$value" == "null" ]]; then + echo "field $name is null" >&2 + echo "null" + return + fi + + # Ensure the value is valid JSON; fallback to null if not + if echo "$value" | jq -c . >/dev/null 2>&1; then + echo "$value" | jq -c . + else + echo "field $name is invalid JSON; defaulting to null" >&2 + echo "null" + fi +} + +sanitize_string_field() { + local name="$1" + local value="$2" + + if [[ -z "$value" || "$value" == "null" ]]; then + echo "field $name is null" >&2 + echo "" + else + echo "$value" + fi +} + +abi=$(sanitize_json_field "abi" "$abi") +devdoc=$(sanitize_json_field "devdoc" "$devdoc") +userdoc=$(sanitize_json_field "userdoc" "$userdoc") +metadata=$(sanitize_json_field "metadata" "$metadata") +storage_layout=$(sanitize_json_field "storage_layout" "$storage_layout") +bytecode=$(sanitize_string_field "bytecode" "$bytecode") +deployed_bytecode=$(sanitize_string_field "deployed_bytecode" "$deployed_bytecode") + # Create the JSON object json_content=$( jq -n \ diff --git a/run.sh b/run.sh index c6447f7..3225690 100755 --- a/run.sh +++ b/run.sh @@ -140,9 +140,6 @@ done export_address -echo "\033[33mTrying to compile contracts ...\033[0m" -forge build --offline # Ensure the contracts are compiled before running the script - should_verify=$([[ $should_verify == true && $is_broadcast == true ]] && echo true || echo false) if [[ $force_generate_artifact == true ]]; then @@ -199,7 +196,7 @@ fi start_time=$(date +%s) -${op_command} forge script --offline ${verify_arg} ${@} -g 200 --sig 'run(bytes,string)' $(cast calldata 'run()') "${extra_argument}" +${op_command} forge script --offline ${verify_arg} ${@} -g 200 --color always --sig 'run(bytes,string)' $(cast calldata 'run()') "${extra_argument}" if [ $? -ne 0 ]; then exit 1 diff --git a/script/libraries/LibArtifact.sol b/script/libraries/LibArtifact.sol index 0b9e4f0..f608295 100644 --- a/script/libraries/LibArtifact.sol +++ b/script/libraries/LibArtifact.sol @@ -47,15 +47,11 @@ library LibArtifact { console.log(string.concat("By: ", vm.getLabel(info.deployer), ", nonce: ", vm.toString(info.nonce), "\n")); - vm.pauseTracing(); - string memory dirPath = vme.getDeploymentDirectory(vme.getCurrentNetwork()); _tryCreateDir(dirPath); _serializeArtifact(dirPath, info); - - vm.resumeTracing(); } function _serializeArtifact(string memory dirPath, ArtifactInfo memory info) internal { diff --git a/script/libraries/LibDeploy.sol b/script/libraries/LibDeploy.sol index 3dab52e..f1493bc 100644 --- a/script/libraries/LibDeploy.sol +++ b/script/libraries/LibDeploy.sol @@ -229,7 +229,6 @@ library LibDeploy { function deployFromArtifact( DeployInfo memory info ) internal returns (address payable deployed) { - vm.pauseTracing(); deployed = deployFromBytecode( info.absolutePath, info.contractName, @@ -239,7 +238,6 @@ library LibDeploy { info.callValue, info.by ); - vm.resumeTracing(); } function deployFromBytecode( From a85dddd5b28d9ec820e247c7358056ce70181fb5 Mon Sep 17 00:00:00 2001 From: huyhuynh3103 Date: Mon, 12 Jan 2026 11:34:17 +0700 Subject: [PATCH 2/2] Add package-lock.json and update integrity checks in soldeer.lock; rename storage input in LibInitializeGuard --- package-lock.json | 6 ++++++ script/libraries/LibInitializeGuard.sol | 2 +- soldeer.lock | 4 ++-- 3 files changed, 9 insertions(+), 3 deletions(-) create mode 100644 package-lock.json diff --git a/package-lock.json b/package-lock.json new file mode 100644 index 0000000..a9faa7b --- /dev/null +++ b/package-lock.json @@ -0,0 +1,6 @@ +{ + "name": "foundry-deployment-kit", + "lockfileVersion": 3, + "requires": true, + "packages": {} +} diff --git a/script/libraries/LibInitializeGuard.sol b/script/libraries/LibInitializeGuard.sol index 5a9bc68..0103845 100644 --- a/script/libraries/LibInitializeGuard.sol +++ b/script/libraries/LibInitializeGuard.sol @@ -310,7 +310,7 @@ library LibInitializeGuard { inputs[0] = "forge"; inputs[1] = "inspect"; inputs[2] = _getContractAbsolutePath($cache._chainInfo[proxy].forkId, proxy); - inputs[3] = "storage"; + inputs[3] = "storageLayout"; inputs[4] = "--json"; string memory ret = string(vm.ffi(inputs)); diff --git a/soldeer.lock b/soldeer.lock index 9e23c34..7b5ab77 100644 --- a/soldeer.lock +++ b/soldeer.lock @@ -10,14 +10,14 @@ name = "openzeppelin-v4" version = "4.9.5" url = "https://github.com/OpenZeppelin/openzeppelin-contracts/archive/refs/tags/v4.9.5.zip" checksum = "fe249a9cb37b7a6664f8bfe61a9633873fbbb895e5d4c3fac78db50fd9af3a73" -integrity = "590ed70cbd82f6a8ea6512d136626c3aa02a22433a4bf84664faaa463c397574" +integrity = "b4b46e19320d23ccd8708b45bf3a1b996fdd3734fd6ec46cd1d24713af6d44f9" [[dependencies]] name = "openzeppelin-v5" version = "5.1.0" url = "https://github.com/OpenZeppelin/openzeppelin-contracts/archive/refs/tags/v5.1.0.zip" checksum = "30600e9dc4dd7d9089c5f2ae78aedfdb764349ae15647190c792afd07123e2c2" -integrity = "cb412b382c03069b2eb43beda83d3be86c9efcf3724368cb884d527357341366" +integrity = "5c896fe66026522d814bf97d4331d408283f549123254575c8a0f67c1fefecc1" [[dependencies]] name = "solady"