From 85c28509714664b2b16c0d0d8594a9dafc4907d4 Mon Sep 17 00:00:00 2001 From: Eugene Kabanov Date: Thu, 4 Jul 2024 04:08:07 +0300 Subject: [PATCH] Fix publishBlockV1() and publishBlockV2() SSZ decoding process. (#6408) --- .../eth2_apis/eth2_rest_serialization.nim | 24 ++++++++++++++----- 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/beacon_chain/spec/eth2_apis/eth2_rest_serialization.nim b/beacon_chain/spec/eth2_apis/eth2_rest_serialization.nim index 45b5e372b..96da33953 100644 --- a/beacon_chain/spec/eth2_apis/eth2_rest_serialization.nim +++ b/beacon_chain/spec/eth2_apis/eth2_rest_serialization.nim @@ -3536,7 +3536,9 @@ proc decodeBody*( of ConsensusFork.Phase0: let blck = try: - SSZ.decode(body.data, phase0.SignedBeaconBlock) + var res = SSZ.decode(body.data, phase0.SignedBeaconBlock) + res.root = hash_tree_root(res.message) + res except SerializationError as exc: return err(RestErrorMessage.init(Http400, UnableDecodeError, [version, exc.formatMsg("")])) @@ -3548,7 +3550,9 @@ proc decodeBody*( of ConsensusFork.Altair: let blck = try: - SSZ.decode(body.data, altair.SignedBeaconBlock) + var res = SSZ.decode(body.data, altair.SignedBeaconBlock) + res.root = hash_tree_root(res.message) + res except SerializationError as exc: return err(RestErrorMessage.init(Http400, UnableDecodeError, [version, exc.formatMsg("")])) @@ -3560,7 +3564,9 @@ proc decodeBody*( of ConsensusFork.Bellatrix: let blck = try: - SSZ.decode(body.data, bellatrix.SignedBeaconBlock) + var res = SSZ.decode(body.data, bellatrix.SignedBeaconBlock) + res.root = hash_tree_root(res.message) + res except SerializationError as exc: return err(RestErrorMessage.init(Http400, UnableDecodeError, [version, exc.formatMsg("")])) @@ -3572,7 +3578,9 @@ proc decodeBody*( of ConsensusFork.Capella: let blck = try: - SSZ.decode(body.data, capella.SignedBeaconBlock) + var res = SSZ.decode(body.data, capella.SignedBeaconBlock) + res.root = hash_tree_root(res.message) + res except SerializationError as exc: return err(RestErrorMessage.init(Http400, UnableDecodeError, [version, exc.formatMsg("")])) @@ -3584,7 +3592,9 @@ proc decodeBody*( of ConsensusFork.Deneb: let blckContents = try: - SSZ.decode(body.data, DenebSignedBlockContents) + var res = SSZ.decode(body.data, DenebSignedBlockContents) + res.signed_block.root = hash_tree_root(res.signed_block.message) + res except SerializationError as exc: return err(RestErrorMessage.init(Http400, UnableDecodeError, [version, exc.formatMsg("")])) @@ -3596,7 +3606,9 @@ proc decodeBody*( of ConsensusFork.Electra: let blckContents = try: - SSZ.decode(body.data, ElectraSignedBlockContents) + var res = SSZ.decode(body.data, ElectraSignedBlockContents) + res.signed_block.root = hash_tree_root(res.signed_block.message) + res except SerializationError as exc: return err(RestErrorMessage.init(Http400, UnableDecodeError, [version, exc.formatMsg("")]))