Skip to content

Commit

Permalink
♻️ Use Native publicKey256 Cheat Code (#269)
Browse files Browse the repository at this point in the history
### 🕓 Changelog

The Foundry PR [#8679](foundry-rs/foundry#8679)
and `forge-std` PR
[#596](foundry-rs/forge-std#596) introduced a
native `publicKey256` cheat code to derive the public key coordinates
based on the `secp256r1` curve from a random `uint256` private key. As a
result, I refactor the `p256` test and remove the now redundant
[`FreshCryptoLib`](https://github.com/rdubois-crypto/FreshCryptoLib)
submodule from the codebase.

---------
Signed-off-by: Pascal Marco Caversaccio <[email protected]>
  • Loading branch information
pcaversaccio authored Aug 27, 2024
1 parent 1acec74 commit dc2c12b
Show file tree
Hide file tree
Showing 12 changed files with 69 additions and 78 deletions.
128 changes: 64 additions & 64 deletions .gas-snapshot

Large diffs are not rendered by default.

3 changes: 0 additions & 3 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,6 @@
[submodule "lib/erc4626-tests"]
path = lib/erc4626-tests
url = https://github.com/a16z/erc4626-tests.git
[submodule "lib/FreshCryptoLib"]
path = lib/FreshCryptoLib
url = https://github.com/rdubois-crypto/FreshCryptoLib.git
[submodule "lib/halmos-cheatcodes"]
path = lib/halmos-cheatcodes
url = https://github.com/a16z/halmos-cheatcodes.git
Expand Down
1 change: 0 additions & 1 deletion .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ lib/forge-std
lib/properties
lib/create-util
lib/erc4626-tests
lib/FreshCryptoLib
lib/halmos-cheatcodes
lib/solidity-bytes-utils
lib/openzeppelin-contracts
Expand Down
1 change: 0 additions & 1 deletion .solhintignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ lib/forge-std
lib/properties
lib/create-util
lib/erc4626-tests
lib/FreshCryptoLib
lib/halmos-cheatcodes
lib/solidity-bytes-utils
lib/openzeppelin-contracts
Expand Down
1 change: 0 additions & 1 deletion eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ module.exports = [
"lib/properties/**",
"lib/create-util/**",
"lib/erc4626-tests/**",
"lib/FreshCryptoLib/**",
"lib/halmos-cheatcodes/**",
"lib/solidity-bytes-utils/**",
"lib/openzeppelin-contracts/**",
Expand Down
1 change: 0 additions & 1 deletion lib/FreshCryptoLib
Submodule FreshCryptoLib deleted from be47b0
2 changes: 1 addition & 1 deletion lib/create-util
Submodule create-util updated 2 files
+2 −2 package.json
+58 −71 pnpm-lock.yaml
2 changes: 1 addition & 1 deletion lib/forge-std
Submodule forge-std updated 2 files
+10 −0 src/Vm.sol
+1 −1 test/Vm.t.sol
2 changes: 1 addition & 1 deletion lib/halmos-cheatcodes
Submodule halmos-cheatcodes updated 1 files
+3 −0 src/SVM.sol
2 changes: 1 addition & 1 deletion lib/solady
1 change: 0 additions & 1 deletion remappings.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,5 @@ erc4626-tests/=lib/erc4626-tests/
properties/=lib/properties/contracts/
create-util/=lib/create-util/contracts/
halmos-cheatcodes/=lib/halmos-cheatcodes/src/
fresh-crypto-lib=lib/FreshCryptoLib/solidity/src/
openzeppelin/=lib/openzeppelin-contracts/contracts/
solidity-bytes-utils/=lib/solidity-bytes-utils/contracts/
3 changes: 1 addition & 2 deletions test/utils/P256.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import {stdJson} from "forge-std/StdJson.sol";
import {VyperDeployer} from "utils/VyperDeployer.sol";

import {BytesLib} from "solidity-bytes-utils/BytesLib.sol";
import {FCL_ecdsa_utils} from "fresh-crypto-lib/FCL_ecdsa_utils.sol";

import {IP256} from "./interfaces/IP256.sol";

Expand Down Expand Up @@ -147,7 +146,7 @@ contract P256Test is Test {
key = bound(key, 1, _N - 1);
bytes32 hash = keccak256(abi.encode(message));
(bytes32 r, bytes32 s) = vm.signP256(key, hash);
(uint256 qx, uint256 qy) = FCL_ecdsa_utils.ecdsa_derivKpub(key);
(uint256 qx, uint256 qy) = vm.publicKeyP256(key);
if (uint256(s) <= _MALLEABILITY_THRESHOLD) {
assertTrue(P256.verify_sig(hash, uint256(r), uint256(s), qx, qy));
} else {
Expand Down

0 comments on commit dc2c12b

Please sign in to comment.