MynaWallet / monorepo

15 stars 4 forks source link

UnitTest Failed in Test Case `testDeploy` #23

Closed sakuyacatcat closed 8 months ago

sakuyacatcat commented 8 months ago

What command(s) is the bug in?

cd packages/contracts && forge test -vv

Describe the bug

Current Situation

On develop branch In this repo, unittest failed as the following log. This happened not only my local env. @susumutomita encountered the same situation.

> forge test -vv
[⠒] Compiling...
No files changed, compilation skipped

Running 6 tests for test/libraries/RsaVerify.t.sol:TestRsaVerify
[PASS] test_FailRsaVerify() (gas: 327914)
[PASS] test_ShouldHaveProperPrefix() (gas: 268369)
[PASS] test_ShouldHaveValidDelimiter() (gas: 327585)
[PASS] test_ShouldHaveValidPadding() (gas: 317988)
[PASS] test_ShouldUseProperSHA256DEREncoding() (gas: 327671)
[PASS] test_SuccessRsaVerify() (gas: 327778)
Test result: ok. 6 passed; 0 failed; 0 skipped; finished in 733.96µs

Running 1 test for test/deploy/deploy.t.sol:DeployTest
[FAIL. Reason: FailedOp(0, AA23 reverted: Invalid input!)] testDeploy() (gas: 419128)
Logs:
  0xcc30b4b050cf1525f704f55e914a3d1909fc3f1ae88a2edde5d60287f8feea9b

Test result: FAILED. 0 passed; 1 failed; 0 skipped; finished in 1.48ms

Ran 2 test suites: 6 tests passed, 1 failed, 0 skipped (7 total tests)

Failing tests:
Encountered 1 failing test in test/deploy/deploy.t.sol:DeployTest
[FAIL. Reason: FailedOp(0, AA23 reverted: Invalid input!)] testDeploy() (gas: 419128)

Encountered a total of 1 failing tests, 6 tests succeeded

But on develop branch in the past contracts repo, unittest passed.

> forge test -vv
[⠒] Compiling...
No files changed, compilation skipped

Running 6 tests for test/libraries/RsaVerify.t.sol:TestRsaVerify
[PASS] test_FailRsaVerify() (gas: 327914)
[PASS] test_ShouldHaveProperPrefix() (gas: 268369)
[PASS] test_ShouldHaveValidDelimiter() (gas: 327585)
[PASS] test_ShouldHaveValidPadding() (gas: 317988)
[PASS] test_ShouldUseProperSHA256DEREncoding() (gas: 327671)
[PASS] test_SuccessRsaVerify() (gas: 327778)
Test result: ok. 6 passed; 0 failed; 0 skipped; finished in 734.88µs

Running 1 test for test/deploy/deploy.t.sol:DeployTest
[PASS] testDeploy() (gas: 848136)
Logs:
  0xcc30b4b050cf1525f704f55e914a3d1909fc3f1ae88a2edde5d60287f8feea9b

Test result: ok. 1 passed; 0 failed; 0 skipped; finished in 1.84ms

Ran 2 test suites: 7 tests passed, 0 failed, 0 skipped (7 total tests)

Revealed Fact

Inconsistencies between the develop branches of two repositories: myna-wallet-monorepo and contracts.

Comparison results

Here are the results from comparing key directories of the contracts code in both repositories.

Scripts:

> diff -r myna-wallet-monorepo/packages/contracts/script/ contracts/script/
Only in myna-wallet-monorepo/packages/contracts/script: bump-solidity.js

Source Codes:

