-
Notifications
You must be signed in to change notification settings - Fork 285
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
fix(connector-quorum/ethereum): strengthen contract parameter validation #2854
Conversation
@petermetz I was not able to test the changes. I was following these two documentation How should I test these changes I made? This is the steps i followed for compiling packages
Regarding the code, the arguments are passed through the request body as it retrieved in the |
This comment was marked as outdated.
This comment was marked as outdated.
@shivam-Purohit Thank you very much for taking the time to read the documentation in detail! You can run that test file by doing Now some pointers on how to get this done:
|
82d017d
to
b2c7d0d
Compare
Thanks @petermetz for that detailed explanation. Sorry though I messed up with the other branch in merge conflicts. So I created new and forced push. I did the following things like you suggested
A CI test is failing though and I don't know the reason why. Am I missing something? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- I sent a suggestion (see comment above with the diff).
- Before you even look at the suggestion, what I would do is rebase your branch onto upstream/main because the build right now is broken on the old code)
- Then you can apply the suggestions I made one by one. Here are some more details explaining the suggestions themselves:
3.1. Add the ethers package in the specific pakcage.json of the connector plugin not in the root package.json (this is a mono repo so there are dozens of packages in it and the root is only there to hold development tooling/ dev dependencies for the build itself)
3.2. Update the import of the ethers package so that it'simport type { ... }
instead ofimport { ... }
because this way we don't need to actually haveethers
as adependency
in the package.json, it is enough to have it as adevDependency
which is better because it reduces the production code's footprint (bundle/install size in general). There is much more/better explanation provided on this link to the why: https://stackoverflow.com/a/64243357
3.3. Apply the automatic formatter (prettier/eslint)- With doing all the above you should arrive at a point where the PR is close to being done, but then I'll also ask that you update the ethereum connector plugin as well (exact same changes for the most part), which can be tested by executing this other test file:
packages/cactus-plugin-ledger-connector-ethereum/src/test/typescript/integration/geth-invoke-web3-contract-v1.test.ts
Thanks @petermetz for that detailed explanation. Sorry though I messed up with the other branch in merge conflicts. So I created new and forced push. I did the following things like you suggested
1. rebased onto remote/main 2. added ethers dev dependencies for the `cactus-plugin-ledger-connector-ethereum` and `cactus-plugin-ledger-connector-quorum ` packages. I added using `--dev `flag so its added in devDependencies 3. used typed import 4. tested both the files. 5. ran lint and prettier
A CI test is failing though and I don't know the reason why. Am I missing something?
@shivam-Purohit Sorry for the slow response! Some of the tests are unfortunately in a failing state currently as we are working our way through clearing the backlog for the v2.0.0 release. Please let me know which specific tests you are talking about and also you can compare the main branches CI execution results to the ones on your PR and see if they were failing to begin with on the main branch (in which case you can know for sure that you didn't break the those specific tests and then it should be OK)
If it turns out that you did break some test cases then I need to know exactly which ones and then I can give more targeted help.
In the meantime, please make sure not to delete your branch and not to close the PR because we already have the review history here so new branches won't work. If you struggle with the git operations to get all this done let me know and I can help with that too.
Right now it is looking like you still need to squash 4 different commits into one but that can be done later too if you prefer to do it that way (everybody's git workflows are slightly different)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@shivam-Purohit Please also make sure not to use any auto-upgrade syntax when specifying npm dependency versions. It is a security risk (software supply chain attacks)
...nnector-ethereum/src/main/typescript/web-services/invoke-raw-web3eth-contract-v1-endpoint.ts
Outdated
Show resolved
Hide resolved
sure I was also busy with my college exams. I will check with the tests thing you mentioned and I will squash the commits when we are done with the PR. |
noted! |
hey @petermetz @outSH
I am wrong somewhere or we need to modify the tests or add new for checking this. |
@shivam-Purohit Thank you for working on this and also for being receptive to feedback/change requests! For the failing tests: Please let make it so that we can reproduce the test case failure locally on our own machines as well and then we can offer more targeted help. E.g., push your latest changes to your branch, send us a link of that branch and then the instructions of how were you exactly running the test case to get what exact log output. |
f417cbb
to
3c3a233
Compare
@petermetz I think I got what the problem was. From abi we suppose we get the inputs and types for the |
@shivam-Purohit Do you have any blocking issues / more questions to be addressed regarding this PR? |
currently one workflow is failing Other than that I don't think I have any other questions. |
3c3a233
to
da7ef0a
Compare
da7ef0a
to
407bcf4
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@shivam-Purohit I've added a test case to verify that the validation works as expected and also did some refactoring on the error handling itself so that it isn't a security issue anymore (it was reporting HTTP 500 statuses for user errors which should respond with HTTP 4xx)
With all that and with your improvements together: LGTM
args.invocationType | ||
](args.invocationParams); | ||
const txObjectFactory = contract.methods[args.contractMethod]; | ||
const txObject = txObjectFactory(...contractMethodArgs); |
Check failure
Code scanning / CodeQL
Unvalidated dynamic method call High
user-controlled
Thanks a lot. Hope this works! |
@shivam-Purohit Have you hit the 're-request review' button to ping @outSH to check on this again? If not, I recommend doing it so that he has a chance to take another look at the chances you've made. |
@shivam-Purohit Please rebase with main and re-request the review as Peter pointed out, and we can merge it right away. Everything looks good, thank you very much for this contribution! :) |
sorry It slipped my mind I thought the repo was busy. |
sure! |
407bcf4
to
32e87d0
Compare
@shivam-Purohit FYI: That didn't work but I rebased it for you, no worries. |
@shivam-Purohit No worries! It gets complicated sometimes but we do want to make sure that your PR gets merged as much as all the other ones! I recommend hitting that re-request review button for @outSH once again to pass the proverbial ball back . |
Thats a very handy trick, that sure will be very helpful for me in future, thanks a lot! |
@petermetz Was the rebase successful, it says that this branch still has conflicts? should i try to rebase? |
@shivam-Purohit |
Peter's updates: 1. Made improvements to the test case verifying that the parameters with incorrect types are indeed being rejected with useful error messaging 2. Added a new library (which I also had to re-publish with CJS exports) Fixes hyperledger-cacti#2760 Signed-off-by: Shivam Purohit <[email protected]> Signed-off-by: Peter Somogyvari <[email protected]>
32e87d0
to
f299b48
Compare
@outSH @shivam-Purohit FYI I just rebased it! |
Peter's updates:
incorrect types are indeed being rejected with useful error messaging
Fixes #2760
Signed-off-by: Shivam Purohit [email protected]
Signed-off-by: Peter Somogyvari [email protected]
Pull Request Requirements
upstream/main
branch and squashed into single commit to help maintainers review it more efficient and to avoid spaghetti git commit graphs that obfuscate which commit did exactly what change, when and, why.-s
flag when usinggit commit
command. You may refer to this link for more information.Character Limit
A Must Read for Beginners
For rebasing and squashing, here's a must read guide for beginners.