pyth.js 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382
  1. const jsonfile = require('jsonfile');
  2. const elliptic = require('elliptic');
  3. const BigNumber = require('bignumber.js');
  4. const PythSDK = artifacts.require("PythSDK");
  5. const { deployProxy, upgradeProxy } = require('@openzeppelin/truffle-upgrades');
  6. const {expectRevert} = require('@openzeppelin/test-helpers');
  7. const Wormhole = artifacts.require("Wormhole");
  8. const PythProxy = artifacts.require("PythProxy");
  9. const MockPythProxyUpgrade = artifacts.require("MockPythProxyUpgrade");
  10. const testSigner1PK = "cfb12303a19cde580bb4dd771639b0d26bc68353645571a8cff516ab2ee113a0";
  11. const testSigner2PK = "892330666a850761e7370376430bb8c2aa1494072d3bfeaed0c4fa3d5a9135fe";
  12. contract("Pyth", function () {
  13. const testSigner1 = web3.eth.accounts.privateKeyToAccount(testSigner1PK);
  14. const testSigner2 = web3.eth.accounts.privateKeyToAccount(testSigner2PK);
  15. const testChainId = "2";
  16. const testGovernanceChainId = "3";
  17. const testGovernanceContract = "0x0000000000000000000000000000000000000000000000000000000000000004";
  18. const testPyth2WormholeChainId = "1";
  19. const testPyth2WormholeEmitter = "0x71f8dcb863d176e2c420ad6610cf687359612b6fb392e0642b0ca6b1f186aa3b";
  20. const notOwnerError = "Ownable: caller is not the owner -- Reason given: Ownable: caller is not the owner.";
  21. beforeEach(async function () {
  22. this.pythProxy = await deployProxy(
  23. PythProxy,
  24. [
  25. testChainId,
  26. (await Wormhole.deployed()).address,
  27. testPyth2WormholeChainId,
  28. testPyth2WormholeEmitter,
  29. ]
  30. );
  31. });
  32. it("should be initialized with the correct signers and values", async function(){
  33. // chain id
  34. const chainId = await this.pythProxy.chainId();
  35. assert.equal(chainId, testChainId);
  36. // pyth2wormhole
  37. const pyth2wormChain = await this.pythProxy.pyth2WormholeChainId();
  38. assert.equal(pyth2wormChain, testPyth2WormholeChainId);
  39. const pyth2wormEmitter = await this.pythProxy.pyth2WormholeEmitter();
  40. assert.equal(pyth2wormEmitter, testPyth2WormholeEmitter);
  41. })
  42. it("should allow upgrades from the owner", async function(){
  43. // Check that the owner is the default account Truffle
  44. // has configured for the network. upgradeProxy will send
  45. // transactions from the default account.
  46. const accounts = await web3.eth.getAccounts();
  47. const defaultAccount = accounts[0];
  48. const owner = await this.pythProxy.owner();
  49. assert.equal(owner, defaultAccount);
  50. // Try and upgrade the proxy
  51. const newImplementation = await upgradeProxy(
  52. this.pythProxy.address, MockPythProxyUpgrade);
  53. // Check that the new upgrade is successful
  54. assert.equal(await newImplementation.isUpgradeActive(), true);
  55. assert.equal(this.pythProxy.address, newImplementation.address);
  56. })
  57. it("should allow ownership transfer", async function(){
  58. // Check that the owner is the default account Truffle
  59. // has configured for the network.
  60. const accounts = await web3.eth.getAccounts();
  61. const defaultAccount = accounts[0];
  62. assert.equal(await this.pythProxy.owner(), defaultAccount);
  63. // Check that another account can't transfer the ownership
  64. await expectRevert(this.pythProxy.transferOwnership(accounts[1], {from: accounts[1]}), notOwnerError);
  65. // Transfer the ownership to another account
  66. await this.pythProxy.transferOwnership(accounts[2], {from: defaultAccount});
  67. assert.equal(await this.pythProxy.owner(), accounts[2]);
  68. // Check that the original account can't transfer the ownership back to itself
  69. await expectRevert(this.pythProxy.transferOwnership(defaultAccount, {from: defaultAccount}), notOwnerError);
  70. // Check that the new owner can transfer the ownership back to the original account
  71. await this.pythProxy.transferOwnership(defaultAccount, {from: accounts[2]});
  72. assert.equal(await this.pythProxy.owner(), defaultAccount);
  73. })
  74. it("should not allow upgrades from the another account", async function(){
  75. // Check that the owner is the default account Truffle
  76. // has configured for the network.
  77. const accounts = await web3.eth.getAccounts();
  78. const defaultAccount = accounts[0];
  79. assert.equal(await this.pythProxy.owner(), defaultAccount);
  80. // Transfer the ownership to another account
  81. const newOwnerAccount = accounts[1];
  82. await this.pythProxy.transferOwnership(newOwnerAccount, {from: defaultAccount});
  83. assert.equal(await this.pythProxy.owner(), newOwnerAccount);
  84. // Try and upgrade using the default account, which will
  85. // because we are no longer the owner.
  86. await expectRevert(upgradeProxy(this.pythProxy.address, MockPythProxyUpgrade), notOwnerError);
  87. })
  88. const rawBatchPriceAttestation = "0x"+"503257480002020004009650325748000201c0e11df4c58a4e53f2bc059ba57a7c8f30ddada70b5bdc3753f90b824b64dd73c1902e05cdf03bc089a943d921f87ccd0e3e1b774b5660d037b9f428c0d3305e01000000000000071dfffffffb00000000000005f70000000132959bbd00000000c8bfed5f00000000000000030000000041c7b65b00000000c8bfed5f0000000000000003010000000000622f65f4503257480002017090c4ecf0309718d04c5a162c08aa4b78f533f688fa2f3ccd7be74c2a253a54fd4caca566fc44a9d6585420959d13897877c606477b3f0e7f247295b7275620010000000000000440fffffffb00000000000005fb000000015cfe8c9d00000000e3dbaa7f00000000000000020000000041c7c5bb00000000e3dbaa7f0000000000000007010000000000622f65f4503257480002012f064374f55cb2efbbef29329de3b652013a76261876c55a1caf3a489c721ccd8c5dd422900917e8e26316fe598e8f062058d390644e0e36d42c187298420ccd010000000000000609fffffffb00000000000005cd00000001492c19bd00000000dd92071f00000000000000020000000041c7d3fb00000000dd92071f0000000000000001010000000000622f65f45032574800020171ddabd1a2c1fb6d6c4707b245b7c0ab6af0ae7b96b2ff866954a0b71124aee517fbe895e5416ddb4d5af9d83c599ee2c4f94cb25e8597f9e5978bd63a7cdcb70100000000000007bcfffffffb00000000000005e2000000014db2995d00000000dd8f775f00000000000000020000000041c7df9b00000000dd8f775f0000000000000003010000000000622f65f4";
  89. it("should parse batch price attestation correctly", async function() {
  90. const magic = 1345476424;
  91. const version = 2;
  92. let parsed = await this.pythProxy.parseBatchPriceAttestation(rawBatchPriceAttestation);
  93. // Check the header
  94. assert.equal(parsed.header.magic, magic);
  95. assert.equal(parsed.header.version, version);
  96. assert.equal(parsed.header.payloadId, 2);
  97. assert.equal(parsed.nAttestations, 4);
  98. assert.equal(parsed.attestationSize, 150);
  99. assert.equal(parsed.attestations.length, 4);
  100. // Attestation #1
  101. assert.equal(parsed.attestations[0].header.magic, magic);
  102. assert.equal(parsed.attestations[0].header.version, version);
  103. assert.equal(parsed.attestations[0].header.payloadId, 1);
  104. assert.equal(parsed.attestations[0].productId, "0xc0e11df4c58a4e53f2bc059ba57a7c8f30ddada70b5bdc3753f90b824b64dd73");
  105. assert.equal(parsed.attestations[0].priceId, "0xc1902e05cdf03bc089a943d921f87ccd0e3e1b774b5660d037b9f428c0d3305e");
  106. assert.equal(parsed.attestations[0].priceType, 1);
  107. assert.equal(parsed.attestations[0].price, 1821);
  108. assert.equal(parsed.attestations[0].exponent, -5);
  109. assert.equal(parsed.attestations[0].emaPrice.value, 1527);
  110. assert.equal(parsed.attestations[0].emaPrice.numerator, 5143632829);
  111. assert.equal(parsed.attestations[0].emaPrice.denominator, 3368021343);
  112. assert.equal(parsed.attestations[0].emaConf.value, 3);
  113. assert.equal(parsed.attestations[0].emaConf.numerator, 1103607387);
  114. assert.equal(parsed.attestations[0].emaConf.denominator, 3368021343);
  115. assert.equal(parsed.attestations[0].confidenceInterval, 3);
  116. assert.equal(parsed.attestations[0].status, 1);
  117. assert.equal(parsed.attestations[0].corpAct, 0);
  118. assert.equal(parsed.attestations[0].timestamp, 1647273460);
  119. // Attestation #2
  120. assert.equal(parsed.attestations[1].header.magic, magic);
  121. assert.equal(parsed.attestations[1].header.version, version);
  122. assert.equal(parsed.attestations[1].header.payloadId, 1);
  123. assert.equal(parsed.attestations[1].productId, "0x7090c4ecf0309718d04c5a162c08aa4b78f533f688fa2f3ccd7be74c2a253a54");
  124. assert.equal(parsed.attestations[1].priceId, "0xfd4caca566fc44a9d6585420959d13897877c606477b3f0e7f247295b7275620");
  125. assert.equal(parsed.attestations[1].priceType, 1);
  126. assert.equal(parsed.attestations[1].price, 1088);
  127. assert.equal(parsed.attestations[1].exponent, -5);
  128. assert.equal(parsed.attestations[1].emaPrice.value, 1531);
  129. assert.equal(parsed.attestations[1].emaPrice.numerator, 5855153309);
  130. assert.equal(parsed.attestations[1].emaPrice.denominator, 3822824063);
  131. assert.equal(parsed.attestations[1].emaConf.value, 2);
  132. assert.equal(parsed.attestations[1].emaConf.numerator, 1103611323);
  133. assert.equal(parsed.attestations[1].emaConf.denominator, 3822824063);
  134. assert.equal(parsed.attestations[1].confidenceInterval, 7);
  135. assert.equal(parsed.attestations[1].status, 1);
  136. assert.equal(parsed.attestations[1].corpAct, 0);
  137. assert.equal(parsed.attestations[1].timestamp, 1647273460);
  138. // Attestation #3
  139. assert.equal(parsed.attestations[2].header.magic, magic);
  140. assert.equal(parsed.attestations[2].header.version, version);
  141. assert.equal(parsed.attestations[2].header.payloadId, 1);
  142. assert.equal(parsed.attestations[2].productId, "0x2f064374f55cb2efbbef29329de3b652013a76261876c55a1caf3a489c721ccd");
  143. assert.equal(parsed.attestations[2].priceId, "0x8c5dd422900917e8e26316fe598e8f062058d390644e0e36d42c187298420ccd");
  144. assert.equal(parsed.attestations[2].priceType, 1);
  145. assert.equal(parsed.attestations[2].price, 1545);
  146. assert.equal(parsed.attestations[2].exponent, -5);
  147. assert.equal(parsed.attestations[2].emaPrice.value, 1485);
  148. assert.equal(parsed.attestations[2].emaPrice.numerator, 5522594237);
  149. assert.equal(parsed.attestations[2].emaPrice.denominator, 3717334815);
  150. assert.equal(parsed.attestations[2].emaConf.value, 2);
  151. assert.equal(parsed.attestations[2].emaConf.numerator, 1103614971);
  152. assert.equal(parsed.attestations[2].emaConf.denominator, 3717334815);
  153. assert.equal(parsed.attestations[2].confidenceInterval, 1);
  154. assert.equal(parsed.attestations[2].status, 1);
  155. assert.equal(parsed.attestations[2].corpAct, 0);
  156. assert.equal(parsed.attestations[2].timestamp, 1647273460);
  157. // Attestation #4
  158. assert.equal(parsed.attestations[3].header.magic, magic);
  159. assert.equal(parsed.attestations[3].header.version, version);
  160. assert.equal(parsed.attestations[3].header.payloadId, 1);
  161. assert.equal(parsed.attestations[3].productId, "0x71ddabd1a2c1fb6d6c4707b245b7c0ab6af0ae7b96b2ff866954a0b71124aee5");
  162. assert.equal(parsed.attestations[3].priceId, "0x17fbe895e5416ddb4d5af9d83c599ee2c4f94cb25e8597f9e5978bd63a7cdcb7");
  163. assert.equal(parsed.attestations[3].priceType, 1);
  164. assert.equal(parsed.attestations[3].price, 1980);
  165. assert.equal(parsed.attestations[3].exponent, -5);
  166. assert.equal(parsed.attestations[3].emaPrice.value, 1506);
  167. assert.equal(parsed.attestations[3].emaPrice.numerator, 5598517597);
  168. assert.equal(parsed.attestations[3].emaPrice.denominator, 3717166943);
  169. assert.equal(parsed.attestations[3].emaConf.value, 2);
  170. assert.equal(parsed.attestations[3].emaConf.numerator, 1103617947);
  171. assert.equal(parsed.attestations[3].emaConf.denominator, 3717166943);
  172. assert.equal(parsed.attestations[3].confidenceInterval, 3);
  173. assert.equal(parsed.attestations[3].status, 1);
  174. assert.equal(parsed.attestations[3].corpAct, 0);
  175. assert.equal(parsed.attestations[3].timestamp, 1647273460);
  176. })
  177. async function attest(contract, data) {
  178. const vm = await signAndEncodeVM(
  179. 1,
  180. 1,
  181. testPyth2WormholeChainId,
  182. testPyth2WormholeEmitter,
  183. 0,
  184. data,
  185. [
  186. testSigner1PK
  187. ],
  188. 0,
  189. 0
  190. );
  191. await contract.attestPriceBatch("0x"+vm);
  192. }
  193. it("should attest price updates over wormhole", async function() {
  194. await attest(this.pythProxy, rawBatchPriceAttestation);
  195. })
  196. it("should cache price updates", async function() {
  197. await attest(this.pythProxy, rawBatchPriceAttestation);
  198. let first = await this.pythProxy.latestPriceInfo("0xc1902e05cdf03bc089a943d921f87ccd0e3e1b774b5660d037b9f428c0d3305e");
  199. assert.equal(first.priceFeed.id, "0xc1902e05cdf03bc089a943d921f87ccd0e3e1b774b5660d037b9f428c0d3305e");
  200. assert.equal(first.priceFeed.productId, "0xc0e11df4c58a4e53f2bc059ba57a7c8f30ddada70b5bdc3753f90b824b64dd73");
  201. assert.equal(first.priceFeed.price, 1821);
  202. assert.equal(first.priceFeed.conf, 3);
  203. assert.equal(first.priceFeed.expo, -5);
  204. assert.equal(first.priceFeed.status.toString(), PythSDK.PriceStatus.TRADING.toString());
  205. assert.equal(first.priceFeed.numPublishers, 0);
  206. assert.equal(first.priceFeed.maxNumPublishers, 0);
  207. assert.equal(first.priceFeed.emaPrice, 1527);
  208. assert.equal(first.priceFeed.emaConf, 3);
  209. assert.equal(first.attestationTime, 1647273460);
  210. let second = await this.pythProxy.latestPriceInfo("0xfd4caca566fc44a9d6585420959d13897877c606477b3f0e7f247295b7275620");
  211. assert.equal(second.priceFeed.id, "0xfd4caca566fc44a9d6585420959d13897877c606477b3f0e7f247295b7275620");
  212. assert.equal(second.priceFeed.productId, "0x7090c4ecf0309718d04c5a162c08aa4b78f533f688fa2f3ccd7be74c2a253a54");
  213. assert.equal(second.priceFeed.price, 1088);
  214. assert.equal(second.priceFeed.conf, 7);
  215. assert.equal(second.priceFeed.expo, -5);
  216. assert.equal(second.priceFeed.status.toString(), PythSDK.PriceStatus.TRADING.toString());
  217. assert.equal(second.priceFeed.numPublishers, 0);
  218. assert.equal(second.priceFeed.maxNumPublishers, 0);
  219. assert.equal(second.priceFeed.emaPrice, 1531);
  220. assert.equal(second.priceFeed.emaConf, 2);
  221. assert.equal(second.attestationTime, 1647273460);
  222. })
  223. it("should only cache updates for new prices", async function() {
  224. // This test sends two batches of updates, for the same Price IDs. The second batch contains
  225. // different price values to the first batch, but only the first and last updates in
  226. // the second batch have a newer timestamp than those in the first batch, and so these
  227. // are the only two which should be cached.
  228. let secondBatchPriceAttestation = "0x"+"503257480002020004009650325748000201c0e11df4c58a4e53f2bc059ba57a7c8f30ddada70b5bdc3753f90b824b64dd73c1902e05cdf03bc089a943d921f87ccd0e3e1b774b5660d037b9f428c0d3305e01000000000000073dfffffffb00000000000005470000000132959bbd00000000c8bfed5f00000000000000030000000041c7b65b00000000c8bfed5f0000000000000003010000000000622f65f5503257480002017090c4ecf0309718d04c5a162c08aa4b78f533f688fa2f3ccd7be74c2a253a54fd4caca566fc44a9d6585420959d13897877c606477b3f0e7f247295b7275620010000000000000450fffffffb00000000000005fb000000015cfe8c9d00000000e3dbaa7f00000000000000020000000041c7c5bb00000000e3dbaa7f0000000000000007010000000000622f65f4503257480002012f064374f55cb2efbbef29329de3b652013a76261876c55a1caf3a489c721ccd8c5dd422900917e8e26316fe598e8f062058d390644e0e36d42c187298420ccd010000000000000659fffffffb00000000000005cd00000001492c19bd00000000dd92071f00000000000000020000000041c7d3fb00000000dd92071f0000000000000001010000000000622f65f45032574800020181ddabd1a2c1fb6d6c4707b245b7c0ab6af0ae7b96b2ff866954a0b71124aee517fbe895e5416ddb4d5af9d83c599ee2c4f94cb25e8597f9e5978bd63a7cdcb70100000000000007bDfffffffb00000000000005e2000000014db2995d00000000dd8f775f00000000000000020000000041c7df9b00000000dd8f775f0000000000000003010000000000622f65f5";
  229. let all_price_ids = ["0xc1902e05cdf03bc089a943d921f87ccd0e3e1b774b5660d037b9f428c0d3305e",
  230. "0xfd4caca566fc44a9d6585420959d13897877c606477b3f0e7f247295b7275620",
  231. "0x8c5dd422900917e8e26316fe598e8f062058d390644e0e36d42c187298420ccd",
  232. "0x17fbe895e5416ddb4d5af9d83c599ee2c4f94cb25e8597f9e5978bd63a7cdcb7"
  233. ];
  234. // Send the first batch
  235. await attest(this.pythProxy, rawBatchPriceAttestation);
  236. let prices_after_first_update = {};
  237. for (var i = 0; i < all_price_ids.length; i++) {
  238. const price_id = all_price_ids[i];
  239. prices_after_first_update[price_id] = await this.pythProxy.latestPriceInfo(price_id);
  240. }
  241. // Send the second batch
  242. await attest(this.pythProxy, secondBatchPriceAttestation);
  243. let prices_after_second_update = {};
  244. for (var i = 0; i < all_price_ids.length; i++) {
  245. const price_id = all_price_ids[i];
  246. prices_after_second_update[price_id] = await this.pythProxy.latestPriceInfo(price_id);
  247. }
  248. // Price IDs which have newer timestamps
  249. let new_price_updates = [
  250. "0xc1902e05cdf03bc089a943d921f87ccd0e3e1b774b5660d037b9f428c0d3305e",
  251. "0x17fbe895e5416ddb4d5af9d83c599ee2c4f94cb25e8597f9e5978bd63a7cdcb7"
  252. ];
  253. // Price IDs which have older timestamps
  254. let old_price_updates = [
  255. "0xfd4caca566fc44a9d6585420959d13897877c606477b3f0e7f247295b7275620",
  256. "0x8c5dd422900917e8e26316fe598e8f062058d390644e0e36d42c187298420ccd"];
  257. // Check that the new price updates have been updated
  258. for (var i = 0; i < new_price_updates.length; i++) {
  259. const price_id = new_price_updates[i];
  260. assert.notEqual(prices_after_first_update[price_id].priceFeed.price, prices_after_second_update[price_id].priceFeed.price);
  261. assert.notEqual(prices_after_first_update[price_id].attestationTime, prices_after_second_update[price_id].attestationTime);
  262. }
  263. // Check that the old price updates have been discarded
  264. for (var i = 0; i < old_price_updates.length; i++) {
  265. const price_id = old_price_updates[i];
  266. assert.equal(prices_after_first_update[price_id].priceFeed.price, prices_after_second_update[price_id].priceFeed.price);
  267. assert.equal(prices_after_first_update[price_id].priceFeed.conf, prices_after_second_update[price_id].priceFeed.conf);
  268. assert.equal(prices_after_first_update[price_id].priceFeed.expo, prices_after_second_update[price_id].priceFeed.expo);
  269. assert.equal(prices_after_first_update[price_id].priceFeed.status.toString(), prices_after_second_update[price_id].priceFeed.status.toString());
  270. assert.equal(prices_after_first_update[price_id].priceFeed.numPublishers, prices_after_second_update[price_id].priceFeed.numPublishers);
  271. assert.equal(prices_after_first_update[price_id].priceFeed.maxNumPublishers, prices_after_second_update[price_id].priceFeed.maxNumPublishers);
  272. assert.equal(prices_after_first_update[price_id].priceFeed.emaPrice, prices_after_second_update[price_id].priceFeed.emaPrice);
  273. assert.equal(prices_after_first_update[price_id].priceFeed.emaConf, prices_after_second_update[price_id].priceFeed.emaConf);
  274. assert.equal(prices_after_first_update[price_id].attestationTime, prices_after_second_update[price_id].attestationTime);
  275. assert.equal(prices_after_first_update[price_id].arrivalTime, prices_after_second_update[price_id].arrivalTime);
  276. }
  277. })
  278. });
  279. const signAndEncodeVM = async function (
  280. timestamp,
  281. nonce,
  282. emitterChainId,
  283. emitterAddress,
  284. sequence,
  285. data,
  286. signers,
  287. guardianSetIndex,
  288. consistencyLevel
  289. ) {
  290. const body = [
  291. web3.eth.abi.encodeParameter("uint32", timestamp).substring(2 + (64 - 8)),
  292. web3.eth.abi.encodeParameter("uint32", nonce).substring(2 + (64 - 8)),
  293. web3.eth.abi.encodeParameter("uint16", emitterChainId).substring(2 + (64 - 4)),
  294. web3.eth.abi.encodeParameter("bytes32", emitterAddress).substring(2),
  295. web3.eth.abi.encodeParameter("uint64", sequence).substring(2 + (64 - 16)),
  296. web3.eth.abi.encodeParameter("uint8", consistencyLevel).substring(2 + (64 - 2)),
  297. data.substr(2)
  298. ]
  299. const hash = web3.utils.soliditySha3(web3.utils.soliditySha3("0x" + body.join("")))
  300. let signatures = "";
  301. for (let i in signers) {
  302. const ec = new elliptic.ec("secp256k1");
  303. const key = ec.keyFromPrivate(signers[i]);
  304. const signature = key.sign(hash.substr(2), {canonical: true});
  305. const packSig = [
  306. web3.eth.abi.encodeParameter("uint8", i).substring(2 + (64 - 2)),
  307. zeroPadBytes(signature.r.toString(16), 32),
  308. zeroPadBytes(signature.s.toString(16), 32),
  309. web3.eth.abi.encodeParameter("uint8", signature.recoveryParam).substr(2 + (64 - 2)),
  310. ]
  311. signatures += packSig.join("")
  312. }
  313. const vm = [
  314. web3.eth.abi.encodeParameter("uint8", 1).substring(2 + (64 - 2)),
  315. web3.eth.abi.encodeParameter("uint32", guardianSetIndex).substring(2 + (64 - 8)),
  316. web3.eth.abi.encodeParameter("uint8", signers.length).substring(2 + (64 - 2)),
  317. signatures,
  318. body.join("")
  319. ].join("");
  320. return vm
  321. }
  322. function zeroPadBytes(value, length) {
  323. while (value.length < 2 * length) {
  324. value = "0" + value;
  325. }
  326. return value;
  327. }