> diff -r myna-wallet-monorepo/packages/contracts/src/ contracts/src/
diff -r myna-wallet-monorepo/packages/contracts/src/base/MynaWallet.sol contracts/src/base/MynaWallet.sol
14d13
< import { IRsaVerifier } from "../interfaces/IRsaVerifier.sol";
31,32d29
<     address constant RSA_VERIFIER_ADDRESS = 0xE042A2524DF80121dD25B40D1749D39dC34B27FF;
<
168,219c165,167
<         uint256 hashedInU256 = uint256(hashed);
<         (uint[2] memory _pA, uint[2][2] memory _pB, uint[2] memory _pC, uint[21] memory _pubSignals) = parseBytesToVerifierInput(userOp.signature);
<         require(_pubSignals[20] == hashedInU256, "Invalid user");
<         bool ret = IRsaVerifier(RSA_VERIFIER_ADDRESS).verifyProof(
<             _pA,
<             _pB,
<             _pC,
<             _pubSignals
<         );
<         if (!ret) return SIG_VALIDATION_FAILED;
<     }
<
<     function parseBytesToVerifierInput(bytes memory bytesData)
<         internal
<         pure
<         returns (uint[2] memory _pA, uint[2][2] memory _pB, uint[2] memory _pC, uint[21] memory _pubSignals)
<     {
<         require(bytesData.length == 928, "Invalid input!");
<         uint cnt = 0;
<         for (uint i = 0; i < 2; i++) {
<             _pA[i] = sliceUint(bytesData, cnt * 32);
<             cnt ++;
<         }
<
<         for (uint i = 0; i < 2; i++) {
<             for (uint j = 0; j < 2; j++) {
<                 _pB[i][j] = sliceUint(bytesData, cnt * 32);
<                 cnt ++;
<             }
<         }
<
<         for (uint i = 0; i < 2; i++) {
<             _pC[i] = sliceUint(bytesData, cnt * 32);
<             cnt ++;
<         }
<
<         for (uint i = 0; i < 21; i++) {
<             _pubSignals[i] = sliceUint(bytesData, cnt * 32);
<             cnt ++;
<         }
<     }
<
<     function sliceUint(bytes memory bs, uint start)
<         internal pure
<         returns (uint)
<     {
<         require(bs.length >= start + 32, "slicing out of range");
<         uint x;
<         assembly {
<             x := mload(add(bs, add(0x20, start)))
<         }
<         return x;
---
>         (bytes memory modulus, bytes memory exponent) = getOwner();
>         uint256 ret = verifyPkcs1Sha256(hashed, userOp.signature, exponent, modulus);
>         if (ret != 0) return SIG_VALIDATION_FAILED;
Only in myna-wallet-monorepo/packages/contracts/src/base: RsaVerifier.sol
Only in myna-wallet-monorepo/packages/contracts/src: circom-verifier
Only in myna-wallet-monorepo/packages/contracts/src: interfaces

Tests:

> diff -r myna-wallet-monorepo/packages/contracts/test/ contracts/test/
Only in contracts/test: base

Concrete steps to reproduce the bug. If it's able reproduce via testool, please share test_id from jenkins report

hiroism007 commented 8 months ago

@sakuyacatcat

.@motemotech inadvertently pushed his local development branch to the remote develop branch. I have since rolled back his changes, and our tests are now running successfully. Thank you for bringing this to our attention!

sakuyacatcat commented 8 months ago

I confirmed all test cases passed green, so I close this issue.

> forge test -vvv
[⠒] Compiling...
No files changed, compilation skipped

Running 6 tests for test/libraries/RsaVerify.t.sol:TestRsaVerify
[PASS] test_FailRsaVerify() (gas: 327914)
[PASS] test_ShouldHaveProperPrefix() (gas: 268369)
[PASS] test_ShouldHaveValidDelimiter() (gas: 327585)
[PASS] test_ShouldHaveValidPadding() (gas: 317988)
[PASS] test_ShouldUseProperSHA256DEREncoding() (gas: 327671)
[PASS] test_SuccessRsaVerify() (gas: 327778)
Test result: ok. 6 passed; 0 failed; 0 skipped; finished in 693.17µs

Running 1 test for test/deploy/deploy.t.sol:DeployTest
[PASS] testDeploy() (gas: 848136)
Logs:
  0xcc30b4b050cf1525f704f55e914a3d1909fc3f1ae88a2edde5d60287f8feea9b

Test result: ok. 1 passed; 0 failed; 0 skipped; finished in 1.81ms

Ran 2 test suites: 7 tests passed, 0 failed, 0 skipped (7 total tests)

Prevent this situation, create another issue #27 to introduce cicd to contracts directory.