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

feat: transaction with CONTRACT_NEGATIVE_VALUE breaks some routes #3387

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

natanasow
Copy link
Collaborator

@natanasow natanasow commented Jan 14, 2025

Description:

It seems like eth_getBlockByNumber fails because one of the transactions in the block was a CONTRACT_NEGATIVE_VALUE failure. The expectation is for the block to be successfully returned.

Steps to reproduce:

  1. call eth_getBlockByNumber on block 73298898
  2. see "Error invoking RPC: Invalid value - cannot pass negative number" response

The problematic transaction is here

Related issue(s):

Fixes #3367

Notes for reviewer:

Checklist

  • Documented (Code comments, README, etc.)
  • Tested (unit, integration, etc.)

Signed-off-by: nikolay <n.atanasow94@gmail.com>
@natanasow natanasow self-assigned this Jan 14, 2025
@natanasow natanasow added the bug Something isn't working label Jan 14, 2025
@natanasow natanasow added this to the 0.65.0 milestone Jan 14, 2025
Copy link

github-actions bot commented Jan 14, 2025

Test Results

 18 files   -   7  236 suites   - 151   32m 48s ⏱️ - 40m 17s
612 tests  -   3  608 ✅ + 18  4 💤 ±0  0 ❌  - 21 
628 runs   - 410  624 ✅  - 384  4 💤  - 1  0 ❌  - 25 

Results for commit c17f02a. ± Comparison against base commit 67b61c6.

This pull request removes 3 tests.
"after all" hook for "@release should execute "eth_estimateGas" for contract call, using a standard websocket" ‑ RPC Server Acceptance Tests Acceptance tests @web-socket-batch-1 eth_estimateGas "after all" hook for "@release should execute "eth_estimateGas" for contract call, using a standard websocket"
"after all" hook in "RPC Server Acceptance Tests" ‑ RPC Server Acceptance Tests "after all" hook in "RPC Server Acceptance Tests"
"before each" hook for "should execute "eth_getStorageAt" request to get current state changes" ‑ RPC Server Acceptance Tests Acceptance tests @api-batch-2 RPC Server Acceptance Tests "before each" hook for "should execute "eth_getStorageAt" request to get current state changes"

♻️ This comment has been updated with latest results.

Signed-off-by: nikolay <n.atanasow94@gmail.com>
Signed-off-by: nikolay <n.atanasow94@gmail.com>
@natanasow natanasow marked this pull request as ready for review January 14, 2025 15:55
@natanasow natanasow requested review from a team as code owners January 14, 2025 15:55
@natanasow natanasow requested a review from stoyanov-st January 14, 2025 15:55
Signed-off-by: nikolay <n.atanasow94@gmail.com>
Copy link

Copy link

codecov bot commented Jan 15, 2025

Codecov Report

Attention: Patch coverage is 41.66667% with 7 lines in your changes missing coverage. Please review.

Project coverage is 84.77%. Comparing base (67b61c6) to head (c17f02a).
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
packages/relay/src/formatters.ts 41.66% 5 Missing and 2 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3387      +/-   ##
==========================================
- Coverage   84.87%   84.77%   -0.11%     
==========================================
  Files          69       69              
  Lines        4742     4750       +8     
  Branches     1067     1069       +2     
==========================================
+ Hits         4025     4027       +2     
- Misses        400      405       +5     
- Partials      317      318       +1     
Flag Coverage Δ
config-service 98.14% <ø> (ø)
relay 79.56% <ø> (ø)
server 83.28% <ø> (ø)
ws-server 36.66% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
packages/relay/src/formatters.ts 63.97% <41.66%> (-2.04%) ⬇️

Copy link
Member

@quiet-node quiet-node left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work overall. Blocking as one warning needed to be addressed.

Also, is it feasible to add an e2e test to avoid regression?

@@ -265,6 +266,33 @@ const nanOrNumberTo0x = (input: number | BigNumber | bigint | null): string => {
return input == null || Number.isNaN(input) ? numberTo0x(0) : numberTo0x(input);
};

const nanOrNumberInt64To0x = (input: number | BigNumber | bigint | null): string => {
if (input && input < 0) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This got a warning

Operator '<' cannot be applied to types 'number | bigint | BigNumber' and 'number'.ts(2365)

Comment on lines +271 to +288
// the hex of a negative number can be obtained from the binary value of that number positive value
// the binary value needs to be negated and then to be incremented by 1

// how the transformation works (using 16 bits)
// a 16 bits integer variables have values from -32768 to +32767, so:
// 0 - 0x0000 - 0000 0000 0000 0000
// 32767 - 0x7fff - 0111 1111 1111 1111
// -32768 - 0x8000 - 1000 0000 0000 0000
// -1 - 0xffff - 1111 1111 1111 1111

// converting int16 -10 will be done as following:
// - make it positive = 10
// - 16 bits binary value of 10 = 0000 0000 0000 1010
// - inverse the bytes = 1111 1111 1111 0101
// - adding +1 = 1111 1111 1111 0110
// - 1111 1111 1111 0110 bits = 0xfff6

// we're using 64 bits integer because that the type returned by the mirror node - int64
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

great explanation 🙌


// we're using 64 bits integer because that the type returned by the mirror node - int64
const bits = 64;
return numberTo0x((BigInt(input.toString()) + (BigInt(1) << BigInt(bits))) % (BigInt(1) << BigInt(bits)));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

question: do we expect number bigger than 53 bits? so it's not automatically coerced to double https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/MAX_SAFE_INTEGER

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Transaction with CONTRACT_NEGATIVE_VALUE prevents entire block from being retrieved
3 participants