Skip to content

Commit

Permalink
feat:span batch txs recoverV
Browse files Browse the repository at this point in the history
Signed-off-by: Chen Kai <281165273grape@gmail.com>
  • Loading branch information
GrapeBaBa committed Jan 14, 2024
1 parent 3a88d5f commit cc4b3d7
Show file tree
Hide file tree
Showing 14 changed files with 160 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -454,6 +454,14 @@ public void setTotalBlockTxCount(long totalBlockTxCount) {
this.totalBlockTxCount = totalBlockTxCount;
}

public long getTotalBlockTxCount() {
return totalBlockTxCount;
}

public BigInteger getProtectedBits() {
return protectedBits;
}

public long getTotalLegacyTxCount() {
return totalLegacyTxCount;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@
import java.io.IOException;
import java.math.BigInteger;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;
import org.apache.tuweni.bytes.Bytes;
import org.hyperledger.besu.datatypes.TransactionType;
import org.junit.jupiter.api.Test;
import org.web3j.utils.Numeric;

Expand Down Expand Up @@ -136,6 +139,143 @@ void decodeAndEncode() throws IOException {
assertArrayEquals(Numeric.hexStringToByteArray(test), res);
}

@Test
void recoveryVUnprotected() throws IOException {
SpanBatchTxs txs = new SpanBatchTxs();
txs.setTotalBlockTxCount(37L);

URL url = Resources.getResource("recunprotectedsigs.txt");
String recunprotectedsigs = Resources.toString(url, Charsets.UTF_8);
txs.decodeTxSigsRS(Unpooled.wrappedBuffer(Numeric.hexStringToByteArray(recunprotectedsigs)));

URL url2 = Resources.getResource("recunprotectedyparity.txt");
String recunprotectedyparity = Resources.toString(url2, Charsets.UTF_8);
txs.decodeYParityBits(Unpooled.wrappedBuffer(Numeric.hexStringToByteArray(recunprotectedyparity)));

URL url3 = Resources.getResource("recunprotectedprotectedbits.txt");
String recunprotectedprotectedbits = Resources.toString(url3, Charsets.UTF_8);
txs.decodeProtectedBits(Unpooled.wrappedBuffer(Numeric.hexStringToByteArray(recunprotectedprotectedbits)));
List<TransactionType> txTypes = new ArrayList<>();
for (int i = 0; i < txs.getTotalBlockTxCount(); i++) {
txTypes.add(TransactionType.FRONTIER);
}
txs.setTxTypes(txTypes);
txs.recoverV(BigInteger.valueOf(108L));
long[] vs = new long[] {
27, 28, 27, 27, 28, 28, 28, 27, 28, 27, 28, 28, 28, 27, 28, 27, 27, 28, 28, 28, 27, 28, 28, 28, 27, 27, 28,
27, 28, 28, 27, 28, 28, 27, 28, 27, 27
};
long[] res = txs.getTxSigs().stream()
.map(spanBatchSignature -> spanBatchSignature.v().longValue())
.mapToLong(Long::longValue)
.toArray();

assertArrayEquals(vs, res);
}

@Test
void recoveryVLegacy() throws IOException {
SpanBatchTxs txs = new SpanBatchTxs();
txs.setTotalBlockTxCount(37L);
txs.setTotalLegacyTxCount(37L);

URL url = Resources.getResource("reclegcysigs.txt");
String recunprotectedsigs = Resources.toString(url, Charsets.UTF_8);
txs.decodeTxSigsRS(Unpooled.wrappedBuffer(Numeric.hexStringToByteArray(recunprotectedsigs)));

URL url2 = Resources.getResource("reclegcyyparity.txt");
String recunprotectedyparity = Resources.toString(url2, Charsets.UTF_8);
txs.decodeYParityBits(Unpooled.wrappedBuffer(Numeric.hexStringToByteArray(recunprotectedyparity)));

URL url3 = Resources.getResource("reclegcyprotectedbits.txt");
String recunprotectedprotectedbits = Resources.toString(url3, Charsets.UTF_8);
txs.decodeProtectedBits(Unpooled.wrappedBuffer(Numeric.hexStringToByteArray(recunprotectedprotectedbits)));
List<TransactionType> txTypes = new ArrayList<>();
for (int i = 0; i < txs.getTotalBlockTxCount(); i++) {
txTypes.add(TransactionType.FRONTIER);
}
txs.setTxTypes(txTypes);
txs.recoverV(BigInteger.valueOf(108L));
long[] vs = new long[] {
251, 252, 251, 251, 251, 251, 252, 251, 252, 251, 251, 252, 252, 251, 252, 251, 251, 251, 251, 251, 252,
252, 252, 251, 252, 251, 252, 251, 252, 252, 252, 252, 251, 251, 252, 252, 251
};
long[] res = txs.getTxSigs().stream()
.map(spanBatchSignature -> spanBatchSignature.v().longValue())
.mapToLong(Long::longValue)
.toArray();

assertArrayEquals(vs, res);
}

@Test
void recoveryVAccessList() throws IOException {
SpanBatchTxs txs = new SpanBatchTxs();
txs.setTotalBlockTxCount(37L);

URL url = Resources.getResource("recaccsigs.txt");
String recunprotectedsigs = Resources.toString(url, Charsets.UTF_8);
txs.decodeTxSigsRS(Unpooled.wrappedBuffer(Numeric.hexStringToByteArray(recunprotectedsigs)));

URL url2 = Resources.getResource("recaccyparity.txt");
String recunprotectedyparity = Resources.toString(url2, Charsets.UTF_8);
txs.decodeYParityBits(Unpooled.wrappedBuffer(Numeric.hexStringToByteArray(recunprotectedyparity)));

URL url3 = Resources.getResource("recaccprotectedbits.txt");
String recunprotectedprotectedbits = Resources.toString(url3, Charsets.UTF_8);
txs.decodeProtectedBits(Unpooled.wrappedBuffer(Numeric.hexStringToByteArray(recunprotectedprotectedbits)));
List<TransactionType> txTypes = new ArrayList<>();
for (int i = 0; i < txs.getTotalBlockTxCount(); i++) {
txTypes.add(TransactionType.ACCESS_LIST);
}
txs.setTxTypes(txTypes);
txs.recoverV(BigInteger.valueOf(108L));
long[] vs = new long[] {
1, 1, 1, 0, 1, 1, 1, 0, 0, 1, 0, 0, 1, 1, 1, 1, 1, 0, 0, 1, 1, 1, 0, 1, 0, 1, 1, 0, 0, 0, 1, 0, 0, 0, 1, 1,
0
};
long[] res = txs.getTxSigs().stream()
.map(spanBatchSignature -> spanBatchSignature.v().longValue())
.mapToLong(Long::longValue)
.toArray();

assertArrayEquals(vs, res);
}

@Test
void recoveryVE1559() throws IOException {
SpanBatchTxs txs = new SpanBatchTxs();
txs.setTotalBlockTxCount(37L);

URL url = Resources.getResource("rece1559sigs.txt");
String recunprotectedsigs = Resources.toString(url, Charsets.UTF_8);
txs.decodeTxSigsRS(Unpooled.wrappedBuffer(Numeric.hexStringToByteArray(recunprotectedsigs)));

URL url2 = Resources.getResource("rece1559yparity.txt");
String recunprotectedyparity = Resources.toString(url2, Charsets.UTF_8);
txs.decodeYParityBits(Unpooled.wrappedBuffer(Numeric.hexStringToByteArray(recunprotectedyparity)));

URL url3 = Resources.getResource("rece1559protectedbits.txt");
String recunprotectedprotectedbits = Resources.toString(url3, Charsets.UTF_8);
txs.decodeProtectedBits(Unpooled.wrappedBuffer(Numeric.hexStringToByteArray(recunprotectedprotectedbits)));
List<TransactionType> txTypes = new ArrayList<>();
for (int i = 0; i < txs.getTotalBlockTxCount(); i++) {
txTypes.add(TransactionType.EIP1559);
}
txs.setTxTypes(txTypes);
txs.recoverV(BigInteger.valueOf(108L));
long[] vs = new long[] {
0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 0, 0, 1, 0, 1, 1, 1, 0, 1, 0, 1, 1, 0, 1, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1,
0
};
long[] res = txs.getTxSigs().stream()
.map(spanBatchSignature -> spanBatchSignature.v().longValue())
.mapToLong(Long::longValue)
.toArray();

assertArrayEquals(vs, res);
}

//
// @Test
// void TestSpanBatchTxsContractCreationBits()
Expand Down
1 change: 1 addition & 0 deletions hildr-utilities/src/test/resources/recaccprotectedbits.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0x
1 change: 1 addition & 0 deletions hildr-utilities/src/test/resources/recaccsigs.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0xf76f1cd2c35e493d64df97610359a7bf26ec9e6aab9704c3f42c09ad239f5c02679634002186eb24289056391ae1e9390b6a833c0d264da071a7fd6a7ed909488159d21b5b06b744c64fc50654ca042586ac05e47a832ae8401d5c377570caf626edf29b5afb375c6702d3a61fe1f2ad0dc78963f06089a59fe2e75324f20a61b63adb59189f1e52b2ba64204f41e6b15d2c98b88a551a9b7fe3d32486db5fc410110614df3391ba2399d6e6ffb2df3266ab24f4b7957e5f79071f2054a11a0e9245284eb72ccfa224c007cce90fe096a96c25e7b2a567dc08cd248ff24dba12056c55523ba900f07a7bf6948ceb6b6b1b7e94756ef3777e6300a3d292c85f0dcda6b8f13f42b1eb0c133f026072aade69bce585bd8c73f388ad2fea927c4e2f7af8df36059ebe4294337df1bed8962106a1219a5bf52864f7e0459644b1ee59315d631a617c752406283534a01f04b7ba5d60f46eae60381e4413835c178bc009a9354fa2071e745941dd74f35f0ca8885594d537d59cbcadd5facea4c59d33bba81a2f56a246db5b303e4700a6fe94e530eaa017d0f2c84f1e8ab6b60e8e9b5d8d5ad611b2960eb54fb06effbb2c7c790ca503786dbf00b99e5f685e09d654a47a7a088ccc9008eb6d2f009bda9be00c6caab53db9dfa4e38ca74a113b629360ee6dd61abcd88ffc5b4acdb522c84f751ff5dfba8d1ebffce65de1ad71e165a5626bf63a1b5c6d10a0e25cf7168718f02a0da2a7fb50a397a41ba5439c5ce434a92d453b81e255fd370425c1772f690cc39ccfc6ba45fa2e4c92d540bd311d544fbafd65f66d3cbaa7d828ea5c373b3584b24bd661d66393bcbcbcc7e1da24532dbf882a04dabb7bd04ecea3893448955416923e38fb0728ca5f29e248f9b94430f424719772d4c2daa9f01f5a4c38c5098ce24d0be5c41a3b609dac135173749983e90b087d635dbe575e0532a37175eb7ec5ee4d43713441657f1659306c3504ec766deab458cdae13c874c03605b6df7e22d71c3124f2e85094c21b4a96568cf439c3a587123e58d84dca0fd437717670cea11b4c13b629c0c04fac5a585ea39560fdf9faee83ddbb3de9d04564ea9f1121b1b2a6da55a1c29e4fae71f0251565818a8371e18e17cee8d6a60b7051168b2fbf95c6bf3d182663698417a94f74b90886d4dfd26954062fe0b852ee9b0807c9891d3a34692c9167743f695c26ce41b80cd7760d81a2730a3d96384637247daa735a4a4bbe57130c2516be9f36980326b754f5ca5119e24fd075ca5a453551468650d13bcc71f170c7deeae632155f0fc99d0f6163d6fb3547d958b4dd38d42945279f649713b7e04e58aa48cfdc58ec86399b55e59d3028c1e2e1c90db854422a49f0725696d9d6acb1e9213dbb624c6e6b4f9c64dd6c773a12d87c1bde0924a01402fffe3cff88178ff3af2c95c4a5a3a9a45575a388034282eb96b2d89f5e9c59b211a814294e8e10abef7ffb8422ee4d3f5acb8c07bcde66863872ec79ee36e89e6c3407f556edc108d68c1dea5c242c2c4ecf03bea852d77c9a60392a0b2257afa6674151f3aad80545336144c970d30c640349a06fb6a7587b37811e6386c5a34f4206851340797ee5ba8f40225ffd3adac3212e6d7e6625843c5d515e3e2f3518fb6644c55e318fa9798fdc1309fd1570fd183ad37b6a707a50f1ceb9005435472bea527af98dbc68e69fc8cef7ea49a3e43890f1b4d1d0b58e6e54430b7824ea55f098eec122352537c5a84bd27dd2d9e76294ad3bea4086df3d70f2f3477422e42a5397f7f693aec274e0e203026b2b0aca2ea23b5b4936b92cb26e08fa0d9aa7602b31914bfdf010c042b45f4fb54f5d4504c39bd54b1d9e96da910d3fbac89b68bc65892239f73c555d9675c6f99befcc540931409c1003b6de285771e4f0fa7257907b6d633630b0e20d924ab269c3f8a462520b63b81a1c2dc2bceba20c2f3ab6a65536f7546635826496c593206016159226e8576bcf402dd91cdf7e218c95c496b2a2a3f65a95b11a1214008e2ae10505fb43710101c67489bf395e95a3f4c33aa5e68c23fbd4891d1d1b679a6fe667c798aea9d1addd28deb5f978be49531c09eefae0247bc554fbd7f7014d3df9fcf973a9f6375762f2d4f9787a1ee23dec19969c94aa14649abf77196a67cbd8e599df65a0ec92bc205bfc7b99222de7184278e0c52021c2ed546424f10bac57690b8fe16ead5bc537669bb489f5ac81795fb9353d201a5e8c6000b6ae32f9ec70207539b6f3062694d90c29bc8a3455c45c1be8fc9a6d52dd8744ffeee11e3dd92a5ea363da8d1436c8e356354a8f94826ea73fe79e1075a168ddca5c6dfc63c195c444db676249082eb28895e2faa79d679183c988738379f712da9bf29a297b865c573cc66459a193697dc964f8f3954d74a12481363a0313a4ad75d8b24bede7023f793f897fe36c7ba140fbbc2c62bbc8200cd87201a2b5a3405322f1b1e180c319285b3098acebf46630306eb70fab908dabbb592b23a8f70bfdcef1ee747485b5bcb60be586cbd08ddd8bbdc301ed7e2e57ae2ee81ebd0050397ea7710d69d09fbbc60ccc4618fe513cdd23111a89c0d0976bcc361ed44210e0df077e90bf4f90781475a3f053b39cc35c462bbf0a2e6b1f795c793493f95daeb7b083a35cf8b8c5539958d9c5f67ab8d6cd43a02c06d963b690c05ce59ea50c6feaa8b127f4b56897c6963179b9b108aaa1d75c9f75a806e9759dcacfde6d77d59ab0f5095bfc20a0a919ef299fdb40fe7eb324bc79321a70e5791f2027fb6590d80d701b98d0aaeff2e330fd7afdb04705ff9ae795b239a37172475610f63dad355a94fd264a38aefabf90297aeb974541b06e0c3af44404b52f69c5d5ef3cbb5a64a754391ed2a9fd60577f2a54c916a8b0d366064659af24a87456db2335d3b3c65f6aa339ed2189b34dd8aab658927309a43db946d1a988de892951e2c822d6d82d159ffcc16ab3eeae2df758d4d9d0c19bbe6efedc657533059db032c3d6f59988d3872a14434f1e89ee435019ee75a9c1465a9bdb841485cfd0e0e216d87a5e8fa0652c3f5896c788d5058897c9307dba6fef929a4d3c15143e546abdaae92acb71eb9e80d5a0e9d4c38e7d3ad40d88e1c749e921c8edcdb4efd7a95569bad050183473b33634c654135b085a8de26a30e7b16ddb1655d0955e0f6a3efc6da50d2cf3e764f7dce04e79f9f6de8a027dce88ef15df3f1948979423c28c5cd246dd39656fb40013f8fb62b8331adfdbf50cb1780db21f2975ad0a37ddea98fe6f78357b28d639ed8ccb005d3e9b5b7d12338e2f4c76d7
1 change: 1 addition & 0 deletions hildr-utilities/src/test/resources/recaccyparity.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0x0c46b9f277
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0x
1 change: 1 addition & 0 deletions hildr-utilities/src/test/resources/rece1559sigs.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0x952be1536bd3de6df77c84d79a3baab6beea6636393d5fdfd688aba52bf92f40685d056d935f3334d4f2b5414773666cbbb1a25f82a259612429c2a486dac8685045c10fc5b67da4e7e76bc8fb3c45090ca6c93d213c9cf08599d9adcc4a2d34154b3c258071954811258940be58c49bbeda054b058ec84243939a043304dcd7af69c531e10beccd76afe2d51020628a021deb9be392aa45e5dbb9798350d19912582a9f8a59102c480e92494d65d3c73fb9ce95ba14bea8a96baa242e5cd874da0cb937f8b531702024977d20999c3c4c78fc1fd4548940ea10f2f303b91f2629a2dd22c98f1234056f63748c8eaf6353cf498fef658c7db913f4c3975d3093cd35ed639e80391685964b4e727314c97905fd1bce7306b6289445bfe43e4f3a556e509e7f0a66205ae51077fce2bab80d567d558c864f8e4ff45d0971c557e69a68a7815369900ba8b635808586903250b68315ff1497857ffb13fd641f65907f2523ca86b041fe3fe8befdf0d0e4ea8959da4bc0330be7cafae0a7a7b7c7867861339057799b86acb1d2fbe4a900c3d688c0b668535e231bb818a31fdcece7761409e953ae2e3c619e51200ee907e6603a75990e761aca1fed16ac086d745def1f711d643b9f043e05bec512dd9ed9e2c06ccb328f9a65a2b4458630fac02b0224a131cffd6296e9aadeabf04aba1d2fcb1fd51ebacd853471cd22586575bca3af5b82cf5b1f29376846ad1093319271dabe421d05f9da316bab64445514686eb3ad8346ee78f484c0da3215e82ad98cce005f79b5b96c30fc49c6644d281937ebe81e7cf88d2895d5720bc4d7b104f996fcba6d2dac4f6ceb0c8c9df41b5968b3fdb3b4aec295120e74853b9071689ef394444f2a52fbdeb2c02182561dd0ab19100684e032775ce8280638ca7353b778a4412a9c79e9180cdb8e7b3061516efe7435eb6c34860d82388607b5e3fcb4b79b96ea97e1dbecccade74a62181ef869047b53af5d58ebf905791129273096c8da68e029748544dc4ae1755ec7db70acdaf75e759059ac1ca253dc0d74072f16cf118fedbe3ca6bf9eb8750cee3b6291948af9cdf377a4f42e6e946d3b14067249df65ed30333ac1ac5971dfa25006c73d55f5795e51a0e646fdbb1558b2a9d006c5ae7af5786dc6e8fb9a04082186d0a59ea104678589ef42406e4b6ee0fee45db6bfadd3ff53d3f33f2f963ead719cd1f920bba354124184f8a27212cdb52fe7e6d8288300dccbd343d6dd7a84bf4fe9c0835f4cf62ec1e1af75a2a6df3e681361e78443979fc4e7ec99463f5c1a7a2eeff522aefb085108c7a843c513bedccd1a9a1374bf373ef22a912a287336f6292ba22ef1634786c4c2d12fc25838cd2940de5efdc4f825b3c7c60936606984499cfbf97d62ce5a7095b6292f612834cbe570072a0a9dbdaf1d52bfffe5052e153b68a2dd88d263786d23d26d9f340ea203affc616f857a2525d139d54c15e7cf5b13136d3c4d0e2ffa8b960f8e96448bf035f72027d89c516421bfd127c61731a4264db00bdba7c492b87fb9d463c4f18c84751e6906d329d62e836bba4233f3879a17ab2d941b16219b24e3e3596799a6e16cca447299d70b0dcc0eea32cc4264e17f8db8a5d6c56bdf0d3494151e13186a84c229c26dd98dd6f29ac879b0be3e3ed1281426dc77bf45c570cbfe6b327d672fa2126797986a2fff82f972b644a47148d7112a77d10bf7f19f19161760f164c3cdfbbf12f5e1da2f8fef7386eee3d31e6584f670fe654a98e5425f8b2f0df79f019145d3d522990bc441933b565e9f9df3d631865c53d9f4a0061bd44393976737c2664f28992a6da96644e2a61774d6c1245879929c191ee189a41cad0a0e5f659644248add1e35d9fc252f6e91f27f5bdd27ed2b0b30628b2e9a71be295c342411eee2d12383e324916e78905dffbdf7f96328e312ee3cd5e16f12c3b666ef88d81f3c092d15f06b43db2204c1fb138bf41e52414d91b9a7426b7fb8f72f8608ef1895e5f19d062a981cf058e182ea1bd63de58fc5d0232c6be60984c87e45abd77dbc4721b06499ef70bcbbb851d4a83466f60288a5bdcecc7f1e8ad1030d06d4efbcbe1409ff449e1d1a7a8c53463c1b27162d7043b4c65046d96dd52e4104d44c7e11495a75f414bcaf7e328d64662db4e035a1a1118612d5122e665a5d8204fa5888ef59305cfb37bfed5364a6192c433bb8e2d6f18f875007320048ceb2262809b6c26f3f654b155120822bd988e2309b3bf428ae39086323be0cbf30bbeb2b11fd3b8312799f1fb2651404794a60f4f9b39922dbacc0a6c0c9427bc78ed902c53242b4c52b56c5ccd65935ce64990341c5eb77e7bc85747378385393d881e764bb508ffb3aa2712156ec9dd936493be9489fdd3efb9cfdbcdb8faf91c8977b60de0d26a71a31819ae94e200556b787c0921eca6fe796f0395cf68ffd311452bb7c8e1739f462122e69492ce0191e72692169ddeff213453efffa032287e4ed9c2d973acdbaa4db49abf7c20e7f7c1d3d27d3d8bb6158519621af8739dfcee18c5e337817a3ff3c417262579e55db13c56161f71d5a78333689f88bd1abf52f6145fe2d3b9b45c8e5d350fbc90cdcaa739994af14d14ba79fba1fbac6bc63eeaad81e50af0488167deba1871960b98063ea0e0aca0bf9ee9f6adc38794c4bf24a20386fdfefba8e81b93b8efade4168443fd976d99d52814b02b87858f640b97f57178be04a44596615842e8edf6f9052c747b3fc1df4cbb128774876658bf67f1ab3c3c37de7dae7f970f03b6fd49e144eba1dd8c6decc19320b6d67ec57f06fcfd42fa5264b638ceff3bde0c4d677b94315643894e79039577a11de7640af6ac7ebf4480b6c140eb094196eb5d3a5ac741b14431c3e793133278f85d742feb32e672e10b64f639ef63437700d3feed874547a68d99b5b60a5ab973ae0952903426d36d39053f46c6614ea7ce629558b0102beaf4b38d9838ccec98e012a7c40ce80c774988c2dac48b5590e07a47139698df7282c560d73063b4ab3400ed4f2492a0b42df76d387e1e291b66791018ec192551f70d4dce37276efa7b2f7a3a1eaa518fdfbc026bffe00ca2951cc3c4e3c22a479286b95d81908679e06c56146724dc77945ffb8aa24907df1b32899ebc233e5c16cc8cf902c5c7acc18a1508e41116ff34218255fd3c3271c51195ba6616135c6dd70d324bfee1dc160844ad69ee509e1aa84e2e50f5741eedfee60714e9de9bf99d826b00f585c744609b0938a0eddb033e503aef9cdb76274745a5c222a7042e3064bc5917b4be8510143b6c7cdb1c799ec
1 change: 1 addition & 0 deletions hildr-utilities/src/test/resources/rece1559yparity.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0x0ff96ba4cc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0x1fffffffff
Loading

0 comments on commit cc4b3d7

Please sign in to comment.