{"id":5667,"date":"2024-12-03T23:30:19","date_gmt":"2024-12-03T22:30:19","guid":{"rendered":"https:\/\/wsj-crypto.com\/?p=5667"},"modified":"2024-12-03T23:30:19","modified_gmt":"2024-12-03T22:30:19","slug":"mastering-secure-c-programming-essential-techniques-for-identifying-and-mitigating-vulnerabilities","status":"publish","type":"post","link":"https:\/\/wsj-crypto.com\/index.php\/2024\/12\/03\/mastering-secure-c-programming-essential-techniques-for-identifying-and-mitigating-vulnerabilities\/","title":{"rendered":"Mastering Secure C Programming: Essential Techniques for Identifying and Mitigating Vulnerabilities"},"content":{"rendered":"<p><\/p>\n<div id=\"\">\n<p class=\"chakra-text css-gi02ar\">For <!-- --><a target=\"_blank\" rel=\"noopener\" class=\"chakra-link css-ug8vf0\" href=\"https:\/\/eips.ethereum.org\/EIPS\/eip-4844\">EIP-4844<!-- --><\/a>, Ethereum clients must possess the capability to compute and validate KZG commitments. Instead of each client developing their own cryptographic solutions, researchers and developers collaborated to create <!-- --><a target=\"_blank\" rel=\"noopener\" class=\"chakra-link css-ug8vf0\" href=\"https:\/\/github.com\/ethereum\/c-kzg-4844\">c-kzg-4844<!-- --><\/a>, a comparatively compact C library featuring bindings for more advanced programming languages. The objective was to establish a sturdy and effective cryptographic library that all clients could utilize. The Protocol Security Research team at the Ethereum Foundation had the chance to evaluate and enhance this library. This blog post will elaborate on some methods we implement to bolster the security of C projects.<!-- --><\/p>\n<p><!-- --><br \/>\n<!-- --><\/p>\n<h2 class=\"chakra-heading css-1w54o5f\" id=\"fuzz\">Fuzz<!-- --><\/h2>\n<p><!-- --><\/p>\n<p class=\"chakra-text css-gi02ar\">Fuzzing is a dynamic code testing approach that entails supplying random inputs to identify bugs within a program. <!-- --><a target=\"_blank\" rel=\"noopener\" class=\"chakra-link css-ug8vf0\" href=\"https:\/\/www.llvm.org\/docs\/LibFuzzer.html\">LibFuzzer<!-- --><\/a> and <!-- --><a target=\"_blank\" rel=\"noopener\" class=\"chakra-link css-ug8vf0\" href=\"https:\/\/github.com\/AFLplusplus\/AFLplusplus\">afl++<!-- --><\/a> are two well-known fuzzing frameworks for C projects. Both are in-process, coverage-guided, evolutionary fuzzing engines. For c-kzg-4844, <!-- --><a target=\"_blank\" rel=\"noopener\" class=\"chakra-link css-ug8vf0\" href=\"https:\/\/github.com\/ethereum\/c-kzg-4844\/tree\/main\/fuzz\">we opted for<!-- --><\/a> LibFuzzer, owing to our established integration with LLVM project\u2019s other features.<!-- --><\/p>\n<p><!-- --><\/p>\n<p class=\"chakra-text css-gi02ar\">Presented below is the fuzzer for <!-- --><span class=\"chakra-text css-ons8vw\">verify_kzg_proof<\/span>, one of the methods in c-kzg-4844:<!-- --><\/p>\n<p><!-- --><\/p>\n<div class=\"chakra-stack css-1uyok63\">\n<pre><pre style=\"color:white;font-family:Consolas, Monaco, &quot;Andale Mono&quot;, &quot;Ubuntu Mono&quot;, monospace;text-align:left;white-space:pre;word-spacing:normal;word-break:normal;word-wrap:normal;line-height:1.5;font-size:1em;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-hyphens:none;-moz-hyphens:none;-ms-hyphens:none;hyphens:none;padding:1em;margin:0.5em 0;overflow:auto;background:#011627\"><code class=\"language-c=\" style=\"color:#d6deeb;font-family:Consolas, Monaco, &quot;Andale Mono&quot;, &quot;Ubuntu Mono&quot;, monospace;text-align:left;white-space:pre;word-spacing:normal;word-break:normal;word-wrap:normal;line-height:1.5;font-size:1em;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-hyphens:none;-moz-hyphens:none;-ms-hyphens:none;hyphens:none\"><span>#include \"..\/base_fuzz.h\"\n<!-- --><\/span>\n<!-- -->static const size_t COMMITMENT_OFFSET = 0;\n<!-- -->static const size_t Z_OFFSET = COMMITMENT_OFFSET + BYTES_PER_COMMITMENT;\n<!-- -->static const size_t Y_OFFSET = Z_OFFSET + BYTES_PER_FIELD_ELEMENT;\n<!-- -->static const size_t PROOF_OFFSET = Y_OFFSET + BYTES_PER_FIELD_ELEMENT;\n<!-- -->static const size_t INPUT_SIZE = PROOF_OFFSET + BYTES_PER_PROOF;\n<!-- -->\n<!-- -->int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {\n<!-- -->    initialize();\n<!-- -->    if (size == INPUT_SIZE) {\n<!-- -->        bool ok;\n<!-- -->        verify_kzg_proof(\n<!-- -->            &amp;ok,\n<!-- -->            (const Bytes48 *)(data + COMMITMENT_OFFSET),\n<!-- -->            (const Bytes32 *)(data + Z_OFFSET),\n<!-- -->            (const Bytes32 *)(data + Y_OFFSET),\n<!-- -->            (const Bytes48 *)(data + PROOF_OFFSET),\n<!-- -->            &amp;s\n<!-- -->        );\n<!-- -->    }\n<!-- -->    return 0;\n<!-- -->}\n<!-- --><\/code><\/pre>\n<\/div>\n<p><!-- --><\/p>\n<p class=\"chakra-text css-gi02ar\">Upon execution, this is the resulting output. Should an issue arise, the input would be recorded to disk, and execution would halt. Ideally, reproducing the problem should be possible.<!-- --><\/p>\n<p><!-- --><\/p>\n<p class=\"chakra-text css-gi02ar\">\n<p><!-- --><\/p>\n<p class=\"chakra-text css-gi02ar\">Additionally, there is differential fuzzing, a method where two or more implementations of the same interface are fuzzed concurrently, and the outputs are compared. For any specific input, if the outputs differ when they were expected to be the same, it signifies an error. This approach is quite prevalent in Ethereum as we prefer to maintain multiple implementations of the same functionalities. Such diversity enhances safety, ensuring that if one implementation has flaws, the others may not experience the same issues.<!-- --><\/p>\n<p><!-- --><\/p>\n<p class=\"chakra-text css-gi02ar\">For KZG libraries, we established <!-- --><a target=\"_blank\" rel=\"noopener\" class=\"chakra-link css-ug8vf0\" href=\"https:\/\/github.com\/jtraglia\/kzg-fuzz\">kzg-fuzz<!-- --><\/a>, which differentially fuzzes c-kzg-4844 (via its Golang bindings) and <!-- --><a target=\"_blank\" rel=\"noopener\" class=\"chakra-link css-ug8vf0\" href=\"https:\/\/github.com\/crate-crypto\/go-kzg-4844\">go-kzg-4844<!-- --><\/a>. Up to this point, no discrepancies have been noted.<!-- --><\/p>\n<p><!-- --><\/p>\n<h2 class=\"chakra-heading css-1w54o5f\" id=\"coverage\">Coverage<!-- --><\/h2>\n<p><!-- --><\/p>\n<p class=\"chakra-text css-gi02ar\">Subsequently, we utilized <!-- --><a target=\"_blank\" rel=\"noopener\" class=\"chakra-link css-ug8vf0\" href=\"https:\/\/www.llvm.org\/docs\/CommandGuide\/llvm-profdata.html\">llvm-profdata<!-- --><\/a> and <!-- --><a target=\"_blank\" rel=\"noopener\" class=\"chakra-link css-ug8vf0\" href=\"https:\/\/www.llvm.org\/docs\/CommandGuide\/llvm-cov.html\">llvm-cov<!-- --><\/a> to produce a coverage report from executing the tests. This serves as an excellent means to confirm which code has been executed (&#8220;covered&#8221;) and tested. Refer to the <!-- --><a target=\"_blank\" rel=\"noopener\" class=\"chakra-link css-ug8vf0\" href=\"https:\/\/github.com\/ethereum\/c-kzg-4844\/blob\/f3fffecd1ce7e8b6620cd5bac50c660efc20e48c\/src\/Makefile#L76-L91\"><span class=\"chakra-text css-ons8vw\">coverage<\/span><\/a> target in the Makefile of c-kzg-4844 for an illustration of how to generate this report.<!-- --><\/p>\n<p><!-- --><\/p>\n<p class=\"chakra-text css-gi02ar\">When this target is executed (<!-- --><em class=\"chakra-text css-0\">i.e.<!-- --><\/em>, <!-- --><span class=\"chakra-text css-ons8vw\">make coverage<\/span>) a table is produced that provides a high-level summary of how much of each function has been executed. The exported functions are listed at the top, while the non-exported (static) functions appear at the bottom.<!-- --><\/p>\n<p><!-- --><\/p>\n<p class=\"chakra-text css-gi02ar\"><img decoding=\"async\" alt=\"\" src=\"https:\/\/storage.googleapis.com\/ethereum-hackmd\/upload_cc6a7e22dce7e1f4e3ca1942d9271e2a.png\" class=\"chakra-image css-hw6q2r\"\/><\/p>\n<p><!-- --><\/p>\n<p class=\"chakra-text css-gi02ar\">The above table exhibits considerable green, yet it also contains some yellow and red. To discern what is being executed and what is not, refer to the generated HTML file (<!-- --><span class=\"chakra-text css-ons8vw\">coverage.html<\/span>), which displays the complete source file and marks non-executed code in red. In this project&#8217;s instance, most of the non-executed code pertains to challenging-to-test error scenarios, including memory allocation failures. For example, here\u2019s some code that hasn\u2019t been executed:<!-- --><\/p>\n<p><!-- --><\/p>\n<p class=\"chakra-text css-gi02ar\"><img decoding=\"async\" alt=\"\" src=\"https:\/\/storage.googleapis.com\/ethereum-hackmd\/upload_492f85debe5377bd42bcf2411df12021.png\" class=\"chakra-image css-hw6q2r\"\/><\/p>\n<p><!-- --><\/p>\n<p class=\"chakra-text css-gi02ar\">At the commencement of this function, it verifies whether the trusted setup possesses sufficient size to carry out a pairing check. No test case supplies an invalid trusted setup, resulting in this section not being executed. Furthermore, since we solely test with the accurate trusted setup, the outcome of <!-- --><span class=\"chakra-text css-ons8vw\">is_monomial_form<\/span> consistently remains the same and fails to return the error value.<!-- --><\/p>\n<p><!-- --><\/p>\n<h2 class=\"chakra-heading css-1w54o5f\" id=\"profile\">Profile<!-- --><\/h2>\n<p><!-- --><\/p>\n<p class=\"chakra-text css-gi02ar\">We do not urge this forall initiatives, but since c-kzg-4844 is a performance-critical library, we believe it&#8217;s essential to analyze its exposed functions and gauge their execution duration. This can assist in pinpointing inefficiencies that could potentially lead to DoS conditions for nodes. For this purpose, we opted to use <!-- --><a target=\"_blank\" rel=\"noopener\" class=\"chakra-link css-ug8vf0\" href=\"https:\/\/github.com\/gperftools\/gperftools\">gperftools<!-- --><\/a> (Google Performance Tools) rather than <!-- --><a target=\"_blank\" rel=\"noopener\" class=\"chakra-link css-ug8vf0\" href=\"https:\/\/llvm.org\/docs\/XRay.html\">llvm-xray<!-- --><\/a> because we found it to offer more features and better usability.<!-- --><\/p>\n<p><!-- --><\/p>\n<p class=\"chakra-text css-gi02ar\">The subsequent example offers a straightforward illustration that profiles <!-- --><span class=\"chakra-text css-ons8vw\">my_function<\/span>. Profiling functions by assessing which instruction is being processed intermittently. If a function executes rapidly enough, it might not be registered by the profiler. To mitigate this risk, it may be necessary to invoke your function numerous times. In this case, we call <!-- --><span class=\"chakra-text css-ons8vw\">my_function<\/span> 1000 instances.<!-- --><\/p>\n<p><!-- --><\/p>\n<div class=\"chakra-stack css-1uyok63\">\n<pre><pre style=\"color:white;font-family:Consolas, Monaco, &quot;Andale Mono&quot;, &quot;Ubuntu Mono&quot;, monospace;text-align:left;white-space:pre;word-spacing:normal;word-break:normal;word-wrap:normal;line-height:1.5;font-size:1em;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-hyphens:none;-moz-hyphens:none;-ms-hyphens:none;hyphens:none;padding:1em;margin:0.5em 0;overflow:auto;background:#011627\"><code class=\"language-c=\" style=\"color:#d6deeb;font-family:Consolas, Monaco, &quot;Andale Mono&quot;, &quot;Ubuntu Mono&quot;, monospace;text-align:left;white-space:pre;word-spacing:normal;word-break:normal;word-wrap:normal;line-height:1.5;font-size:1em;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-hyphens:none;-moz-hyphens:none;-ms-hyphens:none;hyphens:none\"><span>#include <gperftools>\n<!-- --><\/gperftools><\/span>\n<!-- -->int task_a(int n) {\n<!-- -->    if (n     return task_a(n - 1) * n;\n<!-- -->}\n<!-- -->\n<!-- -->int task_b(int n) {\n<!-- -->    if (n     return task_b(n - 2) + n;\n<!-- -->}\n<!-- -->\n<!-- -->void my_function(void) {\n<!-- -->    for (int i = 0; i         if (i % 2 == 0) {\n<!-- -->            task_a(i);\n<!-- -->        } else {\n<!-- -->            task_b(i);\n<!-- -->        }\n<!-- -->    }\n<!-- -->}\n<!-- -->\n<!-- -->int main(void) {\n<!-- -->    ProfilerStart(\"example.prof\");\n<!-- -->    for (int i = 0; i         my_function();\n<!-- -->    }\n<!-- -->    ProfilerStop();\n<!-- -->    return 0;\n<!-- -->}\n<!-- --><\/code><\/pre>\n<\/div>\n<p><!-- --><\/p>\n<p class=\"chakra-text css-gi02ar\">Utilize <!-- --><span class=\"chakra-text css-ons8vw\">ProfilerStart(&#8220;<filename>&#8220;)<\/filename><\/span> and <!-- --><span class=\"chakra-text css-ons8vw\">ProfilerStop()<\/span> to designate which segments of your program to analyze. Upon recompilation and execution, it will generate a file on disk containing profiling information. You can subsequently utilize <!-- --><a target=\"_blank\" rel=\"noopener\" class=\"chakra-link css-ug8vf0\" href=\"https:\/\/github.com\/google\/pprof\">pprof<!-- --><\/a> to illustrate this information.<!-- --><\/p>\n<p><!-- --><\/p>\n<p class=\"chakra-text css-gi02ar\"><img decoding=\"async\" alt=\"\" src=\"https:\/\/storage.googleapis.com\/ethereum-hackmd\/upload_928840ff7f217e9bef867c28c52ce5b5.png\" class=\"chakra-image css-hw6q2r\"\/><\/p>\n<p><!-- --><\/p>\n<p class=\"chakra-text css-gi02ar\">Here lies the graph produced from the previous command:<!-- --><\/p>\n<p><!-- --><\/p>\n<p class=\"chakra-text css-gi02ar\"><img decoding=\"async\" alt=\"\" src=\"https:\/\/storage.googleapis.com\/ethereum-hackmd\/upload_65ba3120f91592876c51b8ac92525914.png\" class=\"chakra-image css-hw6q2r\"\/><\/p>\n<p><!-- --><\/p>\n<p class=\"chakra-text css-gi02ar\">Here is a larger instance derived from one of c-kzg-4844&#8217;s functions. The subsequent image displays the profiling graph for <!-- --><a target=\"_blank\" rel=\"noopener\" class=\"chakra-link css-ug8vf0\" href=\"https:\/\/github.com\/ethereum\/c-kzg-4844\/blob\/f3fffecd1ce7e8b6620cd5bac50c660efc20e48c\/src\/c_kzg_4844.c#L1106-L1145\"><span class=\"chakra-text css-ons8vw\">compute_blob_kzg_proof<\/span><\/a>. Clearly, 80% of this function&#8217;s duration is dedicated to executing Montgomery multiplications. This is anticipated.<!-- --><\/p>\n<p><!-- --><\/p>\n<p class=\"chakra-text css-gi02ar\"><img decoding=\"async\" alt=\"\" src=\"https:\/\/storage.googleapis.com\/ethereum-hackmd\/upload_e6bad1c1c6cb6a5a71aa98a108abb99d.png\" class=\"chakra-image css-hw6q2r\"\/><\/p>\n<p><!-- --><\/p>\n<h2 class=\"chakra-heading css-1w54o5f\" id=\"reverse\">Reverse<!-- --><\/h2>\n<p><!-- --><\/p>\n<p class=\"chakra-text css-gi02ar\">Next, inspect your binary using a software reverse engineering (SRE) tool such as <!-- --><a target=\"_blank\" rel=\"noopener\" class=\"chakra-link css-ug8vf0\" href=\"https:\/\/ghidra-sre.org\">Ghidra<!-- --><\/a> or <!-- --><a target=\"_blank\" rel=\"noopener\" class=\"chakra-link css-ug8vf0\" href=\"https:\/\/hex-rays.com\/ida-free\/\">IDA<!-- --><\/a>. These utilities assist in comprehending how high-level constructs are transformed into low-level machine code. We find it beneficial to review your source code this manner; similar to how reading a document in an unfamiliar font compels your mind to interpret phrases distinctively. It&#8217;s invaluable to observe the types of optimizations your compiler performs. Although uncommon, there are instances when the compiler eliminates elements it considered superfluous. Stay vigilant for this; a situation like this did occur in c-kzg-4844, <!-- --><a target=\"_blank\" rel=\"noopener\" class=\"chakra-link css-ug8vf0\" href=\"https:\/\/github.com\/ethereum\/c-kzg-4844\/pull\/133\">some of the tests were being optimized out<!-- --><\/a>.<!-- --><\/p>\n<p><!-- --><\/p>\n<p class=\"chakra-text css-gi02ar\">When you analyze a decompiled function, it won\u2019t possess variable names, intricate types, or annotations. This information is absent from the binary once compiled. It is up to you to reverse-engineer this. Often you&#8217;ll observe functions being inlined into a singular function, multiple variables being condensed into a single buffer, and the order of verifications varying. These are just optimizations by the compiler and are generally acceptable. It may be advantageous to compile your binary with DWARF debugging details; most SRE tools can scrutinize this section for enhanced outcomes.<!-- --><\/p>\n<p><!-- --><\/p>\n<p class=\"chakra-text css-gi02ar\">For instance, this is what <!-- --><span class=\"chakra-text css-ons8vw\">blob_to_kzg_commitment<\/span> initially resembles in Ghidra:<!-- --><\/p>\n<p><!-- --><\/p>\n<p class=\"chakra-text css-gi02ar\"><img decoding=\"async\" alt=\"\" src=\"https:\/\/storage.googleapis.com\/ethereum-hackmd\/upload_add5963e243fa2449ff2fa088db8e2b8.png\" class=\"chakra-image css-hw6q2r\"\/><\/p>\n<p><!-- --><\/p>\n<p class=\"chakra-text css-gi02ar\">With a bit of effort, you can reassign variable names and incorporate comments to enhance readability. Here\u2019s what it may look like following a few minutes of effort:<!-- --><\/p>\n<p><!-- --><\/p>\n<p class=\"chakra-text css-gi02ar\"><img decoding=\"async\" alt=\"\" src=\"https:\/\/storage.googleapis.com\/ethereum-hackmd\/upload_187e2686e3e43aec289d5c3c2a8914e3.png\" class=\"chakra-image css-hw6q2r\"\/><\/p>\n<p><!-- --><\/p>\n<h2 class=\"chakra-heading css-1w54o5f\" id=\"static-analysis\">Static Analysis<!-- --><\/h2>\n<p><!-- --><\/p>\n<p class=\"chakra-text css-gi02ar\"><a target=\"_blank\" rel=\"noopener\" class=\"chakra-link css-ug8vf0\" href=\"https:\/\/clang.llvm.org\">Clang<!-- --><\/a> comes packaged with the <!-- --><a target=\"_blank\" rel=\"noopener\" class=\"chakra-link css-ug8vf0\" href=\"https:\/\/clang-analyzer.llvm.org\">Clang Static Analyzer<!-- --><\/a>, a superb static analysis tool capable of detecting numerous issues that compilers might overlook. As the term &#8220;static&#8221; implies, it inspects code without executing it. While this process is slower than compiling, it is significantly quicker than &#8220;dynamic&#8221; analysis tools that run the code.<!-- --><\/p>\n<p><!-- --><\/p>\n<p class=\"chakra-text css-gi02ar\">Here\u2019s a straightforward example that neglects to release <!-- --><span class=\"chakra-text css-ons8vw\">arr<\/span> (alongside another issue which we will delve into later). The compiler will fail to recognize this, even with all warnings activated because, from a technical standpoint, this is entirely valid code.<!-- --><\/p>\n<p><!-- --><\/p>\n<div class=\"chakra-stack css-1uyok63\">\n<pre><pre style=\"color:white;font-family:Consolas, Monaco, &quot;Andale Mono&quot;, &quot;Ubuntu Mono&quot;, monospace;text-align:left;white-space:pre;word-spacing:normal;word-break:normal;word-wrap:normal;line-height:1.5;font-size:1em;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-hyphens:none;-moz-hyphens:none;-ms-hyphens:none;hyphens:none;padding:1em;margin:0.5em 0;overflow:auto;background:#011627\"><code class=\"language-c=\" style=\"color:#d6deeb;font-family:Consolas, Monaco, &quot;Andale Mono&quot;, &quot;Ubuntu Mono&quot;, monospace;text-align:left;white-space:pre;word-spacing:normal;word-break:normal;word-wrap:normal;line-height:1.5;font-size:1em;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-hyphens:none;-moz-hyphens:none;-ms-hyphens:none;hyphens:none\"><span>#include <stdlib.h>\n<!-- --><\/stdlib.h><\/span>\n<!-- -->int main(void) {\n<!-- -->    int* arr = malloc(5 * sizeof(int));\n<!-- -->    arr[5] = 42;\n<!-- -->    return 0;\n<!-- -->}\n<!-- --><\/code><\/pre>\n<\/div>\n<p><!-- --><\/p>\n<p class=\"chakra-text css-gi02ar\">The <!-- --><span class=\"chakra-text css-ons8vw\">unix.Malloc<\/span> verifier will detect that <!-- --><span class=\"chakra-text css-ons8vw\">arr<\/span> was never de-allocated. The phrase in the alert may appear somewhat unclear, yet it becomes logical upon reflection; the analyzer arrived at the return statement and observed that the memory had not been released.<!-- --><\/p>\n<p><!-- --><\/p>\n<p class=\"chakra-text css-gi02ar\"><img decoding=\"async\" alt=\"\" src=\"https:\/\/storage.googleapis.com\/ethereum-hackmd\/upload_a881c53b712cbfcdc95251ac9e26e9c7.png\" class=\"chakra-image css-hw6q2r\"\/><\/p>\n<p><!-- --><\/p>\n<p class=\"chakra-text css-gi02ar\">Nevertheless, not all discoveries are this straightforward. Below is an observation made by Clang Static Analyzer in c-kzg-4844 upon its first assessment of the project:<!-- --><\/p>\n<p><!-- --><\/p>\n<p class=\"chakra-text css-gi02ar\"><img decoding=\"async\" alt=\"\" src=\"https:\/\/storage.googleapis.com\/ethereum-hackmd\/upload_8cb730fd65c5008b19e66b0e0567267d.png\" class=\"chakra-image css-hw6q2r\"\/><\/p>\n<p><!-- --><\/p>\n<p class=\"chakra-text css-gi02ar\">When given an unusual input, it was feasible to shift this value by 32 bits which constitutes undefined behavior. The resolution was to constrain the input with <!-- --><span class=\"chakra-text css-ons8vw\">CHECK(log2_pow2(n) != 0)<\/span> to make this impossible. Well done, Clang Static Analyzer!<!-- --><\/p>\n<p><!-- --><\/p>\n<h2 class=\"chakra-heading css-1w54o5f\" id=\"sanitize\">Sanitize<!-- --><\/h2>\n<p><!-- --><\/p>\n<p class=\"chakra-text css-gi02ar\">Sanitizers are dynamic examination utilities that augment (add instructions) to programs, enabling them to highlight issues during runtime. They prove especially beneficial for detecting frequent errors related to memory management. Clang is equipped with several sanitizers by default; below are the four we consider most beneficial and user-friendly.<!-- --><\/p>\n<p><!-- --><\/p>\n<h3 class=\"chakra-heading css-145upk7\" id=\"address\">Address<!-- --><\/h3>\n<p><!-- --><\/p>\n<p class=\"chakra-text css-gi02ar\"><a target=\"_blank\" rel=\"noopener\" class=\"chakra-link css-ug8vf0\" href=\"https:\/\/clang.llvm.org\/docs\/AddressSanitizer.html\">AddressSanitizer<!-- --><\/a> (ASan) is a rapid memory fault detector that can recognize out-of-bounds accesses, use-after-free, use-after-return, use-after-scope, double-free, and memory leaks.<!-- --><\/p>\n<p><!-- --><\/p>\n<p class=\"chakra-text css-gi02ar\">Here is the identical example from earlier. It forgets to release <!-- --><span class=\"chakra-text css-ons8vw\">arr<\/span> and it will set the 6th element in a 5-element array. This serves as a straightforward instance of a heap-buffer-overflow:<!-- --><\/p>\n<p><!-- --><\/p>\n<div class=\"chakra-stack css-1uyok63\">\n<pre><pre style=\"color:white;font-family:Consolas, Monaco, &quot;Andale Mono&quot;, &quot;Ubuntu Mono&quot;, monospace;text-align:left;white-space:pre;word-spacing:normal;word-break:normal;word-wrap:normal;line-height:1.5;font-size:1em;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-hyphens:none;-moz-hyphens:none;-ms-hyphens:none;hyphens:none;padding:1em;margin:0.5em 0;overflow:auto;background:#011627\"><code class=\"language-c=\" style=\"color:#d6deeb;font-family:Consolas, Monaco, &quot;Andale Mono&quot;, &quot;Ubuntu Mono&quot;, monospace;text-align:left;white-space:pre;word-spacing:normal;word-break:normal;word-wrap:normal;line-height:1.5;font-size:1em;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-hyphens:none;-moz-hyphens:none;-ms-hyphens:none;hyphens:none\"><span>#include <stdlib.h>\n<!-- --><\/stdlib.h><\/span>\n<!-- -->int main(void) {\n<!-- -->    int* arr = malloc(5 * sizeof(int));\n<!-- -->    arr[5] = 42;\n<!-- -->    return 0;\n<!-- -->}\n<!-- --><\/code><\/pre>\n<\/div>\n<p><!-- --><\/p>\n<p class=\"chakra-text css-gi02ar\">When compiled with <!-- --><span class=\"chakra-text css-ons8vw\">-fsanitize=address<\/span> and executed, it will generate the following error message. This directs you toward a precise indication (a 4-byte write in <!-- --><span class=\"chakra-text css-ons8vw\">main<\/span>). You could analyze this binary in a disassembler to ascertain precisely which instruction (at <!-- --><span class=\"chakra-text css-ons8vw\">main+0x84<\/span>) is resulting in the problem.<!-- --><\/p>\n<p><!-- --><\/p>\n<p class=\"chakra-text css-gi02ar\"><img decoding=\"async\" alt=\"\" src=\"https:\/\/storage.googleapis.com\/ethereum-hackmd\/upload_f93e2b996431bb0fa2c97fd074047a8a.png\" class=\"chakra-image css-hw6q2r\"\/><\/p>\n<p><!-- --><\/p>\n<p class=\"chakra-text css-gi02ar\">In a similar fashion, here&#8217;s a case where it detects a heap-use-after-free:<!-- --><\/p>\n<p><!-- --><\/p>\n<div class=\"chakra-stack css-1uyok63\">\n<pre><pre style=\"color:white;font-family:Consolas, Monaco, &quot;Andale Mono&quot;, &quot;Ubuntu Mono&quot;, monospace;text-align:left;white-space:pre;word-spacing:normal;word-break:normal;word-wrap:normal;line-height:1.5;font-size:1em;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-hyphens:none;-moz-hyphens:none;-ms-hyphens:none;hyphens:none;padding:1em;margin:0.5em 0;overflow:auto;background:#011627\"><code class=\"language-c=\" style=\"color:#d6deeb;font-family:Consolas, Monaco, &quot;Andale Mono&quot;, &quot;Ubuntu Mono&quot;, monospace;text-align:left;white-space:pre;word-spacing:normal;word-break:normal;word-wrap:normal;line-height:1.5;font-size:1em;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-hyphens:none;-moz-hyphens:none;-ms-hyphens:none;hyphens:none\"><span>#include <stdlib.h>\n<!-- --><\/stdlib.h><\/span>\n<!-- -->int main(void) {\n<!-- -->    int *arr = malloc(5 * sizeof(int));\n<!-- -->    free(arr);\n<!-- -->    return arr[2];\n<!-- -->}\n<!-- --><\/code><\/pre>\n<\/div>\n<p><!-- --><\/p>\n<p class=\"chakra-text css-gi02ar\"><img decoding=\"async\" alt=\"\" src=\"https:\/\/storage.googleapis.com\/ethereum-hackmd\/upload_7acf4da0ecfa28026043293dae99e9ec.png\" class=\"chakra-image css-hw6q2r\"\/><\/p>\n<p><!-- --><\/p>\n<p class=\"chakra-text css-gi02ar\">It informs you that there&#8217;s a 4-byte read of deallocated memory at <!-- --><span class=\"chakra-text css-ons8vw\">main+0x8c<\/span>.<!-- --><\/p>\n<p><!-- --><\/p>\n<h3 class=\"chakra-heading css-145upk7\" id=\"memory\">Memory<!-- --><\/h3>\n<p><!-- --><\/p>\n<p class=\"chakra-text css-gi02ar\"><a target=\"_blank\" rel=\"noopener\" class=\"chakra-link css-ug8vf0\" href=\"https:\/\/clang.llvm.org\/docs\/MemorySanitizer.html\">MemorySanitizer<!-- --><\/a> (MSan) serves as a detector for uninitialized reads. Here is a straightforward case which accesses (and returns) an uninitialized value:<!-- --><\/p>\n<p><!-- --><\/p>\n<div class=\"chakra-stack css-1uyok63\">\n<pre><pre style=\"color:white;font-family:Consolas, Monaco, &quot;Andale Mono&quot;, &quot;Ubuntu Mono&quot;, monospace;text-align:left;white-space:pre;word-spacing:normal;word-break:normal;word-wrap:normal;line-height:1.5;font-size:1em;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-hyphens:none;-moz-hyphens:none;-ms-hyphens:none;hyphens:none;padding:1em;margin:0.5em 0;overflow:auto;background:#011627\"><code class=\"language-c=\" style=\"color:#d6deeb;font-family:Consolas, Monaco, &quot;Andale Mono&quot;, &quot;Ubuntu Mono&quot;, monospace;text-align:left;white-space:pre;word-spacing:normal;word-break:normal;word-wrap:normal;line-height:1.5;font-size:1em;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-hyphens:none;-moz-hyphens:none;-ms-hyphens:none;hyphens:none\"><span>int main(void) {\n<!-- --><\/span>    int array[2];\n<!-- -->    return array[0];\n<!-- -->}\n<!-- --><\/code><\/pre>\n<\/div>\n<p><!-- --><\/p>\n<p class=\"chakra-text css-gi02ar\">When compiled using <!-- --><span class=\"chakra-text css-ons8vw\">-fsanitize=memory<\/span> and run, it will present the following error notification:<!-- --><\/p>\n<p><!-- --><\/p>\n<p class=\"chakra-text css-gi02ar\"><img decoding=\"async\" alt=\"\" src=\"https:\/\/storage.googleapis.com\/ethereum-hackmd\/upload_08f2007fb193bbf1051d3a46bbbdb299.png\" class=\"chakra-image css-hw6q2r\"\/><\/p>\n<p><!-- --><\/p>\n<h3 class=\"chakra-heading css-145upk7\" id=\"undefined-behavior\">Unpredictable Behavior<!-- --><\/h3>\n<p><!-- --><\/p>\n<p class=\"chakra-text css-gi02ar\"><a target=\"_blank\" rel=\"noopener\" class=\"chakra-link css-ug8vf0\" href=\"https:\/\/clang.llvm.org\/docs\/UndefinedBehaviorSanitizer.html\">UndefinedBehaviorSanitizer<!-- --><\/a> (UBSan) identifies unpredictable behavior, which pertains to cases where the operation of a program is erratic and not dictated by the language standard. Common instances include accessing memory out-of-bounds, dereferencing an invalid pointer, reading variables that are not initialized, and overflowing a signed integer. For instance, incrementing <!-- --><span class=\"chakra-text css-ons8vw\">INT_MAX<\/span> is an example of unpredictable behavior.<!-- --><\/p>\n<p><!-- --><\/p>\n<div class=\"chakra-stack css-1uyok63\">\n<pre><pre style=\"color:white;font-family:Consolas, Monaco, &quot;Andale Mono&quot;, &quot;Ubuntu Mono&quot;, monospace;text-align:left;white-space:pre;word-spacing:normal;word-break:normal;word-wrap:normal;line-height:1.5;font-size:1em;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-hyphens:none;-moz-hyphens:none;-ms-hyphens:none;hyphens:none;padding:1em;margin:0.5em 0;overflow:auto;background:#011627\"><code class=\"language-c=\" style=\"color:#d6deeb;font-family:Consolas, Monaco, &quot;Andale Mono&quot;, &quot;Ubuntu Mono&quot;, monospace;text-align:left;white-space:pre;word-spacing:normal;word-break:normal;word-wrap:normal;line-height:1.5;font-size:1em;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-hyphens:none;-moz-hyphens:none;-ms-hyphens:none;hyphens:none\"><span>#include <limits.h>\n<!-- --><\/limits.h><\/span>\n<!-- -->int main(void) {\n<!-- -->    int b = INT_MAX;\n<!-- -->    return b + 1;\n<!-- -->}\n<!-- --><\/code><\/pre>\n<\/div>\n<p><!-- --><\/p>\n<p class=\"chakra-text css-gi02ar\">When compiled using <!-- --><span class=\"chakra-text css-ons8vw\">-fsanitize=undefined<\/span> and then executed, it will display the following error notification pinpointing the exact issue and its conditions:<!-- --><\/p>\n<p><!-- --><\/p>\n<p class=\"chakra-text css-gi02ar\"><img decoding=\"async\" alt=\"\" src=\"https:\/\/storage.googleapis.com\/ethereum-hackmd\/upload_943dbefe49f7da39c69bec29e3c4261a.png\" class=\"chakra-image css-hw6q2r\"\/><\/p>\n<p><!-- --><\/p>\n<h3 class=\"chakra-heading css-145upk7\" id=\"thread\">Threading<!-- --><\/h3>\n<p><!-- --><\/p>\n<p class=\"chakra-text css-gi02ar\"><a target=\"_blank\" rel=\"noopener\" class=\"chakra-link css-ug8vf0\" href=\"https:\/\/clang.llvm.org\/docs\/ThreadSanitizer.html\">ThreadSanitizer<!-- --><\/a> (TSan) identifies data races, which can take place in multi-threaded applications when two or more threads access a common memory location concurrently. This scenario introduces unpredictability and may result in undefined behavior. Below is an instance where two threads increment a global <!-- --><span class=\"chakra-text css-ons8vw\">counter<\/span> variable. Without any form of locking or semaphores, it is completely feasible for both threads to increment the variable simultaneously.<!-- --><\/p>\n<p><!-- --><\/p>\n<div class=\"chakra-stack css-1uyok63\">\n<pre><pre style=\"color:white;font-family:Consolas, Monaco, &quot;Andale Mono&quot;, &quot;Ubuntu Mono&quot;, monospace;text-align:left;white-space:pre;word-spacing:normal;word-break:normal;word-wrap:normal;line-height:1.5;font-size:1em;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-hyphens:none;-moz-hyphens:none;-ms-hyphens:none;hyphens:none;padding:1em;margin:0.5em 0;overflow:auto;background:#011627\"><code class=\"language-c=\" style=\"color:#d6deeb;font-family:Consolas, Monaco, &quot;Andale Mono&quot;, &quot;Ubuntu Mono&quot;, monospace;text-align:left;white-space:pre;word-spacing:normal;word-break:normal;word-wrap:normal;line-height:1.5;font-size:1em;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-hyphens:none;-moz-hyphens:none;-ms-hyphens:none;hyphens:none\"><span>#include <pthread.h>\n<!-- --><\/pthread.h><\/span>\n<!-- -->int counter = 0;\n<!-- -->\n<!-- -->void *increment(void *arg) {\n<!-- -->    (void)arg;\n<!-- -->    for (int i = 0; i         counter++;\n<!-- -->    return NULL;\n<!-- -->}\n<!-- -->\n<!-- -->int main(void) {\n<!-- -->    pthread_t thread1, thread2;\n<!-- -->    pthread_create(&amp;thread1, NULL, increment, NULL);\n<!-- -->    pthread_create(&amp;thread2, NULL, increment, NULL);\n<!-- -->    pthread_join(thread1, NULL);\n<!-- -->    pthread_join(thread2, NULL);\n<!-- -->    return 0;\n<!-- -->}\n<!-- --><\/code><\/pre>\n<\/div>\n<p><!-- --><\/p>\n<p class=\"chakra-text css-gi02ar\">When compiled using <!-- --><span class=\"chakra-text css-ons8vw\">-fsanitize=thread<\/span> and run, it will display the following error notification:<!-- --><\/p>\n<p><!-- --><\/p>\n<p class=\"chakra-text css-gi02ar\"><img decoding=\"async\" alt=\"\" src=\"https:\/\/storage.googleapis.com\/ethereum-hackmd\/upload_82d46b5c5a4b180cbcdd2e7c12637cae.png\" class=\"chakra-image css-hw6q2r\"\/><\/p>\n<p><!-- --><\/p>\n<p class=\"chakra-text css-gi02ar\">This error notification indicates that there exists a data race. In both threads, the <!-- --><span class=\"chakra-text css-ons8vw\">increment<\/span> function is concurrently writing to the same 4 bytes. It even specifies that the memory involved is the <!-- --><span class=\"chakra-text css-ons8vw\">counter<\/span>.<!-- --><\/p>\n<p><!-- --><\/p>\n<h2 class=\"chakra-heading css-1w54o5f\" id=\"valgrind\">Valgrind<!-- --><\/h2>\n<p><!-- --><\/p>\n<p class=\"chakra-text css-gi02ar\"><a target=\"_blank\" rel=\"noopener\" class=\"chakra-link css-ug8vf0\" href=\"https:\/\/valgrind.org\">Valgrind<!-- --><\/a> is a formidable instrumentation framework designated for constructing dynamic analysis tools, renowned for detecting memory errors and leaks through its integrated Memcheck tool.<!-- --><\/p>\n<p><!-- --><\/p>\n<p class=\"chakra-text css-gi02ar\">The next image illustrates the results obtained from executing c-kzg-4844&#8217;s tests utilizing Valgrind. The red box highlights a legitimate finding for a &#8220;conditional jump or move [that] depends on uninitialized value(s).&#8221;<!-- --><\/p>\n<p><!-- --><\/p>\n<p class=\"chakra-text css-gi02ar\"><img decoding=\"async\" alt=\"\" src=\"https:\/\/storage.googleapis.com\/ethereum-hackmd\/upload_39f00e156f5f622804660bb2622b5cb4.png\" class=\"chakra-image css-hw6q2r\"\/><\/p>\n<p><!-- --><\/p>\n<p class=\"chakra-text css-gi02ar\">This <!-- --><a target=\"_blank\" rel=\"noopener\" class=\"chakra-link css-ug8vf0\" href=\"https:\/\/github.com\/ethereum\/c-kzg-4844\/pull\/375\">highlighted an edge case<!-- --><\/a> in <!-- --><a target=\"_blank\" rel=\"noopener\" class=\"chakra-link css-ug8vf0\" href=\"https:\/\/github.com\/ethereum\/c-kzg-4844\/blob\/b2e41491ad1859f1792964a2432a419b64dc6fb2\/src\/c_kzg_4844.c#L1557-L1570\"><span class=\"chakra-text css-ons8vw\">expand_root_of_unity<\/span><\/a>. If incorrect root of unity or width was supplied, it could result in the loop terminating prior to the initialization of <!-- --><span class=\"chakra-text css-ons8vw\">out[width]<\/span>. In such a case, the final validation would rely on an uninitialized value.<!-- --><\/p>\n<p><!-- --><\/p>\n<div class=\"chakra-stack css-1uyok63\">\n<pre><pre style=\"color:white;font-family:Consolas, Monaco, &quot;Andale Mono&quot;, &quot;Ubuntu Mono&quot;, monospace;text-align:left;white-space:pre;word-spacing:normal;word-break:normal;word-wrap:normal;line-height:1.5;font-size:1em;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-hyphens:none;-moz-hyphens:none;-ms-hyphens:none;hyphens:none;padding:1em;margin:0.5em 0;overflow:auto;background:#011627\"><code class=\"language-c=1557\" style=\"color:#d6deeb;font-family:Consolas, Monaco, &quot;Andale Mono&quot;, &quot;Ubuntu Mono&quot;, monospace;text-align:left;white-space:pre;word-spacing:normal;word-break:normal;word-wrap:normal;line-height:1.5;font-size:1em;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-hyphens:none;-moz-hyphens:none;-ms-hyphens:none;hyphens:none\"><span>static C_KZG_RET expand_root_of_unity(\n<!-- --><\/span>    fr_t *out, const fr_t *root, uint64_t width\n<!-- -->) {\n<!-- -->    out[0] = FR_ONE;\n<!-- -->    out[1] = *root;\n<!-- -->\n<!-- -->    for (uint64_t i = 2; !fr_is_one(&amp;out[i - 1]); i++) {\n<!-- -->        CHECK(i         blst_fr_mul(&amp;out[i], &amp;out[i - 1], root);\n<!-- -->    }\n<!-- -->    CHECK(fr_is_one(&amp;out[width]));\n<!-- -->\n<!-- -->    return C_KZG_OK;\n<!-- -->}\n<!-- --><\/code><\/pre>\n<\/div>\n<p><!-- --><\/p>\n<h2 class=\"chakra-heading css-1w54o5f\" id=\"security-review\">Security Assessment<!-- --><\/h2>\n<p><!-- --><\/p>\n<p class=\"chakra-text css-gi02ar\">Once the development reaches a stable state, it is crucial to carry out thorough testing, and additionally, have your team manually scrutinize the codebase multiple times. Following this, it&#8217;s advisable to arrange a security assessment by a recognized security organization. While this won&#8217;t serve as a definitive endorsement, it indicates that your project possesses a certain level of security. It is important to remember that achieving perfect security is unattainable; there will always be potential vulnerabilities.<!-- --><\/p>\n<p><!-- --><\/p>\n<p class=\"chakra-text css-gi02ar\">For the c-kzg-4844 and go-kzg-4844 projects, the Ethereum Foundation engaged <!-- --><a target=\"_blank\" rel=\"noopener\" class=\"chakra-link css-ug8vf0\" href=\"https:\/\/sigmaprime.io\/\">Sigma Prime<!-- --><\/a> to perform a security assessment. They generated <!-- --><a target=\"_blank\" rel=\"noopener\" class=\"chakra-link css-ug8vf0\" href=\"https:\/\/github.com\/ethereum\/c-kzg-4844\/blob\/main\/doc\/audit\/Sigma_Prime_Ethereum_Foundation_KZG_Implementations_Security_Assessment.pdf\">this documentation<!-- --><\/a> which outlines 8 findings. Among these, there is one critical vulnerability identified in go-kzg-4844, which was a significant discovery. The BLS12-381 library utilized by go-kzg-4844, <!-- --><a target=\"_blank\" rel=\"noopener\" class=\"chakra-link css-ug8vf0\" href=\"https:\/\/github.com\/Consensys\/gnark-crypto\/\"><span class=\"chakra-text css-ons8vw\">gnark-crypto<\/span><\/a>, contained a flaw that permitted invalid G1 and G2 points to be decoded successfully. Should this issue not have been rectified, it might have led to a consensus problem (a disagreement among different implementations) within Ethereum.<!-- --><\/p>\n<p><!-- --><\/p>\n<h2 class=\"chakra-heading css-1w54o5f\" id=\"bug-bounty\">Bug Reward Program<!-- --><\/h2>\n<p><!-- --><\/p>\n<p class=\"chakra-text css-gi02ar\">If a weakness within your project poses the possibility of being exploited for advantage, similar to the situation with Ethereum, consider implementing a bug bounty initiative. This program enables security researchers, or indeed anyone, to report vulnerabilities in return for a financial reward. Typically, this is targeted toward findings that can demonstrate the feasibility of exploitation. If the bug bounty rewards are fair, those who identify bugs will alert you to the issue instead of leveraging it or selling it to a third party. It is advisable to launch your bug bounty initiative once the issues from the initial security assessment are addressed; ideally, the costs for the security review should be less than the payouts for the bug bounty.<!-- --><\/p>\n<p><!-- --><\/p>\n<h2 class=\"chakra-heading css-1w54o5f\" id=\"conclusion\">Final Thoughts<!-- --><\/h2>\n<p><!-- --><\/p>\n<p class=\"chakra-text css-gi02ar\">Creating robust C projects, particularly in the vital fields of blockchain and cryptocurrencies, necessitates a comprehensive strategy. Considering the intrinsic vulnerabilities associated with the C programming language, an amalgamation of best practices and tools is imperative for crafting resilient software. We trust that the insights and experiences shared from our work with c-kzg-4844 will offer valuable guidance and recommended practices for others embarking on similar endeavors.<!-- --><\/p>\n<\/div>\n<p><br \/>\n<br \/><a href=\"https:\/\/blog.ethereum.org\/en\/2023\/11\/02\/writing-robust-c\">Source link <\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>For EIP-4844, Ethereum clients must possess the capability to compute and validate KZG commitments. Instead of each client developing their own cryptographic solutions, researchers and developers collaborated to create c-kzg-4844, a comparatively compact C library featuring bindings for more advanced programming languages. The objective was to establish a sturdy and effective cryptographic library that all<\/p>\n","protected":false},"author":3,"featured_media":5124,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[23],"tags":[279],"class_list":{"0":"post-5667","1":"post","2":"type-post","3":"status-publish","4":"format-standard","5":"has-post-thumbnail","7":"category-ethereum","8":"tag-return-a-list-of-comma-separated-tags-from-this-title-secured-6-writing-robust-c-best-practices-for-finding-and-preventing-vulnerabilities"},"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Mastering Secure C Programming: Essential Techniques for Identifying and Mitigating Vulnerabilities - WSJ-Crypto<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/wsj-crypto.com\/index.php\/2024\/12\/03\/mastering-secure-c-programming-essential-techniques-for-identifying-and-mitigating-vulnerabilities\/\" \/>\n<meta property=\"og:locale\" content=\"it_IT\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Mastering Secure C Programming: Essential Techniques for Identifying and Mitigating Vulnerabilities - WSJ-Crypto\" \/>\n<meta property=\"og:description\" content=\"For EIP-4844, Ethereum clients must possess the capability to compute and validate KZG commitments. Instead of each client developing their own cryptographic solutions, researchers and developers collaborated to create c-kzg-4844, a comparatively compact C library featuring bindings for more advanced programming languages. The objective was to establish a sturdy and effective cryptographic library that all\" \/>\n<meta property=\"og:url\" content=\"https:\/\/wsj-crypto.com\/index.php\/2024\/12\/03\/mastering-secure-c-programming-essential-techniques-for-identifying-and-mitigating-vulnerabilities\/\" \/>\n<meta property=\"og:site_name\" content=\"WSJ-Crypto\" \/>\n<meta property=\"article:published_time\" content=\"2024-12-03T22:30:19+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/wsj-crypto.com\/wp-content\/uploads\/2024\/11\/eth-org.jpeg\" \/>\n\t<meta property=\"og:image:width\" content=\"2100\" \/>\n\t<meta property=\"og:image:height\" content=\"900\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"wsjcrypto\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Scritto da\" \/>\n\t<meta name=\"twitter:data1\" content=\"wsjcrypto\" \/>\n\t<meta name=\"twitter:label2\" content=\"Tempo di lettura stimato\" \/>\n\t<meta name=\"twitter:data2\" content=\"12 minuti\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/wsj-crypto.com\/index.php\/2024\/12\/03\/mastering-secure-c-programming-essential-techniques-for-identifying-and-mitigating-vulnerabilities\/\",\"url\":\"https:\/\/wsj-crypto.com\/index.php\/2024\/12\/03\/mastering-secure-c-programming-essential-techniques-for-identifying-and-mitigating-vulnerabilities\/\",\"name\":\"Mastering Secure C Programming: Essential Techniques for Identifying and Mitigating Vulnerabilities - WSJ-Crypto\",\"isPartOf\":{\"@id\":\"https:\/\/wsj-crypto.com\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/wsj-crypto.com\/index.php\/2024\/12\/03\/mastering-secure-c-programming-essential-techniques-for-identifying-and-mitigating-vulnerabilities\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/wsj-crypto.com\/index.php\/2024\/12\/03\/mastering-secure-c-programming-essential-techniques-for-identifying-and-mitigating-vulnerabilities\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/wsj-crypto.com\/wp-content\/uploads\/2024\/11\/eth-org.jpeg\",\"datePublished\":\"2024-12-03T22:30:19+00:00\",\"author\":{\"@id\":\"https:\/\/wsj-crypto.com\/#\/schema\/person\/88a93723b30416db1a352d5a0096c4a7\"},\"breadcrumb\":{\"@id\":\"https:\/\/wsj-crypto.com\/index.php\/2024\/12\/03\/mastering-secure-c-programming-essential-techniques-for-identifying-and-mitigating-vulnerabilities\/#breadcrumb\"},\"inLanguage\":\"it-IT\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/wsj-crypto.com\/index.php\/2024\/12\/03\/mastering-secure-c-programming-essential-techniques-for-identifying-and-mitigating-vulnerabilities\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"it-IT\",\"@id\":\"https:\/\/wsj-crypto.com\/index.php\/2024\/12\/03\/mastering-secure-c-programming-essential-techniques-for-identifying-and-mitigating-vulnerabilities\/#primaryimage\",\"url\":\"https:\/\/wsj-crypto.com\/wp-content\/uploads\/2024\/11\/eth-org.jpeg\",\"contentUrl\":\"https:\/\/wsj-crypto.com\/wp-content\/uploads\/2024\/11\/eth-org.jpeg\",\"width\":2100,\"height\":900},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/wsj-crypto.com\/index.php\/2024\/12\/03\/mastering-secure-c-programming-essential-techniques-for-identifying-and-mitigating-vulnerabilities\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/wsj-crypto.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Mastering Secure C Programming: Essential Techniques for Identifying and Mitigating Vulnerabilities\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/wsj-crypto.com\/#website\",\"url\":\"https:\/\/wsj-crypto.com\/\",\"name\":\"WSJ-Crypto\",\"description\":\"Just Another Crypto News Website\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/wsj-crypto.com\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"it-IT\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/wsj-crypto.com\/#\/schema\/person\/88a93723b30416db1a352d5a0096c4a7\",\"name\":\"wsjcrypto\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"it-IT\",\"@id\":\"https:\/\/wsj-crypto.com\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/86fe8af82ea089646d6639ca2f87e0243d8688d957bd8e3ec22ec3c457cc16d4?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/86fe8af82ea089646d6639ca2f87e0243d8688d957bd8e3ec22ec3c457cc16d4?s=96&d=mm&r=g\",\"caption\":\"wsjcrypto\"},\"url\":\"https:\/\/wsj-crypto.com\/index.php\/author\/wsjcrypto\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Mastering Secure C Programming: Essential Techniques for Identifying and Mitigating Vulnerabilities - WSJ-Crypto","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/wsj-crypto.com\/index.php\/2024\/12\/03\/mastering-secure-c-programming-essential-techniques-for-identifying-and-mitigating-vulnerabilities\/","og_locale":"it_IT","og_type":"article","og_title":"Mastering Secure C Programming: Essential Techniques for Identifying and Mitigating Vulnerabilities - WSJ-Crypto","og_description":"For EIP-4844, Ethereum clients must possess the capability to compute and validate KZG commitments. Instead of each client developing their own cryptographic solutions, researchers and developers collaborated to create c-kzg-4844, a comparatively compact C library featuring bindings for more advanced programming languages. The objective was to establish a sturdy and effective cryptographic library that all","og_url":"https:\/\/wsj-crypto.com\/index.php\/2024\/12\/03\/mastering-secure-c-programming-essential-techniques-for-identifying-and-mitigating-vulnerabilities\/","og_site_name":"WSJ-Crypto","article_published_time":"2024-12-03T22:30:19+00:00","og_image":[{"width":2100,"height":900,"url":"https:\/\/wsj-crypto.com\/wp-content\/uploads\/2024\/11\/eth-org.jpeg","type":"image\/jpeg"}],"author":"wsjcrypto","twitter_card":"summary_large_image","twitter_misc":{"Scritto da":"wsjcrypto","Tempo di lettura stimato":"12 minuti"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/wsj-crypto.com\/index.php\/2024\/12\/03\/mastering-secure-c-programming-essential-techniques-for-identifying-and-mitigating-vulnerabilities\/","url":"https:\/\/wsj-crypto.com\/index.php\/2024\/12\/03\/mastering-secure-c-programming-essential-techniques-for-identifying-and-mitigating-vulnerabilities\/","name":"Mastering Secure C Programming: Essential Techniques for Identifying and Mitigating Vulnerabilities - WSJ-Crypto","isPartOf":{"@id":"https:\/\/wsj-crypto.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/wsj-crypto.com\/index.php\/2024\/12\/03\/mastering-secure-c-programming-essential-techniques-for-identifying-and-mitigating-vulnerabilities\/#primaryimage"},"image":{"@id":"https:\/\/wsj-crypto.com\/index.php\/2024\/12\/03\/mastering-secure-c-programming-essential-techniques-for-identifying-and-mitigating-vulnerabilities\/#primaryimage"},"thumbnailUrl":"https:\/\/wsj-crypto.com\/wp-content\/uploads\/2024\/11\/eth-org.jpeg","datePublished":"2024-12-03T22:30:19+00:00","author":{"@id":"https:\/\/wsj-crypto.com\/#\/schema\/person\/88a93723b30416db1a352d5a0096c4a7"},"breadcrumb":{"@id":"https:\/\/wsj-crypto.com\/index.php\/2024\/12\/03\/mastering-secure-c-programming-essential-techniques-for-identifying-and-mitigating-vulnerabilities\/#breadcrumb"},"inLanguage":"it-IT","potentialAction":[{"@type":"ReadAction","target":["https:\/\/wsj-crypto.com\/index.php\/2024\/12\/03\/mastering-secure-c-programming-essential-techniques-for-identifying-and-mitigating-vulnerabilities\/"]}]},{"@type":"ImageObject","inLanguage":"it-IT","@id":"https:\/\/wsj-crypto.com\/index.php\/2024\/12\/03\/mastering-secure-c-programming-essential-techniques-for-identifying-and-mitigating-vulnerabilities\/#primaryimage","url":"https:\/\/wsj-crypto.com\/wp-content\/uploads\/2024\/11\/eth-org.jpeg","contentUrl":"https:\/\/wsj-crypto.com\/wp-content\/uploads\/2024\/11\/eth-org.jpeg","width":2100,"height":900},{"@type":"BreadcrumbList","@id":"https:\/\/wsj-crypto.com\/index.php\/2024\/12\/03\/mastering-secure-c-programming-essential-techniques-for-identifying-and-mitigating-vulnerabilities\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/wsj-crypto.com\/"},{"@type":"ListItem","position":2,"name":"Mastering Secure C Programming: Essential Techniques for Identifying and Mitigating Vulnerabilities"}]},{"@type":"WebSite","@id":"https:\/\/wsj-crypto.com\/#website","url":"https:\/\/wsj-crypto.com\/","name":"WSJ-Crypto","description":"Just Another Crypto News Website","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/wsj-crypto.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"it-IT"},{"@type":"Person","@id":"https:\/\/wsj-crypto.com\/#\/schema\/person\/88a93723b30416db1a352d5a0096c4a7","name":"wsjcrypto","image":{"@type":"ImageObject","inLanguage":"it-IT","@id":"https:\/\/wsj-crypto.com\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/86fe8af82ea089646d6639ca2f87e0243d8688d957bd8e3ec22ec3c457cc16d4?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/86fe8af82ea089646d6639ca2f87e0243d8688d957bd8e3ec22ec3c457cc16d4?s=96&d=mm&r=g","caption":"wsjcrypto"},"url":"https:\/\/wsj-crypto.com\/index.php\/author\/wsjcrypto\/"}]}},"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/wsj-crypto.com\/index.php\/wp-json\/wp\/v2\/posts\/5667","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/wsj-crypto.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/wsj-crypto.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/wsj-crypto.com\/index.php\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/wsj-crypto.com\/index.php\/wp-json\/wp\/v2\/comments?post=5667"}],"version-history":[{"count":2,"href":"https:\/\/wsj-crypto.com\/index.php\/wp-json\/wp\/v2\/posts\/5667\/revisions"}],"predecessor-version":[{"id":5669,"href":"https:\/\/wsj-crypto.com\/index.php\/wp-json\/wp\/v2\/posts\/5667\/revisions\/5669"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/wsj-crypto.com\/index.php\/wp-json\/wp\/v2\/media\/5124"}],"wp:attachment":[{"href":"https:\/\/wsj-crypto.com\/index.php\/wp-json\/wp\/v2\/media?parent=5667"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/wsj-crypto.com\/index.php\/wp-json\/wp\/v2\/categories?post=5667"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/wsj-crypto.com\/index.php\/wp-json\/wp\/v2\/tags?post=5667"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}