Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

⚰️ remove the code related to the precomputed variant #16

Merged
merged 2 commits into from
Nov 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/secp256r1-verify
24 changes: 0 additions & 24 deletions src/WebAuthn256r1.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
pragma solidity >=0.8.19 <0.9.0;

import { ECDSA256r1 } from "../lib/secp256r1-verify/src/ECDSA256r1.sol";
import { ECDSA256r1Precompute } from "../lib/secp256r1-verify/src/ECDSA256r1Precompute.sol";
import { WebAuthnBase } from "./WebAuthnBase.sol";

/// @title WebAuthn256r1
Expand Down Expand Up @@ -32,27 +31,4 @@ contract WebAuthn256r1 is WebAuthnBase {
return ECDSA256r1.verify(message, r, s, qx, qy);
}
}

/// @notice Verify ECDSA signature though WebAuthn on the secp256r1 curve using a precomputed table
function verify(
bytes1 authenticatorDataFlagMask,
bytes calldata authenticatorData,
bytes calldata clientData,
bytes calldata clientChallenge,
uint256 clientChallengeOffset,
uint256 r,
uint256 s,
address precomputedTable
)
external
returns (bool)
{
unchecked {
bytes32 message = generateMessage(
authenticatorDataFlagMask, authenticatorData, clientData, clientChallenge, clientChallengeOffset
);

return ECDSA256r1Precompute.verify(message, r, s, precomputedTable);
}
}
}
75 changes: 0 additions & 75 deletions test/WebAuthn256r1.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -39,78 +39,3 @@ contract ContractTestVerify is Test {
);
}
}

contract ContractTestVerifyPrecomputation is Test {
WebAuthn256r1 internal implem;
// the address where the the precomputed table will live
address private precomputeAddress;

function setUp() external {
implem = new WebAuthn256r1();
precomputeAddress = vm.addr(42);
}

/// @notice precumpute a shamir table of 256 points for a given pubKey
/// @dev this function execute a JS package listed in the package.json file
/// @param qx the x coordinate of the public key
/// @param qy the y coordinate of the public key
/// @return precompute the precomputed table as a bytes
function _precomputeShamirTable(uint256 qx, uint256 qy) private returns (bytes memory precompute) {
// Precompute a 8 dimensional table for Shamir's trick from c0 and c1
// and return the table as a bytes
string[] memory inputs = new string[](4);
inputs[0] = "npx";
inputs[1] = "@0x90d2b2b7fb7599eebb6e7a32980857d8/secp256r1-computation";
inputs[2] = vm.toString(qx);
inputs[3] = vm.toString(qy);
precompute = vm.ffi(inputs);
}

/// @notice Modifier for generating the precomputed table and storing it in the precompiled contract
/// @dev Uses the `_precomputeShamirTable(<qx>,<qy>)` function to generate the precomputed table
modifier _preparePrecomputeTable(uint256 qx, uint256 qy) {
// generate the precomputed table
bytes memory precompute = _precomputeShamirTable(qx, qy);

// set the precomputed points as the bytecode of the target contract
vm.etch(precomputeAddress, precompute);

// run the test
_;

// unset the bytecode of the target contract
vm.etch(precomputeAddress, hex"00");
}

function test_VerifyPrecomput()
public
_preparePrecomputeTable(
114_874_632_398_302_156_264_159_990_279_427_641_021_947_882_640_101_801_130_664_833_947_273_521_181_002,
32_136_952_818_958_550_240_756_825_111_900_051_564_117_520_891_182_470_183_735_244_184_006_536_587_423
)
{
assertTrue(
implem.verify(
// authenticatorDataFlagMask
0x01,
// authenticatorData
hex"f8e4b678e1c62f7355266eaa4dc1148573440937063a46d848da1e25babbd20b010000004d",
// clientData
hex"7b2274797065223a22776562617574686e2e676574222c226368616c6c656e67"
hex"65223a224e546f2d3161424547526e78786a6d6b61544865687972444e583369"
hex"7a6c7169316f776d4f643955474a30222c226f726967696e223a226874747073"
hex"3a2f2f66726573682e6c65646765722e636f6d222c2263726f73734f726967696e223a66616c73657d",
// clientChallenge
hex"353a3ed5a0441919f1c639a46931de872ac3357de2ce5aa2d68c2639df54189d",
// clientChallengeOffset
0x24,
// r
45_847_212_378_479_006_099_766_816_358_861_726_414_873_720_355_505_495_069_909_394_794_949_093_093_607,
// s
55_835_259_151_215_769_394_881_684_156_457_977_412_783_812_617_123_006_733_908_193_526_332_337_539_398,
// address where the precompute table lives
precomputeAddress
)
);
}
}
Loading