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

fix: ensure new withdrawalCredentials in switchToCompoundingValidator() #7478

Open
wants to merge 1 commit into
base: unstable
Choose a base branch
from

Conversation

twoeths
Copy link
Contributor

@twoeths twoeths commented Feb 18, 2025

Motivation

  • got this issue in Gnosis
Tested this but on first consolidation same target and source validator it apparently worked fine. However, the erigon-lodestar validator node that proposed the consolidation request transaction rejected all peers and forked. It is stuck on this slot: [link](http://45.79.201.144:8083/slot/68121)
Lodestar shows these errors:
Feb-17 07:11:09.621[chain]           debug: Block error slot=68121, code=BLOCK_ERROR_INVALID_STATE_ROOT, slot=68121, root=0xb8362da32e9ba60bb4e76aa3dae3cf3722404f97be7d674a1ba2d61140bae2f0, expectedRoot=0xb3e18d8a01cb01ac43a0e2fc4d11f6f9298d74ed51ed8520f0597001e4499516
Error: BLOCK_ERROR_INVALID_STATE_ROOT
    at verifyBlocksStateTransitionOnly (file:///usr/app/packages/beacon-node/src/chain/blocks/verifyBlocksStateTransitionOnly.ts:71:13)
    at BeaconChain.verifyBlocksInEpoch (file:///usr/app/packages/beacon-node/src/chain/blocks/verifyBlock.ts:114:7)
    at BeaconChain.processBlocks (file:///usr/app/packages/beacon-node/src/chain/blocks/index.ts:74:7)
    at JobItemQueue.runJob (file:///usr/app/packages/beacon-node/src/util/queue/itemQueue.ts:102:22)
Feb-17 07:11:09.622[sync]          verbose: Batch process error id=Finalized, startEpoch=4257, status=Processing, code=BLOCK_ERROR_INVALID_STATE_ROOT, slot=68121, root=0xb8362da32e9ba60bb4e76aa3dae3cf3722404f97be7d674a1ba2d61140bae2f0, expectedRoot=0xb3e18d8a01cb01ac43a0e2fc4d11f6f9298d74ed51ed8520f0597001e4499516
Error: BLOCK_ERROR_INVALID_STATE_ROOT
    at verifyBlocksStateTransitionOnly (file:///usr/app/packages/beacon-node/src/chain/blocks/verifyBlocksStateTransitionOnly.ts:71:13)
    at BeaconChain.verifyBlocksInEpoch (file:///usr/app/packages/beacon-node/src/chain/blocks/verifyBlock.ts:114:7)
    at BeaconChain.processBlocks (file:///usr/app/packages/beacon-node/src/chain/blocks/index.ts:74:7)
    at JobItemQueue.runJob (file:///usr/app/packages/beacon-node/src/util/queue/itemQueue.ts:102:22)

The rest of the nodes are working the fine, even nethermind-lodestar, and the validator seems to have updated to 0x02 withdrawal credentials type. [link](http://45.79.201.144:8083/validator/2000)

closes #7487

Description

  • although it's not proved to fix the issue, we should ensure we always create a new withdrawalCredentials by enforcing the use of Uint8Array.slice(), just in case backed data is a Buffer
  • the similar "Invalid state root" was found in the past due to this code place, as noted in the comment
  • this pattern was used in a lot of places anyway

Update
just found this

describe("Buffer", () => {
  it("slice", () => {
    const buffer = Buffer.alloc(32, 1);
    const sliced = Uint8Array.prototype.slice.call(buffer, 0, buffer.length);
    sliced[0] = 2;
    expect(sliced[0]).toBe(2);
    expect(buffer[0]).toBe(1);
    expect(sliced instanceof Buffer).toBe(false);
  });
});
- Expected
+ Received

- false
+ true

even we used this pattern a lot Uint8Array.prototype.slice.call in ssz to deserialize state it still return a Buffer
when we deserialize state from leveldb, the state bytes there is really the Buffer
that's one possibilities how this issue happened

@twoeths twoeths requested a review from a team as a code owner February 18, 2025 06:39
Copy link

codecov bot commented Feb 18, 2025

Codecov Report

Attention: Patch coverage is 0% with 5 lines in your changes missing coverage. Please review.

Project coverage is 50.47%. Comparing base (a25ea77) to head (162a2d8).

Additional details and impacted files
@@             Coverage Diff              @@
##           unstable    #7478      +/-   ##
============================================
- Coverage     50.48%   50.47%   -0.01%     
============================================
  Files           602      602              
  Lines         40606    40610       +4     
  Branches       2230     2230              
============================================
  Hits          20499    20499              
- Misses        20067    20071       +4     
  Partials         40       40              

@nflaig
Copy link
Member

nflaig commented Feb 18, 2025

just in case backed data is a Buffer

as pointed out on discord, we explicitly convert to Uint8Array if block is submitted through api

// We could just return the `Buffer` here which is a subclass of `Uint8Array` but downstream code does not require it
// and it's better to convert it here to avoid unexpected behavior such as `Buffer.prototype.slice` not copying memory
// See https://github.com/nodejs/node/issues/41588#issuecomment-1016269584
return new Uint8Array(payload.buffer, payload.byteOffset, payload.byteLength);

however, as a sanity check, we could consider asserting that when we pass the block to state-transition

Copy link
Contributor

Performance Report

✔️ no performance regression detected

Full benchmark results
Benchmark suite Current: 8a703e6 Previous: a25ea77 Ratio
getPubkeys - index2pubkey - req 1000 vs - 250000 vc 1.1343 ms/op 933.03 us/op 1.22
getPubkeys - validatorsArr - req 1000 vs - 250000 vc 43.274 us/op 34.747 us/op 1.25
BLS verify - blst 930.94 us/op 835.49 us/op 1.11
BLS verifyMultipleSignatures 3 - blst 2.2484 ms/op 1.1567 ms/op 1.94
BLS verifyMultipleSignatures 8 - blst 3.0924 ms/op 1.6187 ms/op 1.91
BLS verifyMultipleSignatures 32 - blst 7.4879 ms/op 4.7793 ms/op 1.57
BLS verifyMultipleSignatures 64 - blst 10.596 ms/op 8.8093 ms/op 1.20
BLS verifyMultipleSignatures 128 - blst 18.465 ms/op 17.335 ms/op 1.07
BLS deserializing 10000 signatures 705.59 ms/op 690.46 ms/op 1.02
BLS deserializing 100000 signatures 7.2728 s/op 6.7867 s/op 1.07
BLS verifyMultipleSignatures - same message - 3 - blst 1.5228 ms/op 892.13 us/op 1.71
BLS verifyMultipleSignatures - same message - 8 - blst 1.0356 ms/op 1.0113 ms/op 1.02
BLS verifyMultipleSignatures - same message - 32 - blst 1.7877 ms/op 1.6716 ms/op 1.07
BLS verifyMultipleSignatures - same message - 64 - blst 3.0353 ms/op 2.5566 ms/op 1.19
BLS verifyMultipleSignatures - same message - 128 - blst 4.8944 ms/op 4.2973 ms/op 1.14
BLS aggregatePubkeys 32 - blst 22.605 us/op 19.308 us/op 1.17
BLS aggregatePubkeys 128 - blst 78.337 us/op 69.038 us/op 1.13
notSeenSlots=1 numMissedVotes=1 numBadVotes=10 65.196 ms/op 45.287 ms/op 1.44
notSeenSlots=1 numMissedVotes=0 numBadVotes=4 58.867 ms/op 43.546 ms/op 1.35
notSeenSlots=2 numMissedVotes=1 numBadVotes=10 51.696 ms/op 34.312 ms/op 1.51
getSlashingsAndExits - default max 81.870 us/op 74.971 us/op 1.09
getSlashingsAndExits - 2k 351.88 us/op 281.01 us/op 1.25
proposeBlockBody type=full, size=empty 6.7292 ms/op 4.5967 ms/op 1.46
isKnown best case - 1 super set check 220.00 ns/op 200.00 ns/op 1.10
isKnown normal case - 2 super set checks 220.00 ns/op 196.00 ns/op 1.12
isKnown worse case - 16 super set checks 213.00 ns/op 200.00 ns/op 1.06
InMemoryCheckpointStateCache - add get delete 2.5170 us/op 2.1860 us/op 1.15
validate api signedAggregateAndProof - struct 1.7515 ms/op 1.3180 ms/op 1.33
validate gossip signedAggregateAndProof - struct 1.8566 ms/op 1.3189 ms/op 1.41
batch validate gossip attestation - vc 640000 - chunk 32 133.71 us/op 116.91 us/op 1.14
batch validate gossip attestation - vc 640000 - chunk 64 108.88 us/op 101.94 us/op 1.07
batch validate gossip attestation - vc 640000 - chunk 128 100.93 us/op 92.293 us/op 1.09
batch validate gossip attestation - vc 640000 - chunk 256 103.05 us/op 95.599 us/op 1.08
pickEth1Vote - no votes 1.0085 ms/op 919.80 us/op 1.10
pickEth1Vote - max votes 7.9038 ms/op 5.6717 ms/op 1.39
pickEth1Vote - Eth1Data hashTreeRoot value x2048 17.761 ms/op 18.106 ms/op 0.98
pickEth1Vote - Eth1Data hashTreeRoot tree x2048 32.375 ms/op 22.152 ms/op 1.46
pickEth1Vote - Eth1Data fastSerialize value x2048 481.07 us/op 400.99 us/op 1.20
pickEth1Vote - Eth1Data fastSerialize tree x2048 4.3466 ms/op 4.0191 ms/op 1.08
bytes32 toHexString 388.00 ns/op 344.00 ns/op 1.13
bytes32 Buffer.toString(hex) 341.00 ns/op 218.00 ns/op 1.56
bytes32 Buffer.toString(hex) from Uint8Array 418.00 ns/op 315.00 ns/op 1.33
bytes32 Buffer.toString(hex) + 0x 242.00 ns/op 227.00 ns/op 1.07
Object access 1 prop 0.14000 ns/op 0.11300 ns/op 1.24
Map access 1 prop 0.12400 ns/op 0.11200 ns/op 1.11
Object get x1000 6.0320 ns/op 5.4360 ns/op 1.11
Map get x1000 6.4520 ns/op 6.0930 ns/op 1.06
Object set x1000 30.521 ns/op 26.164 ns/op 1.17
Map set x1000 21.175 ns/op 18.255 ns/op 1.16
Return object 10000 times 0.30510 ns/op 0.26730 ns/op 1.14
Throw Error 10000 times 4.7759 us/op 4.0226 us/op 1.19
toHex 144.92 ns/op 124.10 ns/op 1.17
Buffer.from 138.81 ns/op 115.24 ns/op 1.20
shared Buffer 91.470 ns/op 71.837 ns/op 1.27
fastMsgIdFn sha256 / 200 bytes 2.3550 us/op 2.0640 us/op 1.14
fastMsgIdFn h32 xxhash / 200 bytes 226.00 ns/op 197.00 ns/op 1.15
fastMsgIdFn h64 xxhash / 200 bytes 275.00 ns/op 262.00 ns/op 1.05
fastMsgIdFn sha256 / 1000 bytes 7.7740 us/op 6.8940 us/op 1.13
fastMsgIdFn h32 xxhash / 1000 bytes 334.00 ns/op 317.00 ns/op 1.05
fastMsgIdFn h64 xxhash / 1000 bytes 408.00 ns/op 321.00 ns/op 1.27
fastMsgIdFn sha256 / 10000 bytes 70.879 us/op 61.031 us/op 1.16
fastMsgIdFn h32 xxhash / 10000 bytes 1.8640 us/op 1.8000 us/op 1.04
fastMsgIdFn h64 xxhash / 10000 bytes 1.2400 us/op 1.2350 us/op 1.00
send data - 1000 256B messages 12.666 ms/op 12.803 ms/op 0.99
send data - 1000 512B messages 17.455 ms/op 15.261 ms/op 1.14
send data - 1000 1024B messages 28.235 ms/op 21.994 ms/op 1.28
send data - 1000 1200B messages 21.511 ms/op 19.952 ms/op 1.08
send data - 1000 2048B messages 21.357 ms/op 21.143 ms/op 1.01
send data - 1000 4096B messages 25.495 ms/op 24.735 ms/op 1.03
send data - 1000 16384B messages 72.850 ms/op 74.224 ms/op 0.98
send data - 1000 65536B messages 215.81 ms/op 205.50 ms/op 1.05
enrSubnets - fastDeserialize 64 bits 1.8030 us/op 1.6730 us/op 1.08
enrSubnets - ssz BitVector 64 bits 351.00 ns/op 303.00 ns/op 1.16
enrSubnets - fastDeserialize 4 bits 136.00 ns/op 118.00 ns/op 1.15
enrSubnets - ssz BitVector 4 bits 324.00 ns/op 302.00 ns/op 1.07
prioritizePeers score -10:0 att 32-0.1 sync 2-0 119.34 us/op 113.66 us/op 1.05
prioritizePeers score 0:0 att 32-0.25 sync 2-0.25 140.17 us/op 130.46 us/op 1.07
prioritizePeers score 0:0 att 32-0.5 sync 2-0.5 199.48 us/op 191.02 us/op 1.04
prioritizePeers score 0:0 att 64-0.75 sync 4-0.75 378.39 us/op 361.77 us/op 1.05
prioritizePeers score 0:0 att 64-1 sync 4-1 457.00 us/op 440.79 us/op 1.04
array of 16000 items push then shift 1.6152 us/op 1.5342 us/op 1.05
LinkedList of 16000 items push then shift 7.0250 ns/op 6.7330 ns/op 1.04
array of 16000 items push then pop 75.870 ns/op 71.326 ns/op 1.06
LinkedList of 16000 items push then pop 6.9160 ns/op 6.5300 ns/op 1.06
array of 24000 items push then shift 2.3852 us/op 2.2609 us/op 1.06
LinkedList of 24000 items push then shift 7.0010 ns/op 6.6000 ns/op 1.06
array of 24000 items push then pop 102.86 ns/op 96.225 ns/op 1.07
LinkedList of 24000 items push then pop 6.8880 ns/op 6.4830 ns/op 1.06
intersect bitArray bitLen 8 6.4690 ns/op 6.1290 ns/op 1.06
intersect array and set length 8 38.371 ns/op 36.398 ns/op 1.05
intersect bitArray bitLen 128 30.181 ns/op 28.176 ns/op 1.07
intersect array and set length 128 627.80 ns/op 586.23 ns/op 1.07
bitArray.getTrueBitIndexes() bitLen 128 1.1810 us/op 958.00 ns/op 1.23
bitArray.getTrueBitIndexes() bitLen 248 1.7610 us/op 1.6890 us/op 1.04
bitArray.getTrueBitIndexes() bitLen 512 3.6210 us/op 3.4970 us/op 1.04
Buffer.concat 32 items 902.00 ns/op 564.00 ns/op 1.60
Uint8Array.set 32 items 1.1840 us/op 1.7430 us/op 0.68
Buffer.copy 2.6790 us/op 1.9570 us/op 1.37
Uint8Array.set - with subarray 2.0980 us/op 1.6110 us/op 1.30
Uint8Array.set - without subarray 1.6930 us/op 994.00 ns/op 1.70
getUint32 - dataview 212.00 ns/op 184.00 ns/op 1.15
getUint32 - manual 125.00 ns/op 110.00 ns/op 1.14
Set add up to 64 items then delete first 2.4962 us/op 2.1152 us/op 1.18
OrderedSet add up to 64 items then delete first 3.6743 us/op 3.1288 us/op 1.17
Set add up to 64 items then delete last 2.5860 us/op 2.3885 us/op 1.08
OrderedSet add up to 64 items then delete last 4.6337 us/op 3.5115 us/op 1.32
Set add up to 64 items then delete middle 2.7148 us/op 2.3505 us/op 1.15
OrderedSet add up to 64 items then delete middle 6.4923 us/op 4.9953 us/op 1.30
Set add up to 128 items then delete first 5.1974 us/op 4.7941 us/op 1.08
OrderedSet add up to 128 items then delete first 7.5869 us/op 7.6348 us/op 0.99
Set add up to 128 items then delete last 5.6150 us/op 4.8067 us/op 1.17
OrderedSet add up to 128 items then delete last 9.2054 us/op 7.0201 us/op 1.31
Set add up to 128 items then delete middle 5.7637 us/op 4.7284 us/op 1.22
OrderedSet add up to 128 items then delete middle 15.606 us/op 13.414 us/op 1.16
Set add up to 256 items then delete first 12.646 us/op 9.5220 us/op 1.33
OrderedSet add up to 256 items then delete first 17.900 us/op 14.981 us/op 1.19
Set add up to 256 items then delete last 11.781 us/op 9.8720 us/op 1.19
OrderedSet add up to 256 items then delete last 17.309 us/op 13.700 us/op 1.26
Set add up to 256 items then delete middle 10.739 us/op 9.0776 us/op 1.18
OrderedSet add up to 256 items then delete middle 45.542 us/op 39.940 us/op 1.14
transfer serialized Status (84 B) 2.4590 us/op 2.1570 us/op 1.14
copy serialized Status (84 B) 1.3830 us/op 1.2660 us/op 1.09
transfer serialized SignedVoluntaryExit (112 B) 2.5990 us/op 2.1860 us/op 1.19
copy serialized SignedVoluntaryExit (112 B) 1.1990 us/op 1.3290 us/op 0.90
transfer serialized ProposerSlashing (416 B) 2.5550 us/op 3.4810 us/op 0.73
copy serialized ProposerSlashing (416 B) 1.3640 us/op 2.0210 us/op 0.67
transfer serialized Attestation (485 B) 2.5010 us/op 2.3320 us/op 1.07
copy serialized Attestation (485 B) 1.3240 us/op 1.4210 us/op 0.93
transfer serialized AttesterSlashing (33232 B) 2.7630 us/op 2.6870 us/op 1.03
copy serialized AttesterSlashing (33232 B) 3.7530 us/op 3.7410 us/op 1.00
transfer serialized Small SignedBeaconBlock (128000 B) 3.4520 us/op 3.0600 us/op 1.13
copy serialized Small SignedBeaconBlock (128000 B) 9.2420 us/op 9.4900 us/op 0.97
transfer serialized Avg SignedBeaconBlock (200000 B) 3.8680 us/op 3.5770 us/op 1.08
copy serialized Avg SignedBeaconBlock (200000 B) 14.010 us/op 12.498 us/op 1.12
transfer serialized BlobsSidecar (524380 B) 3.8100 us/op 3.9300 us/op 0.97
copy serialized BlobsSidecar (524380 B) 147.12 us/op 69.816 us/op 2.11
transfer serialized Big SignedBeaconBlock (1000000 B) 4.0810 us/op 4.3400 us/op 0.94
copy serialized Big SignedBeaconBlock (1000000 B) 163.31 us/op 109.54 us/op 1.49
pass gossip attestations to forkchoice per slot 3.2437 ms/op 2.6257 ms/op 1.24
forkChoice updateHead vc 100000 bc 64 eq 0 486.70 us/op 429.28 us/op 1.13
forkChoice updateHead vc 600000 bc 64 eq 0 3.0470 ms/op 2.7654 ms/op 1.10
forkChoice updateHead vc 1000000 bc 64 eq 0 5.2230 ms/op 4.5420 ms/op 1.15
forkChoice updateHead vc 600000 bc 320 eq 0 3.0709 ms/op 2.6517 ms/op 1.16
forkChoice updateHead vc 600000 bc 1200 eq 0 3.3531 ms/op 2.6898 ms/op 1.25
forkChoice updateHead vc 600000 bc 7200 eq 0 3.5095 ms/op 2.9975 ms/op 1.17
forkChoice updateHead vc 600000 bc 64 eq 1000 11.582 ms/op 10.114 ms/op 1.15
forkChoice updateHead vc 600000 bc 64 eq 10000 11.648 ms/op 10.058 ms/op 1.16
forkChoice updateHead vc 600000 bc 64 eq 300000 14.849 ms/op 13.322 ms/op 1.11
computeDeltas 500000 validators 300 proto nodes 4.1349 ms/op 3.7647 ms/op 1.10
computeDeltas 500000 validators 1200 proto nodes 4.2353 ms/op 3.7847 ms/op 1.12
computeDeltas 500000 validators 7200 proto nodes 4.1733 ms/op 3.7794 ms/op 1.10
computeDeltas 750000 validators 300 proto nodes 6.0317 ms/op 5.5783 ms/op 1.08
computeDeltas 750000 validators 1200 proto nodes 5.9455 ms/op 5.6610 ms/op 1.05
computeDeltas 750000 validators 7200 proto nodes 6.2183 ms/op 5.6830 ms/op 1.09
computeDeltas 1400000 validators 300 proto nodes 11.190 ms/op 10.501 ms/op 1.07
computeDeltas 1400000 validators 1200 proto nodes 10.882 ms/op 10.472 ms/op 1.04
computeDeltas 1400000 validators 7200 proto nodes 11.174 ms/op 10.474 ms/op 1.07
computeDeltas 2100000 validators 300 proto nodes 18.515 ms/op 15.713 ms/op 1.18
computeDeltas 2100000 validators 1200 proto nodes 17.972 ms/op 15.921 ms/op 1.13
computeDeltas 2100000 validators 7200 proto nodes 17.521 ms/op 15.801 ms/op 1.11
altair processAttestation - 250000 vs - 7PWei normalcase 2.2038 ms/op 2.0502 ms/op 1.07
altair processAttestation - 250000 vs - 7PWei worstcase 3.2909 ms/op 2.9770 ms/op 1.11
altair processAttestation - setStatus - 1/6 committees join 129.31 us/op 122.69 us/op 1.05
altair processAttestation - setStatus - 1/3 committees join 252.45 us/op 234.09 us/op 1.08
altair processAttestation - setStatus - 1/2 committees join 351.22 us/op 329.87 us/op 1.06
altair processAttestation - setStatus - 2/3 committees join 492.51 us/op 419.48 us/op 1.17
altair processAttestation - setStatus - 4/5 committees join 632.97 us/op 583.81 us/op 1.08
altair processAttestation - setStatus - 100% committees join 772.22 us/op 682.51 us/op 1.13
altair processBlock - 250000 vs - 7PWei normalcase 5.5379 ms/op 4.2563 ms/op 1.30
altair processBlock - 250000 vs - 7PWei normalcase hashState 33.614 ms/op 36.920 ms/op 0.91
altair processBlock - 250000 vs - 7PWei worstcase 41.403 ms/op 35.212 ms/op 1.18
altair processBlock - 250000 vs - 7PWei worstcase hashState 118.96 ms/op 90.525 ms/op 1.31
phase0 processBlock - 250000 vs - 7PWei normalcase 2.4768 ms/op 1.6322 ms/op 1.52
phase0 processBlock - 250000 vs - 7PWei worstcase 27.573 ms/op 21.018 ms/op 1.31
altair processEth1Data - 250000 vs - 7PWei normalcase 343.16 us/op 318.88 us/op 1.08
getExpectedWithdrawals 250000 eb:1,eth1:1,we:0,wn:0,smpl:15 7.3090 us/op 4.4830 us/op 1.63
getExpectedWithdrawals 250000 eb:0.95,eth1:0.1,we:0.05,wn:0,smpl:219 24.690 us/op 26.795 us/op 0.92
getExpectedWithdrawals 250000 eb:0.95,eth1:0.3,we:0.05,wn:0,smpl:42 9.4650 us/op 7.0800 us/op 1.34
getExpectedWithdrawals 250000 eb:0.95,eth1:0.7,we:0.05,wn:0,smpl:18 8.3240 us/op 4.5230 us/op 1.84
getExpectedWithdrawals 250000 eb:0.1,eth1:0.1,we:0,wn:0,smpl:1020 134.78 us/op 98.738 us/op 1.37
getExpectedWithdrawals 250000 eb:0.03,eth1:0.03,we:0,wn:0,smpl:11777 1.9043 ms/op 941.54 us/op 2.02
getExpectedWithdrawals 250000 eb:0.01,eth1:0.01,we:0,wn:0,smpl:16384 2.6372 ms/op 1.3417 ms/op 1.97
getExpectedWithdrawals 250000 eb:0,eth1:0,we:0,wn:0,smpl:16384 2.5935 ms/op 1.2845 ms/op 2.02
getExpectedWithdrawals 250000 eb:0,eth1:0,we:0,wn:0,nocache,smpl:16384 3.3094 ms/op 3.1711 ms/op 1.04
getExpectedWithdrawals 250000 eb:0,eth1:1,we:0,wn:0,smpl:16384 2.7300 ms/op 1.3353 ms/op 2.04
getExpectedWithdrawals 250000 eb:0,eth1:1,we:0,wn:0,nocache,smpl:16384 3.3831 ms/op 3.1892 ms/op 1.06
Tree 40 250000 create 415.68 ms/op 419.83 ms/op 0.99
Tree 40 250000 get(125000) 145.56 ns/op 142.75 ns/op 1.02
Tree 40 250000 set(125000) 1.4735 us/op 1.3691 us/op 1.08
Tree 40 250000 toArray() 15.367 ms/op 15.283 ms/op 1.01
Tree 40 250000 iterate all - toArray() + loop 15.508 ms/op 16.466 ms/op 0.94
Tree 40 250000 iterate all - get(i) 51.856 ms/op 51.046 ms/op 1.02
Array 250000 create 2.4247 ms/op 2.3576 ms/op 1.03
Array 250000 clone - spread 818.25 us/op 790.44 us/op 1.04
Array 250000 get(125000) 0.41300 ns/op 0.39600 ns/op 1.04
Array 250000 set(125000) 0.50700 ns/op 0.40600 ns/op 1.25
Array 250000 iterate all - loop 121.88 us/op 77.175 us/op 1.58
phase0 afterProcessEpoch - 250000 vs - 7PWei 48.796 ms/op 45.106 ms/op 1.08
Array.fill - length 1000000 3.6410 ms/op 3.2494 ms/op 1.12
Array push - length 1000000 12.561 ms/op 12.401 ms/op 1.01
Array.get 0.27574 ns/op 0.26809 ns/op 1.03
Uint8Array.get 0.44460 ns/op 0.43030 ns/op 1.03
phase0 beforeProcessEpoch - 250000 vs - 7PWei 16.897 ms/op 15.487 ms/op 1.09
altair processEpoch - mainnet_e81889 311.67 ms/op 274.36 ms/op 1.14
mainnet_e81889 - altair beforeProcessEpoch 19.442 ms/op 17.177 ms/op 1.13
mainnet_e81889 - altair processJustificationAndFinalization 7.4880 us/op 5.2970 us/op 1.41
mainnet_e81889 - altair processInactivityUpdates 4.2007 ms/op 3.9610 ms/op 1.06
mainnet_e81889 - altair processRewardsAndPenalties 62.349 ms/op 38.353 ms/op 1.63
mainnet_e81889 - altair processRegistryUpdates 1.0040 us/op 697.00 ns/op 1.44
mainnet_e81889 - altair processSlashings 181.00 ns/op 171.00 ns/op 1.06
mainnet_e81889 - altair processEth1DataReset 178.00 ns/op 168.00 ns/op 1.06
mainnet_e81889 - altair processEffectiveBalanceUpdates 1.2876 ms/op 1.2214 ms/op 1.05
mainnet_e81889 - altair processSlashingsReset 1.0380 us/op 858.00 ns/op 1.21
mainnet_e81889 - altair processRandaoMixesReset 1.5120 us/op 1.1410 us/op 1.33
mainnet_e81889 - altair processHistoricalRootsUpdate 189.00 ns/op 173.00 ns/op 1.09
mainnet_e81889 - altair processParticipationFlagUpdates 596.00 ns/op 495.00 ns/op 1.20
mainnet_e81889 - altair processSyncCommitteeUpdates 135.00 ns/op 132.00 ns/op 1.02
mainnet_e81889 - altair afterProcessEpoch 53.020 ms/op 47.095 ms/op 1.13
capella processEpoch - mainnet_e217614 972.67 ms/op 903.25 ms/op 1.08
mainnet_e217614 - capella beforeProcessEpoch 69.885 ms/op 59.125 ms/op 1.18
mainnet_e217614 - capella processJustificationAndFinalization 5.7980 us/op 5.3070 us/op 1.09
mainnet_e217614 - capella processInactivityUpdates 16.057 ms/op 15.454 ms/op 1.04
mainnet_e217614 - capella processRewardsAndPenalties 220.76 ms/op 173.09 ms/op 1.28
mainnet_e217614 - capella processRegistryUpdates 8.1310 us/op 6.1750 us/op 1.32
mainnet_e217614 - capella processSlashings 186.00 ns/op 170.00 ns/op 1.09
mainnet_e217614 - capella processEth1DataReset 180.00 ns/op 168.00 ns/op 1.07
mainnet_e217614 - capella processEffectiveBalanceUpdates 10.509 ms/op 13.965 ms/op 0.75
mainnet_e217614 - capella processSlashingsReset 1.1700 us/op 835.00 ns/op 1.40
mainnet_e217614 - capella processRandaoMixesReset 1.4040 us/op 1.1460 us/op 1.23
mainnet_e217614 - capella processHistoricalRootsUpdate 170.00 ns/op 172.00 ns/op 0.99
mainnet_e217614 - capella processParticipationFlagUpdates 591.00 ns/op 504.00 ns/op 1.17
mainnet_e217614 - capella afterProcessEpoch 129.74 ms/op 117.79 ms/op 1.10
phase0 processEpoch - mainnet_e58758 314.27 ms/op 285.33 ms/op 1.10
mainnet_e58758 - phase0 beforeProcessEpoch 82.509 ms/op 74.140 ms/op 1.11
mainnet_e58758 - phase0 processJustificationAndFinalization 5.8850 us/op 5.4720 us/op 1.08
mainnet_e58758 - phase0 processRewardsAndPenalties 46.092 ms/op 35.972 ms/op 1.28
mainnet_e58758 - phase0 processRegistryUpdates 3.8840 us/op 2.9950 us/op 1.30
mainnet_e58758 - phase0 processSlashings 170.00 ns/op 168.00 ns/op 1.01
mainnet_e58758 - phase0 processEth1DataReset 183.00 ns/op 170.00 ns/op 1.08
mainnet_e58758 - phase0 processEffectiveBalanceUpdates 1.1691 ms/op 980.43 us/op 1.19
mainnet_e58758 - phase0 processSlashingsReset 1.0020 us/op 854.00 ns/op 1.17
mainnet_e58758 - phase0 processRandaoMixesReset 1.5590 us/op 1.1530 us/op 1.35
mainnet_e58758 - phase0 processHistoricalRootsUpdate 171.00 ns/op 171.00 ns/op 1.00
mainnet_e58758 - phase0 processParticipationRecordUpdates 863.00 ns/op 852.00 ns/op 1.01
mainnet_e58758 - phase0 afterProcessEpoch 43.696 ms/op 40.040 ms/op 1.09
phase0 processEffectiveBalanceUpdates - 250000 normalcase 1.2605 ms/op 1.3118 ms/op 0.96
phase0 processEffectiveBalanceUpdates - 250000 worstcase 0.5 1.9353 ms/op 1.9836 ms/op 0.98
altair processInactivityUpdates - 250000 normalcase 20.728 ms/op 16.168 ms/op 1.28
altair processInactivityUpdates - 250000 worstcase 24.137 ms/op 16.120 ms/op 1.50
phase0 processRegistryUpdates - 250000 normalcase 10.774 us/op 6.5290 us/op 1.65
phase0 processRegistryUpdates - 250000 badcase_full_deposits 439.29 us/op 229.19 us/op 1.92
phase0 processRegistryUpdates - 250000 worstcase 0.5 128.60 ms/op 109.31 ms/op 1.18
altair processRewardsAndPenalties - 250000 normalcase 43.722 ms/op 42.434 ms/op 1.03
altair processRewardsAndPenalties - 250000 worstcase 40.055 ms/op 34.066 ms/op 1.18
phase0 getAttestationDeltas - 250000 normalcase 7.1676 ms/op 5.8578 ms/op 1.22
phase0 getAttestationDeltas - 250000 worstcase 6.5976 ms/op 6.6448 ms/op 0.99
phase0 processSlashings - 250000 worstcase 119.84 us/op 83.265 us/op 1.44
altair processSyncCommitteeUpdates - 250000 119.50 ms/op 120.27 ms/op 0.99
BeaconState.hashTreeRoot - No change 239.00 ns/op 204.00 ns/op 1.17
BeaconState.hashTreeRoot - 1 full validator 109.18 us/op 81.680 us/op 1.34
BeaconState.hashTreeRoot - 32 full validator 1.2378 ms/op 976.72 us/op 1.27
BeaconState.hashTreeRoot - 512 full validator 11.653 ms/op 11.021 ms/op 1.06
BeaconState.hashTreeRoot - 1 validator.effectiveBalance 132.58 us/op 98.870 us/op 1.34
BeaconState.hashTreeRoot - 32 validator.effectiveBalance 1.4159 ms/op 2.2343 ms/op 0.63
BeaconState.hashTreeRoot - 512 validator.effectiveBalance 22.836 ms/op 21.447 ms/op 1.06
BeaconState.hashTreeRoot - 1 balances 103.08 us/op 72.732 us/op 1.42
BeaconState.hashTreeRoot - 32 balances 1.1910 ms/op 827.62 us/op 1.44
BeaconState.hashTreeRoot - 512 balances 7.4891 ms/op 8.2272 ms/op 0.91
BeaconState.hashTreeRoot - 250000 balances 191.15 ms/op 185.16 ms/op 1.03
aggregationBits - 2048 els - zipIndexesInBitList 22.423 us/op 20.477 us/op 1.10
byteArrayEquals 32 55.924 ns/op 61.083 ns/op 0.92
Buffer.compare 32 18.497 ns/op 16.511 ns/op 1.12
byteArrayEquals 1024 1.6506 us/op 1.5153 us/op 1.09
Buffer.compare 1024 28.478 ns/op 23.686 ns/op 1.20
byteArrayEquals 16384 25.396 us/op 24.220 us/op 1.05
Buffer.compare 16384 194.98 ns/op 193.58 ns/op 1.01
byteArrayEquals 123687377 198.68 ms/op 183.24 ms/op 1.08
Buffer.compare 123687377 6.0814 ms/op 6.4495 ms/op 0.94
byteArrayEquals 32 - diff last byte 54.950 ns/op 52.440 ns/op 1.05
Buffer.compare 32 - diff last byte 18.281 ns/op 17.007 ns/op 1.07
byteArrayEquals 1024 - diff last byte 1.6433 us/op 1.5996 us/op 1.03
Buffer.compare 1024 - diff last byte 27.855 ns/op 24.976 ns/op 1.12
byteArrayEquals 16384 - diff last byte 25.991 us/op 25.293 us/op 1.03
Buffer.compare 16384 - diff last byte 213.61 ns/op 187.46 ns/op 1.14
byteArrayEquals 123687377 - diff last byte 191.53 ms/op 189.07 ms/op 1.01
Buffer.compare 123687377 - diff last byte 6.1776 ms/op 6.7773 ms/op 0.91
byteArrayEquals 32 - random bytes 5.1330 ns/op 5.0250 ns/op 1.02
Buffer.compare 32 - random bytes 17.351 ns/op 16.812 ns/op 1.03
byteArrayEquals 1024 - random bytes 5.1200 ns/op 5.0100 ns/op 1.02
Buffer.compare 1024 - random bytes 18.145 ns/op 16.713 ns/op 1.09
byteArrayEquals 16384 - random bytes 5.3300 ns/op 5.0560 ns/op 1.05
Buffer.compare 16384 - random bytes 18.513 ns/op 16.737 ns/op 1.11
byteArrayEquals 123687377 - random bytes 6.3200 ns/op 6.2900 ns/op 1.00
Buffer.compare 123687377 - random bytes 19.550 ns/op 18.200 ns/op 1.07
regular array get 100000 times 33.271 us/op 43.431 us/op 0.77
wrappedArray get 100000 times 32.955 us/op 32.528 us/op 1.01
arrayWithProxy get 100000 times 13.787 ms/op 14.008 ms/op 0.98
ssz.Root.equals 47.931 ns/op 45.652 ns/op 1.05
byteArrayEquals 48.409 ns/op 44.781 ns/op 1.08
Buffer.compare 11.282 ns/op 10.236 ns/op 1.10
processSlot - 1 slots 12.856 us/op 10.246 us/op 1.25
processSlot - 32 slots 2.7174 ms/op 2.2142 ms/op 1.23
getEffectiveBalanceIncrementsZeroInactive - 250000 vs - 7PWei 63.440 ms/op 51.062 ms/op 1.24
getCommitteeAssignments - req 1 vs - 250000 vc 2.1186 ms/op 2.0328 ms/op 1.04
getCommitteeAssignments - req 100 vs - 250000 vc 4.1250 ms/op 3.9307 ms/op 1.05
getCommitteeAssignments - req 1000 vs - 250000 vc 4.4011 ms/op 4.2010 ms/op 1.05
findModifiedValidators - 10000 modified validators 744.16 ms/op 746.89 ms/op 1.00
findModifiedValidators - 1000 modified validators 707.85 ms/op 686.47 ms/op 1.03
findModifiedValidators - 100 modified validators 253.97 ms/op 283.88 ms/op 0.89
findModifiedValidators - 10 modified validators 146.95 ms/op 215.46 ms/op 0.68
findModifiedValidators - 1 modified validators 150.80 ms/op 142.91 ms/op 1.06
findModifiedValidators - no difference 190.32 ms/op 143.37 ms/op 1.33
compare ViewDUs 6.4685 s/op 5.8657 s/op 1.10
compare each validator Uint8Array 1.9528 s/op 1.6456 s/op 1.19
compare ViewDU to Uint8Array 1.1258 s/op 976.28 ms/op 1.15
migrate state 1000000 validators, 24 modified, 0 new 942.61 ms/op 846.08 ms/op 1.11
migrate state 1000000 validators, 1700 modified, 1000 new 1.2070 s/op 1.1242 s/op 1.07
migrate state 1000000 validators, 3400 modified, 2000 new 1.2732 s/op 1.1703 s/op 1.09
migrate state 1500000 validators, 24 modified, 0 new 914.09 ms/op 870.53 ms/op 1.05
migrate state 1500000 validators, 1700 modified, 1000 new 1.1538 s/op 999.79 ms/op 1.15
migrate state 1500000 validators, 3400 modified, 2000 new 1.3605 s/op 1.3190 s/op 1.03
RootCache.getBlockRootAtSlot - 250000 vs - 7PWei 4.5400 ns/op 4.1900 ns/op 1.08
state getBlockRootAtSlot - 250000 vs - 7PWei 574.83 ns/op 471.58 ns/op 1.22
naive computeProposerIndex 100000 validators 61.298 ms/op 50.887 ms/op 1.20
computeProposerIndex 100000 validators 8.9146 ms/op 7.9855 ms/op 1.12
naiveGetNextSyncCommitteeIndices 1000 validators 7.5153 s/op 7.3477 s/op 1.02
getNextSyncCommitteeIndices 1000 validators 241.60 ms/op 232.21 ms/op 1.04
naiveGetNextSyncCommitteeIndices 10000 validators 7.4473 s/op 7.2344 s/op 1.03
getNextSyncCommitteeIndices 10000 validators 231.47 ms/op 230.94 ms/op 1.00
naiveGetNextSyncCommitteeIndices 100000 validators 7.2617 s/op 6.7864 s/op 1.07
getNextSyncCommitteeIndices 100000 validators 242.18 ms/op 222.39 ms/op 1.09
naive computeShuffledIndex 100000 validators 22.387 s/op 24.039 s/op 0.93
cached computeShuffledIndex 100000 validators 566.54 ms/op 522.05 ms/op 1.09
naive computeShuffledIndex 2000000 validators 487.87 s/op 486.99 s/op 1.00
cached computeShuffledIndex 2000000 validators 30.980 s/op 33.512 s/op 0.92
computeProposers - vc 250000 9.4588 ms/op 9.3335 ms/op 1.01
computeEpochShuffling - vc 250000 42.967 ms/op 40.504 ms/op 1.06
getNextSyncCommittee - vc 250000 139.59 ms/op 143.51 ms/op 0.97
computeSigningRoot for AttestationData 25.548 us/op 24.808 us/op 1.03
hash AttestationData serialized data then Buffer.toString(base64) 1.6479 us/op 1.5066 us/op 1.09
toHexString serialized data 1.1147 us/op 1.0118 us/op 1.10
Buffer.toString(base64) 164.84 ns/op 165.54 ns/op 1.00
nodejs block root to RootHex using toHex 155.49 ns/op 126.32 ns/op 1.23
nodejs block root to RootHex using toRootHex 94.516 ns/op 77.581 ns/op 1.22
browser block root to RootHex using the deprecated toHexString 221.50 ns/op 199.73 ns/op 1.11
browser block root to RootHex using toHex 176.69 ns/op 162.91 ns/op 1.08
browser block root to RootHex using toRootHex 166.95 ns/op 156.18 ns/op 1.07

by benchmarkbot/action

const newWithdrawalCredentials = validator.withdrawalCredentials.slice();
const newWithdrawalCredentials = Uint8Array.prototype.slice.call(
validator.withdrawalCredentials,
0,
Copy link
Contributor

Choose a reason for hiding this comment

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

Is the second and third param of call() necessary? Can we do

Uint8Array.prototype.slice.call(validator.withdrawalCredentials);

Copy link
Member

Choose a reason for hiding this comment

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

I don't think it is necessary, but don't mind either way

@twoeths
Copy link
Contributor Author

twoeths commented Feb 22, 2025

sanity

just in case backed data is a Buffer

as pointed out on discord, we explicitly convert to Uint8Array if block is submitted through api

// We could just return the `Buffer` here which is a subclass of `Uint8Array` but downstream code does not require it
// and it's better to convert it here to avoid unexpected behavior such as `Buffer.prototype.slice` not copying memory
// See https://github.com/nodejs/node/issues/41588#issuecomment-1016269584
return new Uint8Array(payload.buffer, payload.byteOffset, payload.byteLength);

however, as a sanity check, we could consider asserting that when we pass the block to state-transition

@nflaig this withdrawalCredentials comes from validator which is part of BeaconState. And BeaconState could come from db which is Buffer

@nflaig
Copy link
Member

nflaig commented Feb 22, 2025

@nflaig this withdrawalCredentials comes from validator which is part of BeaconState. And BeaconState could come from db which is Buffer

yeah noticed that as well, was pointing that out because only the node that proposed the block has the issue, which is still unclear to me why that is the case

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Invalid state root upgrading validator to 0x02
3 participants