CN109815372B - Scrypt algorithm workload proof method and device - Google Patents
Scrypt algorithm workload proof method and device Download PDFInfo
- Publication number
- CN109815372B CN109815372B CN201910068396.6A CN201910068396A CN109815372B CN 109815372 B CN109815372 B CN 109815372B CN 201910068396 A CN201910068396 A CN 201910068396A CN 109815372 B CN109815372 B CN 109815372B
- Authority
- CN
- China
- Prior art keywords
- data
- storage
- task
- cycle
- current
- Prior art date
- Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
- Active
Links
- 238000000034 method Methods 0.000 title claims abstract description 47
- 238000000605 extraction Methods 0.000 claims description 17
- 238000004364 calculation method Methods 0.000 claims description 16
- 230000006870 function Effects 0.000 claims description 16
- 239000000284 extract Substances 0.000 claims description 8
- 230000008569 process Effects 0.000 description 4
- 101001121408 Homo sapiens L-amino-acid oxidase Proteins 0.000 description 3
- 101000827703 Homo sapiens Polyphosphoinositide phosphatase Proteins 0.000 description 3
- 102100026388 L-amino-acid oxidase Human genes 0.000 description 3
- 102100023591 Polyphosphoinositide phosphatase Human genes 0.000 description 3
- 101100012902 Saccharomyces cerevisiae (strain ATCC 204508 / S288c) FIG2 gene Proteins 0.000 description 3
- 101100233916 Saccharomyces cerevisiae (strain ATCC 204508 / S288c) KAR5 gene Proteins 0.000 description 3
- 238000006243 chemical reaction Methods 0.000 description 2
- 238000010586 diagram Methods 0.000 description 2
- 230000007246 mechanism Effects 0.000 description 1
- 230000004048 modification Effects 0.000 description 1
- 238000012986 modification Methods 0.000 description 1
Landscapes
- Information Retrieval, Db Structures And Fs Structures Therefor (AREA)
Abstract
本公开涉及一种Scrypt算法工作量证明方法及装置,所述方法包括多个工作量证明的任务,所述任务包括第一阶段和第二阶段,所述方法包括:在各任务的第一阶段,在第一数据中抽取部分数据作为存储数据进行存储,存储数据的数量少于第一数据的数量;在各任务的第二阶段,将各任务分别对应至第一周期内不同的第一时隙,在与目标任务对应的第一时隙内,根据目标任务的存储数据确定对应的第一数据,根据对应的第一数据生成第二数据,所述目标任务包括任一任务,所述第一周期包括多个第一时隙,第一时隙的数量大于或等于任务的数量。本公开实施例可以节省存储空间,提高多任务的执行效率。
The present disclosure relates to a Scrypt algorithm workload proof method and device, the method includes multiple workload proof tasks, the tasks include a first stage and a second stage, the method includes: in the first stage of each task, extracting part of the data from the first data as storage data for storage, the amount of storage data is less than the amount of first data; in the second stage of each task, each task is respectively corresponded to a different first time slot in the first cycle, in the first time slot corresponding to the target task, the corresponding first data is determined according to the storage data of the target task, and the second data is generated according to the corresponding first data, the target task includes any task, the first cycle includes multiple first time slots, and the number of first time slots is greater than or equal to the number of tasks. The embodiment of the present disclosure can save storage space and improve the execution efficiency of multiple tasks.
Description
技术领域Technical Field
本公开涉及区块链技术领域,尤其涉及一种Scrypt算法工作量证明方法及装置。The present disclosure relates to the field of blockchain technology, and in particular to a Scrypt algorithm workload proof method and device.
背景技术Background Art
区块链技术的工作量证明方法中,Scrypt算法工作量证明方法的第一阶段生成设定数量的第一数据,并在第二阶段随机使用第一数据生成第二数据。第一数据的数量较多,占据了较大的存储空间,使得Scrypt算法工作量证明方法的实现芯片的体积较大,不利于缩小相关设备的体积。In the proof-of-work method of blockchain technology, the first stage of the Scrypt algorithm proof-of-work method generates a set amount of first data, and in the second stage, the first data is randomly used to generate second data. The amount of first data is large, occupying a large storage space, making the chip implementing the Scrypt algorithm proof-of-work method larger in size, which is not conducive to reducing the size of related equipment.
发明内容Summary of the invention
有鉴于此,本公开提出了一种Scrypt算法工作量证明方法及装置。用以解决Scrypt算法工作量证明方法占用存储空间大,无法减小相关芯片体积的问题。In view of this, the present disclosure proposes a Scrypt algorithm workload proof method and device to solve the problem that the Scrypt algorithm workload proof method occupies a large storage space and cannot reduce the size of the related chip.
根据本公开的一方面,提供了一种Scrypt算法工作量证明方法,所述方法包括多个工作量证明的任务,所述任务包括第一阶段和第二阶段,所述方法包括:According to one aspect of the present disclosure, a Scrypt algorithm workload proof method is provided, the method comprising a plurality of workload proof tasks, the tasks comprising a first stage and a second stage, the method comprising:
在各任务的第一阶段,在第一数据中抽取部分数据作为存储数据进行存储,所述存储数据的数量少于所述第一数据的数量;In the first stage of each task, part of the data is extracted from the first data and stored as storage data, and the amount of the storage data is less than the amount of the first data;
在各任务的第二阶段,将各任务分别对应至第一周期内不同的第一时隙,在与目标任务对应的第一时隙内,根据所述目标任务的存储数据确定对应的第一数据,根据所述对应的第一数据生成第二数据,所述目标任务包括任一所述任务,所述第一周期包括多个第一时隙,所述第一时隙的数量大于或等于所述任务的数量。In the second stage of each task, each task is respectively corresponded to a different first time slot in the first cycle. In the first time slot corresponding to the target task, the corresponding first data is determined according to the storage data of the target task, and the second data is generated according to the corresponding first data. The target task includes any of the tasks, and the first cycle includes multiple first time slots, and the number of the first time slots is greater than or equal to the number of tasks.
在一种可能的实现方式中,在各任务的第一阶段,在第一数据中抽取部分数据作为存储数据进行存储,包括:In a possible implementation, in the first stage of each task, extracting part of the first data as storage data for storage includes:
在各任务的第一阶段,将各任务分别对应至第二周期内不同的第二时隙,In the first phase of each task, each task is mapped to a different second time slot in the second cycle.
在与所述目标任务对应的第二时隙内,生成第一数据,并在第一数据中抽取部分数据作为存储数据写入存储器,所述第二周期包括多个第二时隙,所述第二时隙的数量大于或等于所述任务的数量。In a second time slot corresponding to the target task, first data is generated, and part of the first data is extracted and written into a memory as storage data, wherein the second cycle includes a plurality of second time slots, and the number of the second time slots is greater than or equal to the number of the tasks.
在一种可能的实现方式中,根据所述目标任务的存储数据确定对应的第一数据,根据所述对应的第一数据生成第二数据,包括:In a possible implementation, determining corresponding first data according to the stored data of the target task, and generating second data according to the corresponding first data includes:
在所述目标任务的所述存储数据中查找与当前第二数据对应的第一数据;Searching the stored data of the target task for first data corresponding to the current second data;
当无法在所述存储数据中查找到与当前第二数据对应的第一数据时,根据最接近的存储数据,确定与所述当前第二数据对应的第一数据;When the first data corresponding to the current second data cannot be found in the stored data, determining the first data corresponding to the current second data according to the closest stored data;
根据与所述当前第二数据对应的第一数据和所述当前第二数据,得到所述当前第二数据的下一个第二数据。The next second data of the current second data is obtained according to the first data corresponding to the current second data and the current second data.
在一种可能的实现方式中,所述第一数据为有序序列,在第一数据中抽取部分数据作为存储数据进行存储,包括:In a possible implementation, the first data is an ordered sequence, and extracting part of the first data as storage data for storage includes:
根据所述存储数据的序列号确定所述存储数据的存储地址;Determining a storage address of the stored data according to a serial number of the stored data;
在所述目标任务的所述存储数据中查找与当前第二数据对应的第一数据,包括:Searching the stored data of the target task for first data corresponding to the current second data includes:
根据在所述目标任务的当前第二数据中预设数位上的数据生成索引地址,在所述存储地址中查找所述索引地址,根据查找结果确定与当前第二数据对应的第一数据。An index address is generated according to data at a preset digit in the current second data of the target task, the index address is searched in the storage address, and the first data corresponding to the current second data is determined according to the search result.
在一种可能的实现方式中,根据最接近的存储数据,确定与所述当前第二数据对应的第一数据,包括:In a possible implementation, determining, according to the closest stored data, first data corresponding to the current second data includes:
确定最接近的存储地址与所述索引地址之间的差值;determining a difference between the closest storage address and the index address;
根据所述差值确定的迭代次数,将最接近的存储地址中的存储数据进行迭代运算,得到与所述索引地址对应的第一数据。According to the number of iterations determined by the difference, the storage data in the closest storage address is iteratively calculated to obtain the first data corresponding to the index address.
在一种可能的实现方式中,在第一数据中抽取部分数据作为存储数据进行存储,包括以下任意一种:In a possible implementation, extracting part of the data from the first data as storage data for storage includes any of the following:
在第一数据中按照预设的抽取间隔抽取存储数据进行存储;Extracting and storing the stored data in the first data according to a preset extraction interval;
在第一数据中按照预设的序列号范围抽取存储数据进行存储;Extracting and storing the stored data in the first data according to a preset sequence number range;
在第一数据中随机抽取预设数量的存储数据进行存储。A preset number of storage data are randomly selected from the first data for storage.
在一种可能的实现方式中,各任务的存储数据存储在存储器的不同存储空间,所述存储空间的数量大于或等于所述任务的数量。In a possible implementation, the storage data of each task is stored in different storage spaces of a memory, and the number of the storage spaces is greater than or equal to the number of the tasks.
在一种可能的实现方式中,以所述第二周期在前、所述第一周期在后组成的执行周期执行各所述任务。In a possible implementation, each of the tasks is executed in an execution cycle consisting of the second cycle in front and the first cycle in the back.
在一种可能的实现方式中,所述第一周期还包括空闲时隙,所述空闲时隙的数量或时长根据所述存储器的延迟确定。In a possible implementation manner, the first cycle further includes idle time slots, and the number or duration of the idle time slots is determined according to the delay of the memory.
在一种可能的实现方式中,所述第一周期和所述第二周期并行。In a possible implementation manner, the first cycle and the second cycle are performed in parallel.
在一种可能的实现方式中,所述方法还包括:In a possible implementation, the method further includes:
当所述多个任务中的至少一个任务执行完毕时,将执行完毕的任务对应的第一时隙分配至新的任务。When at least one of the multiple tasks is completed, a first time slot corresponding to the completed task is allocated to a new task.
根据本公开的另一方面,提供了一种Scrypt算法工作量证明装置,所述装置用于执行多个工作量证明的任务,所述任务包括第一阶段和第二阶段,所述装置包括:According to another aspect of the present disclosure, a Scrypt algorithm workload proof device is provided, the device is used to perform multiple workload proof tasks, the tasks include a first stage and a second stage, the device includes:
抽取模块,用于在各任务的第一阶段,在第一数据中抽取部分数据作为存储数据进行存储,所述存储数据的数量少于所述第一数据的数量;An extraction module, used for extracting part of the data from the first data as storage data for storage in the first stage of each task, wherein the amount of the storage data is less than the amount of the first data;
第一周期执行模块,用于在各任务的第二阶段,将各任务分别对应至第一周期内不同的第一时隙,在与目标任务对应的第一时隙内,根据所述目标任务的存储数据确定对应的第一数据,根据所述对应的第一数据生成第二数据,所述目标任务包括任一所述任务,所述第一周期包括多个第一时隙,所述第一时隙的数量大于或等于所述任务的数量。The first cycle execution module is used to correspond each task to a different first time slot in the first cycle in the second stage of each task, determine the corresponding first data according to the storage data of the target task in the first time slot corresponding to the target task, and generate second data according to the corresponding first data, the target task includes any of the tasks, the first cycle includes multiple first time slots, and the number of the first time slots is greater than or equal to the number of the tasks.
在一种可能的实现方式中,所述抽取模块,包括:In a possible implementation, the extraction module includes:
第二周期执行子模块,用于在各任务的第一阶段,将各任务分别对应至第二周期内不同的第二时隙,在与所述目标任务对应的第二时隙内,生成第一数据,并在第一数据中抽取部分数据作为存储数据写入存储器,所述第二周期包括多个第二时隙,所述第二时隙的数量大于或等于所述任务的数量。The second cycle execution submodule is used to correspond each task to a different second time slot in the second cycle in the first stage of each task, generate first data in the second time slot corresponding to the target task, and extract part of the first data and write it into the memory as storage data. The second cycle includes multiple second time slots, and the number of the second time slots is greater than or equal to the number of tasks.
在一种可能的实现方式中,所述第一周期执行模块,包括:In a possible implementation, the first cycle execution module includes:
对应数据查找子模块,用于在所述目标任务的所述存储数据中查找与当前第二数据对应的第一数据;A corresponding data search submodule, used to search the stored data of the target task for first data corresponding to the current second data;
对应数据确定子模块,用于当无法在所述存储数据中查找到与当前第二数据对应的第一数据时,根据最接近的存储数据,确定与所述当前第二数据对应的第一数据;A corresponding data determination submodule, for determining the first data corresponding to the current second data according to the closest stored data when the first data corresponding to the current second data cannot be found in the stored data;
第二数据获取子模块,用于根据与所述当前第二数据对应的第一数据和所述当前第二数据,得到所述当前第二数据的下一个第二数据。The second data acquisition submodule is used to obtain the next second data of the current second data according to the first data corresponding to the current second data and the current second data.
在一种可能的实现方式中,所述第一数据为有序序列,所述抽取模块,包括:In a possible implementation, the first data is an ordered sequence, and the extraction module includes:
存储地址子模块,用于根据所述存储数据的序列号确定所述存储数据的存储地址;A storage address submodule, used to determine the storage address of the storage data according to the serial number of the storage data;
所述对应数据查找子模块,用于:The corresponding data search submodule is used to:
根据在所述目标任务的当前第二数据中预设数位上的数据生成索引地址,在所述存储地址中查找所述索引地址,根据查找结果确定与当前第二数据对应的第一数据。An index address is generated according to data at a preset digit in the current second data of the target task, the index address is searched in the storage address, and the first data corresponding to the current second data is determined according to the search result.
在一种可能的实现方式中,所述对应数据确定子模块,用于:In a possible implementation, the corresponding data determination submodule is used to:
确定最接近的存储地址与所述索引地址之间的差值;determining a difference between the closest storage address and the index address;
根据所述差值确定的迭代次数,将最接近的存储地址中的存储数据进行迭代运算,得到与所述索引地址对应的第一数据。According to the number of iterations determined by the difference, the storage data in the closest storage address is iteratively calculated to obtain the first data corresponding to the index address.
在一种可能的实现方式中,在第一数据中抽取部分数据作为存储数据进行存储,包括以下任意一种:In a possible implementation, extracting part of the data from the first data as storage data for storage includes any of the following:
在第一数据中按照预设的抽取间隔抽取存储数据进行存储;Extracting and storing the stored data in the first data according to a preset extraction interval;
在第一数据中按照预设的序列号范围抽取存储数据进行存储;Extracting and storing the stored data in the first data according to a preset sequence number range;
在第一数据中随机抽取预设数量的存储数据进行存储。A preset number of storage data are randomly selected from the first data for storage.
在一种可能的实现方式中,各任务的存储数据存储在存储器的不同存储空间,所述存储空间的数量大于或等于所述任务的数量。In a possible implementation, the storage data of each task is stored in different storage spaces of a memory, and the number of the storage spaces is greater than or equal to the number of the tasks.
在一种可能的实现方式中,以所述第二周期在前、所述第一周期在后组成的执行周期执行各所述任务。In a possible implementation, each of the tasks is executed in an execution cycle consisting of the second cycle in front and the first cycle in the back.
在一种可能的实现方式中,所述第一周期还包括空闲时隙,所述空闲时隙的数量或时长根据所述存储器的延迟确定。In a possible implementation manner, the first cycle further includes idle time slots, and the number or duration of the idle time slots is determined according to the delay of the memory.
在一种可能的实现方式中,所述第一周期和所述第二周期并行。In a possible implementation manner, the first cycle and the second cycle are performed in parallel.
在本公开实施例中,在Scrypt算法工作量证明的第一阶段,在第一数据中抽取部分数据作为存储数据进行存储,可以节省存储空间。将多个任务分别对应至第一周期内不同的第一时隙,在与各任务对应的第一时隙内生成第二数据,可以提高多任务的执行效率。In the disclosed embodiment, in the first stage of the Scrypt algorithm workload proof, part of the data is extracted from the first data and stored as storage data, which can save storage space. Multiple tasks are respectively mapped to different first time slots in the first cycle, and second data is generated in the first time slot corresponding to each task, which can improve the execution efficiency of multiple tasks.
根据下面参考附图对示例性实施例的详细说明,本公开的其它特征及方面将变得清楚。Further features and aspects of the present disclosure will become apparent from the following detailed description of exemplary embodiments with reference to the attached drawings.
附图说明BRIEF DESCRIPTION OF THE DRAWINGS
包含在说明书中并且构成说明书的一部分的附图与说明书一起示出了本公开的示例性实施例、特征和方面,并且用于解释本公开的原理。The accompanying drawings, which are incorporated in and constitute a part of the specification, illustrate exemplary embodiments, features, and aspects of the disclosure and, together with the description, serve to explain the principles of the disclosure.
图1示出根据本公开一实施例的Scrypt算法工作量证明方法的流程图;FIG1 is a flowchart of a Scrypt algorithm workload proof method according to an embodiment of the present disclosure;
图2示出根据本公开一实施例的Scrypt算法工作量证明方法的流程图;FIG2 shows a flow chart of a Scrypt algorithm workload proof method according to an embodiment of the present disclosure;
图3示出根据本公开一实施例的Scrypt算法工作量证明方法的流程图;FIG3 shows a flow chart of a Scrypt algorithm workload proof method according to an embodiment of the present disclosure;
图4示出根据本公开一实施例的Scrypt算法工作量证明装置的框图。FIG4 shows a block diagram of a Scrypt algorithm workload proof device according to an embodiment of the present disclosure.
具体实施方式DETAILED DESCRIPTION
以下将参考附图详细说明本公开的各种示例性实施例、特征和方面。附图中相同的附图标记表示功能相同或相似的元件。尽管在附图中示出了实施例的各种方面,但是除非特别指出,不必按比例绘制附图。Various exemplary embodiments, features and aspects of the present disclosure will be described in detail below with reference to the accompanying drawings. The same reference numerals in the accompanying drawings represent elements with the same or similar functions. Although various aspects of the embodiments are shown in the accompanying drawings, the drawings are not necessarily drawn to scale unless otherwise specified.
在这里专用的词“示例性”意为“用作例子、实施例或说明性”。这里作为“示例性”所说明的任何实施例不必解释为优于或好于其它实施例。The word “exemplary” is used exclusively herein to mean “serving as an example, example, or illustration.” Any embodiment described herein as “exemplary” is not necessarily to be construed as preferred or advantageous over other embodiments.
另外,为了更好的说明本公开,在下文的具体实施方式中给出了众多的具体细节。本领域技术人员应当理解,没有某些具体细节,本公开同样可以实施。在一些实例中,对于本领域技术人员熟知的方法、手段、元件和电路未作详细描述,以便于凸显本公开的主旨。In addition, in order to better illustrate the present disclosure, numerous specific details are given in the following specific embodiments. It should be understood by those skilled in the art that the present disclosure can also be implemented without certain specific details. In some examples, methods, means, components and circuits well known to those skilled in the art are not described in detail in order to highlight the subject matter of the present disclosure.
图1示出根据本公开一实施例的Scrypt算法工作量证明方法的流程图,如图1所示,方法包括:FIG. 1 shows a flow chart of a Scrypt algorithm workload proof method according to an embodiment of the present disclosure. As shown in FIG. 1 , the method includes:
步骤S10,各任务的第一阶段,在第一数据中抽取部分数据作为存储数据进行存储,存储数据的数量少于第一数据的数量。Step S10, the first stage of each task, extracts part of the data from the first data as storage data for storage, and the amount of the storage data is less than the amount of the first data.
在一种可能的实现方式中,工作量证明是实现系统一致性的重要机制。工作量证明要求参与方付出一定量的计算资源,来证明自己完成了一定的工作量。在Scrypt算法中,工作量证明包括第一阶段和第二阶段。在第一阶段,可以将随机数利用HASH函数进行运算后得到多个第一数据。各第一数据之间具有级联关系,可以组成序列。例如,在第一阶段,可以根据随机数1利用HASH函数运算后,得到第一个第一数据。可以将第一个第一数据利用HASH函数运算后,得到第二个第一数据。可以利用HASH函数进行多次运算后得到预设数量的第一数据。可以将各第一数据进行存储。为节省存储空间,本实施例可以在第一数据中抽取部分数据作为存储数据进行存储,可以节省存储空间。In one possible implementation, proof of work is an important mechanism for achieving system consistency. Proof of work requires participants to pay a certain amount of computing resources to prove that they have completed a certain amount of work. In the Scrypt algorithm, proof of work includes a first stage and a second stage. In the first stage, the random number can be operated using a HASH function to obtain multiple first data. There is a cascade relationship between the first data, and a sequence can be formed. For example, in the first stage, the first first data can be obtained by operating the random number 1 using a HASH function. The first first data can be operated using a HASH function to obtain the second first data. A preset number of first data can be obtained after multiple operations using the HASH function. Each first data can be stored. In order to save storage space, this embodiment can extract part of the data from the first data as storage data for storage, which can save storage space.
在一种可能的实现方式中,存储数据的数量少于第一数据的数量,由于第二数据需要随机用到第一数据。当计算第二数据所需的第一数据没有被存储时,需要根据存储数据计算到得到,从而耗费一定的计算资源,降低了计算效率。可以根据节省存储空间和保证计算效率的两方面需求,确定存储数据的数量。In a possible implementation, the amount of stored data is less than the amount of first data, because the second data needs to use the first data randomly. When the first data required for calculating the second data is not stored, it needs to be calculated based on the stored data, thereby consuming certain computing resources and reducing computing efficiency. The amount of stored data can be determined based on the two requirements of saving storage space and ensuring computing efficiency.
在一种可能的实现方式中,在第一数据中抽取部分数据作为存储数据进行存储,包括以下任意一种:In a possible implementation, extracting part of the data from the first data as storage data for storage includes any of the following:
在第一数据中按照预设的抽取间隔抽取存储数据进行存储;Extracting and storing the stored data in the first data according to a preset extraction interval;
在第一数据中按照预设的序列号范围抽取存储数据进行存储;Extracting and storing the stored data in the first data according to a preset sequence number range;
在第一数据中随机抽取预设数量的存储数据进行存储。A preset number of storage data are randomly selected from the first data for storage.
在一种可能的实现方式中,可以预设抽取间隔。例如,预设抽取间隔可以为三个第一数据。则可以抽取第一个第一数据、第四个第一数据、第八个第一数据……依次类推,直至抽取到最后一个存储数据进行存储。在第二数据的计算过程中,第一数据会被随机的使用到,按照抽取间隔抽取到得存储寻列,能够在第一数据中较平均的抽取存储数据,使得存储数据的被使用的几率相当。In a possible implementation, an extraction interval may be preset. For example, the preset extraction interval may be three first data. Then the first first data, the fourth first data, the eighth first data, and so on may be extracted, until the last stored data is extracted for storage. In the calculation process of the second data, the first data will be used randomly, and the storage columns extracted according to the extraction interval can extract the stored data more evenly in the first data, so that the probability of the stored data being used is equivalent.
在一种可能的实现方式中,各第一数据之间有级联关系,各第一数据可以组成一个序列。各第一数据之间的序列号可以根据第一数据的生成顺序确定。可以在第一数据中按照预设的序列号范围抽取存储数据。例如,共有1024个第一数据,可以抽取1-50、100-150、200-250……的序列号范围的第一数据作为存储数据。可以根据多个序列号范围抽取存储数据,也可以根据一个序列号范围抽取存储数据。本公开不限定序列号范围的数量,也不限定各序列号范围的长度。In a possible implementation, there is a cascade relationship between each first data, and each first data can form a sequence. The sequence number between each first data can be determined according to the generation order of the first data. The storage data can be extracted from the first data according to a preset sequence number range. For example, there are 1024 first data in total, and the first data with sequence number ranges of 1-50, 100-150, 200-250... can be extracted as storage data. The storage data can be extracted according to multiple sequence number ranges, or it can be extracted according to one sequence number range. The present disclosure does not limit the number of sequence number ranges, nor does it limit the length of each sequence number range.
在一种可能的实现方式中,可以在第一数据中随机抽取预设数量的存储数据进行存储。例如,共有1024个第一数据可以随机抽取256个存储数据,可以随机抽取第一个、第五个、第十五个第一数据……作为存储数据。In a possible implementation, a preset number of storage data may be randomly selected from the first data for storage. For example, 256 storage data may be randomly selected from a total of 1024 first data, and the first, fifth, fifteenth first data, etc. may be randomly selected as storage data.
步骤S20,在各任务的第二阶段,将各任务分别对应至第一周期内不同的第一时隙,在与目标任务对应的第一时隙内,根据目标任务的存储数据确定对应的第一数据,根据对应的第一数据生成第二数据,目标任务包括任一任务,第一周期包括多个第一时隙,第一时隙的数量大于或等于任务的数量。Step S20, in the second stage of each task, each task is respectively corresponded to a different first time slot in the first cycle, in the first time slot corresponding to the target task, the corresponding first data is determined according to the storage data of the target task, and the second data is generated according to the corresponding first data, the target task includes any task, the first cycle includes multiple first time slots, and the number of first time slots is greater than or equal to the number of tasks.
在一种可能的实现方式中,在第二阶段,可以根据第一数据和随机数,利用HASH函数进行运算得到第二数据。例如,在第二阶段,可以根据最后一个第一数据或根据随机数2,利用HASH函数进行运算,得到第一个第二数据。可以将第一个第二数据利用HASH函数进行运算,得到第一个第二数据的运算结果,可以确定与第一个第二数据对应的第一数据,可以将与第一个第二数据对应的第一数据和第一个第二数据的运算结果进行异或运算,得到第二个第二数据。可以将第二数据利用HASH函数进行运算,得到第二个第二数据的运算结果,可以确定一个与第二个第二数据对应的第一数据,可以将与第二个第二数据对应的第一数据和第二个第二数据的运算结果进行异或运算,得到第三个第二数据。以此类推,直至得到预设数量的第二数据。In a possible implementation, in the second stage, the second data can be obtained by using a HASH function to calculate based on the first data and the random number. For example, in the second stage, the first second data can be obtained by using a HASH function to calculate based on the last first data or based on the random number 2. The first second data can be calculated using a HASH function to obtain the calculation result of the first second data, the first data corresponding to the first second data can be determined, and the first data corresponding to the first second data and the calculation result of the first second data can be XORed to obtain the second second data. The second data can be calculated using a HASH function to obtain the calculation result of the second second data, a first data corresponding to the second second data can be determined, and the first data corresponding to the second second data and the calculation result of the second second data can be XORed to obtain the third second data. And so on, until a preset number of second data is obtained.
在一种可能的实现方式中,可以根据当前第二数据中设定数位上的数据和预设的数据转换规则,得到与当前第二数据对应的第一数据。可以根据需求确定数据转换规则,本公开对此不做限定。由于各第一数据之间有级联关系,可以根据任一第一数据,经过计算得到与任一第二数据对应的第一数据。可以根据存储数据,得到与各第二数据对应的第一数据。In a possible implementation, the first data corresponding to the current second data can be obtained according to the data on the set digits in the current second data and the preset data conversion rule. The data conversion rule can be determined according to the demand, and the present disclosure does not limit this. Since there is a cascade relationship between the first data, the first data corresponding to any second data can be obtained by calculation according to any first data. The first data corresponding to each second data can be obtained according to the stored data.
在一种可能的实现方式中,第二数据之间具有级联关系。利用本公开实施例中的方法,计算得到最后一个第二数据,并将计算得到的最后一个第二数据输出至Scrypt算法中工作量证明部分的其它运算步骤,以完成Scrypt算法中工作量证明,本领域技术人员可以理解的是,具体第二数据输出至Scrypt算法中的其它步骤,以完成的Scrypt算法工作量证明的相关描述可参考现有技术。In a possible implementation, the second data have a cascade relationship. Using the method in the embodiment of the present disclosure, the last second data is calculated, and the calculated last second data is output to other operation steps of the proof-of-work part in the Scrypt algorithm to complete the proof-of-work in the Scrypt algorithm. It can be understood by those skilled in the art that the specific second data is output to other steps in the Scrypt algorithm to complete the relevant description of the proof-of-work of the Scrypt algorithm can refer to the prior art.
在一种可能的实现方式中,在各任务的第二阶段,确定与当前第二数据对应的第一数据的过程中,存在对应的第一数据不是存储数据,需要根据存储数据运算后得到与当前第二数据对应的第一数据,在根据运算得到的与当前第二数据对应的第一数据得到下一个第二数据的情况。各任务中,当前第二数据对应的第一数据在存储数据中的命中率不同,根据存储数据运算得到对应的第一数据的迭代次数不同,运算耗时也不同,导致各任务的第二阶段所需时长各不相同。在传统的工作量证明方法中,当多个工作量证明的任务同时执行时,需要等待所有任务的当前第二数据生成后,才能进行下一个第二数据的生成过程,各任务的执行效率低。In one possible implementation, in the second stage of each task, in the process of determining the first data corresponding to the current second data, there is a situation where the corresponding first data is not the stored data, and it is necessary to obtain the first data corresponding to the current second data after calculation based on the stored data, and then obtain the next second data based on the first data corresponding to the current second data obtained by calculation. In each task, the hit rate of the first data corresponding to the current second data in the stored data is different, the number of iterations of obtaining the corresponding first data based on the stored data calculation is different, and the calculation time is also different, resulting in different durations required for the second stage of each task. In the traditional proof-of-work method, when multiple proof-of-work tasks are executed simultaneously, it is necessary to wait for the current second data of all tasks to be generated before the next second data generation process can be carried out, and the execution efficiency of each task is low.
在一种可能的实现方式中,在各任务的第二阶段,可以将各任务分别对应至第一周期内不同的第一时隙,第一周期包括多个第一时隙,第一时隙的数量大于或等于任务的数量。例如,第一周期为T1,T1包括10个第一时隙,可以分别对应10个不同的任务,第一个第一时隙对应任务1,第二个第一时隙对应任务2,第三个第一时隙对应任务3……。在第一个第一时隙对应的时长范围内,执行任务1的第二阶段,在第二个第一时隙对应的时长范围内,执行任务2的第二阶段,并以此类推,直至第一周期执行完毕后,执行下一个第一周期。In a possible implementation, in the second phase of each task, each task can be respectively corresponded to a different first time slot in the first cycle, and the first cycle includes multiple first time slots, and the number of first time slots is greater than or equal to the number of tasks. For example, the first cycle is T1, and T1 includes 10 first time slots, which can correspond to 10 different tasks respectively. The first first time slot corresponds to task 1, the second first time slot corresponds to task 2, and the third first time slot corresponds to task 3.... Within the duration corresponding to the first first time slot, the second phase of task 1 is executed, and within the duration corresponding to the second first time slot, the second phase of task 2 is executed, and so on, until the first cycle is completed and the next first cycle is executed.
在一种可能的实现方式中,当多个任务中的至少一个任务执行完毕后,可以将执行完毕的任务对应的第一时隙分配至新任务。例如,在10个任务中,任务3执行完毕。可以将与任务3对应的第三个第一时隙分配至新的任务11,从而提高多任务执行效率。In a possible implementation, when at least one of the multiple tasks is completed, the first time slot corresponding to the completed task can be allocated to a new task. For example, among 10 tasks, task 3 is completed. The third first time slot corresponding to task 3 can be allocated to a new task 11, thereby improving the efficiency of multi-task execution.
在本实施例中,在Scrypt算法工作量证明的第一阶段,在第一数据中抽取部分数据作为存储数据进行存储,可以节省存储空间。将多个任务分别对应至第一周期内不同的第一时隙,在与各任务对应的第一时隙内生成第二数据,可以提高多任务的执行效率。In this embodiment, in the first stage of the Scrypt algorithm workload proof, part of the data is extracted from the first data and stored as storage data, which can save storage space. Multiple tasks are respectively mapped to different first time slots in the first cycle, and second data is generated in the first time slot corresponding to each task, which can improve the execution efficiency of multiple tasks.
图2示出根据本公开一实施例的Scrypt算法工作量证明方法的流程图,如图2所示,方法包括:步骤S11、步骤S20,其中步骤S20可参考上述图1中相关描述,步骤S11包括:FIG2 shows a flow chart of a Scrypt algorithm workload proof method according to an embodiment of the present disclosure. As shown in FIG2 , the method includes: step S11 and step S20, wherein step S20 may refer to the relevant description in FIG1 above, and step S11 includes:
步骤S11,在各任务的第一阶段,将各任务分别对应至第二周期内不同的第二时隙,在与目标任务对应的第二时隙内,生成第一数据,并在第一数据中抽取部分数据作为存储数据写入存储器,第二周期包括多个第二时隙,第二时隙的数量大于或等于任务的数量。Step S11, in the first stage of each task, each task is respectively corresponded to a different second time slot in the second cycle, and in the second time slot corresponding to the target task, the first data is generated, and part of the data is extracted from the first data and written into the memory as storage data. The second cycle includes multiple second time slots, and the number of second time slots is greater than or equal to the number of tasks.
在一种可能的实现方式中,可以将各任务分别对应至第二周期内的不同第二时隙,在于目标任务对应的第二时隙内,执行目标任务的第一阶段,生成第一数据,并在第一数据中抽取部分数据作为存储数据写入存储器。由于各任务第二阶段的执行时长不同,将各任务分别对应至第一周期后,当其中一个任务完成后,可以释放与其对应的第一时隙,并将释放出的第一时隙用于新的任务。相应的,可以将与完成的任务对应的第二周期内对应的第二时隙也释放,并将释放出的第二时隙也分配至新的任务,以提高多任务的执行效率。In a possible implementation, each task can be respectively mapped to a different second time slot in the second cycle, and in the second time slot corresponding to the target task, the first stage of the target task is executed to generate first data, and part of the data in the first data is extracted and written into the memory as storage data. Since the execution time of the second stage of each task is different, after each task is respectively mapped to the first cycle, when one of the tasks is completed, the first time slot corresponding to it can be released, and the released first time slot can be used for a new task. Accordingly, the second time slot corresponding to the second cycle corresponding to the completed task can also be released, and the released second time slot can also be allocated to the new task to improve the execution efficiency of multiple tasks.
在一种可能的实现方式中,各任务在第一周期对应的第一时隙的序号,可以与在第二周期内对应的第二时隙的序号相同或不同。In a possible implementation, the sequence number of the first time slot corresponding to each task in the first cycle may be the same as or different from the sequence number of the second time slot corresponding to each task in the second cycle.
在本实施例中,在各任务的第一阶段,将各任务分别对应至第二周期内不同的第二时隙,在与目标任务对应的第二时隙内,生成第一数据,并在第一数据中抽取部分数据作为存储数据写入存储器。将各任务的第一阶段,也在对应的第一时隙内完成,可以进一步提高多任务的执行效率。In this embodiment, in the first stage of each task, each task is respectively mapped to a different second time slot in the second cycle, and in the second time slot corresponding to the target task, first data is generated, and part of the first data is extracted and written into the memory as storage data. The first stage of each task is also completed in the corresponding first time slot, which can further improve the execution efficiency of multiple tasks.
图3示出根据本公开一实施例的Scrypt算法工作量证明方法的流程图,如图3所示,方法包括:步骤S10、步骤S21、步骤S22、步骤S23,其中步骤S10可参考上述图1中相关描述,步骤S21、步骤S22以及步骤S23包括:FIG3 shows a flow chart of a Scrypt algorithm workload proof method according to an embodiment of the present disclosure. As shown in FIG3 , the method includes: step S10, step S21, step S22, and step S23, wherein step S10 may refer to the relevant description in FIG1 above, and step S21, step S22, and step S23 include:
步骤S21,在目标任务的存储数据中查找与当前第二数据对应的第一数据。Step S21, searching the storage data of the target task for the first data corresponding to the current second data.
在一种可能的实现方式中,存储数据为部分第一数据。与当前第二数据对应的第一数据可能是存储数据,也可能不是存储数据。当与当前第二数据对应的第一数据为存储数据时,可以在存储数据中提取后用于当前第二数据的计算。In a possible implementation, the stored data is part of the first data. The first data corresponding to the current second data may be the stored data or may not be the stored data. When the first data corresponding to the current second data is the stored data, it can be extracted from the stored data and used for calculating the current second data.
步骤S22,当无法在存储数据中查找到与当前第二数据对应的第一数据时,根据最接近的存储数据,确定与当前第二数据对应的第一数据。Step S22: when the first data corresponding to the current second data cannot be found in the stored data, the first data corresponding to the current second data is determined according to the closest stored data.
在一种可能的实现方式中,当无法在存储数据中查找到与当前第二数据对应的第一数据时,可以根据最接近的存储数据,利用HASH函数进行计算后,确定与当前第二数据对应的第一数据。例如,与当前第二数据对应的第一数据的序列号为14,存储数据中各第一数据的序列号分别为1、6、11、16……等。可以根据最接近序列号14的第16个第一数据,利用HASH函数进行级联计算,得到与当前第二数据对应的序列号为14的第一数据。In a possible implementation, when the first data corresponding to the current second data cannot be found in the stored data, the first data corresponding to the current second data can be determined after calculation using the HASH function based on the closest stored data. For example, the sequence number of the first data corresponding to the current second data is 14, and the sequence numbers of the first data in the stored data are 1, 6, 11, 16, etc. The first data corresponding to the current second data with a sequence number of 14 can be obtained by performing a cascade calculation using the HASH function based on the 16th first data closest to the sequence number 14.
在一种可能的实现方式中,可以将序列号小于与当前第二数据对应的第一数据的序列号中最接近的存储数据,确定为最接近的存储数据。例如,可以在小于14的序列号中,根据最接近的序列号为11的第一数据,利用HASH函数进行级联计算,得到与当前第二数据对应的序列号为14的第一数据。In a possible implementation, the closest stored data with a sequence number smaller than the sequence number of the first data corresponding to the current second data may be determined as the closest stored data. For example, among the sequence numbers smaller than 14, the first data with the closest sequence number of 11 may be cascaded using a HASH function to obtain the first data with a sequence number of 14 corresponding to the current second data.
步骤S23,根据与当前第二数据对应的第一数据和当前第二数据,得到当前第二数据的下一个第二数据。Step S23, obtaining the next second data of the current second data according to the first data corresponding to the current second data and the current second data.
在一种可能的实现方式中,可以将当前第二数据利用HASH函数进行运算得到运算结果,可以将与当前第二数据对应的第一数据和运算结果进行异或运算,得到当前第二数据的下一个第二数据。In a possible implementation, the current second data may be operated using a HASH function to obtain an operation result, and the first data corresponding to the current second data and the operation result may be XORed to obtain the next second data of the current second data.
在本实施例中,当无法在各存储数据中查找到与当前第二数据对应的第一数据时,根据最接近的存储数据,确定与当前第二数据对应的第一数据,并根据与当前第二数据对应的第一数据和当前第二数据,得到当前第二数据的下一个第二数据。第二数据可以根据存储数据计算得到,降低了第一数据所需的存储空间。In this embodiment, when the first data corresponding to the current second data cannot be found in each stored data, the first data corresponding to the current second data is determined based on the closest stored data, and the next second data of the current second data is obtained based on the first data corresponding to the current second data and the current second data. The second data can be calculated based on the stored data, reducing the storage space required for the first data.
在一种可能的实现方式中,第一数据为有序序列,方法中步骤S10,包括:In a possible implementation, the first data is an ordered sequence, and step S10 in the method includes:
根据存储数据的序列号确定存储数据的存储地址。The storage address of the stored data is determined according to the serial number of the stored data.
在一种可能的实现方式中,可以根据第一数据的序列号确定存储数据的序列号。例如,当序列号为1、10、15、20的第一数据作为存储数据时,存储数据的序列号也为1、10、15、20。可以将存储数据的序列号作为存储数据的存储地址。即各存储数据的存储地址为1、10、15、20。In a possible implementation, the sequence number of the stored data can be determined according to the sequence number of the first data. For example, when the first data with sequence numbers 1, 10, 15, and 20 are used as the stored data, the sequence numbers of the stored data are also 1, 10, 15, and 20. The sequence number of the stored data can be used as the storage address of the stored data. That is, the storage addresses of each stored data are 1, 10, 15, and 20.
步骤S21,包括:根据在目标任务的当前第二数据中预设数位上的数据生成索引地址,在存储地址中查找索引地址,根据查找结果确定与当前第二数据对应的第一数据。Step S21 includes: generating an index address according to data at a preset digit in the current second data of the target task, searching for the index address in the storage address, and determining the first data corresponding to the current second data according to the search result.
在一种可能的实现方式中,可以以2为底数,以当前第二数据中预设数位上的数据为指数,生成当前第二数据的索引地址。例如,第一数据的数量为1024个。可以以2为底数,以第二数据中最后10个数位上的数据作为指数得到1024个结果,可以对应1024个第一数据。可以根据需求确定预设数位的数量和位置。In a possible implementation, the index address of the current second data can be generated by taking 2 as the base and the data at the preset digits in the current second data as the index. For example, the number of first data is 1024. 1024 results can be obtained by taking 2 as the base and the data at the last 10 digits in the second data as the index, which can correspond to 1024 first data. The number and position of the preset digits can be determined according to requirements.
在一种可能的实现方式中,可以在存储地址中查找索引地址。如果在存储地址中查找到索引地址,可以将与索引地址相同的存储地址上的存储数据,确定为与当前第二数据对应的第一数据。如果在存储地址中没有查找到索引地址,可以在小于索引地址的存储地址中,查找与索引地址最接近的存储地址中的存储数据,经过级联结算得到与当前第二数据对应的第一数据。例如,索引地址为14,存储地址为1,5,10,15,可以根据存储地址为10的存储数据,经过级联计算得到存储地址为14的第一数据。In one possible implementation, the index address may be searched in the storage address. If the index address is found in the storage address, the storage data at the same storage address as the index address may be determined as the first data corresponding to the current second data. If the index address is not found in the storage address, the storage data at the storage address closest to the index address may be searched in the storage addresses less than the index address, and the first data corresponding to the current second data may be obtained through cascade calculation. For example, if the index address is 14 and the storage addresses are 1, 5, 10, and 15, the first data at the storage address 14 may be obtained through cascade calculation based on the storage data at the storage address 10.
在本实施例中,根据存储数据的序列号确定存储数据的存储地址,根据当前第二数据中预设数位上的数据生成索引地址,在存储地址中查找索引地址,根据查找结果确定与当前第二数据对应的第一数据。通过存储地址和索引地址,可以使得与当前第二数据对应的第一数据的查找过程简单、可靠。In this embodiment, the storage address of the stored data is determined according to the serial number of the stored data, the index address is generated according to the data at the preset digit in the current second data, the index address is searched in the storage address, and the first data corresponding to the current second data is determined according to the search result. Through the storage address and the index address, the search process of the first data corresponding to the current second data can be made simple and reliable.
在一种可能的实现方式中,根据最接近的存储数据,确定与当前第二数据对应的第一数据,包括:In a possible implementation, determining first data corresponding to current second data according to the closest stored data includes:
确定最接近的存储地址与索引地址之间的差值。The difference between the closest storage address and the index address is determined.
根据差值确定的迭代次数,将最接近的存储地址中的存储数据进行迭代运算,得到与索引地址对应的第一数据。According to the number of iterations determined by the difference, the storage data in the closest storage address is iteratively calculated to obtain the first data corresponding to the index address.
在一种可能的实现方式中,可以在小于索引地址的存储地址中,确定与索引地址最接近的存储地址。可以计算最接近的存储地址与索引地址之间的差值。例如,索引地址为14,各存储数据的存储地址为1、5、10、15、20……。可以将存储地址10确定为最接近的存储地址,确定差值为14-10=4。In a possible implementation, the storage address closest to the index address can be determined among the storage addresses smaller than the index address. The difference between the closest storage address and the index address can be calculated. For example, the index address is 14, and the storage addresses of the storage data are 1, 5, 10, 15, 20, ... The storage address 10 can be determined as the closest storage address, and the difference is determined to be 14-10=4.
在一种可能的实现方式中,由于第一数据之间具有级联关系。可以根据差值,对最接近的存储地址中的存储数据进行迭代计算,得到与索引地址对应的第一数据。例如,差值为4,可以将最近接的存储地址中的存储数据,利用HASH函数进行四次迭代运算,得到与索引地址对应的第一数据。In a possible implementation, since the first data have a cascade relationship, the storage data in the closest storage address can be iteratively calculated according to the difference to obtain the first data corresponding to the index address. For example, if the difference is 4, the storage data in the closest storage address can be iteratively calculated four times using the HASH function to obtain the first data corresponding to the index address.
在本实施中,可以确定最接近的存储地址与索引地址之间的差值;根据差值确定的迭代次数,将最接近的存储地址中的存储数据进行迭代运算,得到与索引地址对应的第一数据。根据差值确定迭代次数,可以方便地根据存储数据计算得到与当前第二数据对应的第一数据。In this implementation, the difference between the closest storage address and the index address can be determined; according to the number of iterations determined by the difference, the storage data in the closest storage address is iteratively calculated to obtain the first data corresponding to the index address. By determining the number of iterations according to the difference, the first data corresponding to the current second data can be conveniently calculated according to the storage data.
在一种可能的实现方式中,方法还包括:In a possible implementation, the method further includes:
各任务的存储数据存储在存储器的不同存储空间,存储空间的数量大于或等于任务的数量。The storage data of each task is stored in different storage spaces of the memory, and the number of storage spaces is greater than or equal to the number of tasks.
在一种可能的实现方式中,可以将存储器划分为不同的存储空间。可以根据任务的数量确定存储空间的数量。例如,对应于10个任务,可以将存储器划分为10个存储空间,每个存储空间对应一个任务。各任务可将存储数据存储在对应的存储空间中,并在对应的存储空间中提取存储数据计算得到第二数据。In a possible implementation, the memory may be divided into different storage spaces. The number of storage spaces may be determined according to the number of tasks. For example, corresponding to 10 tasks, the memory may be divided into 10 storage spaces, each storage space corresponding to one task. Each task may store storage data in a corresponding storage space, and extract the storage data in the corresponding storage space to calculate and obtain the second data.
在本实施例中,通过将存取器划分为不同的存储空间,各任务在对应的存储空间进行数据的读写,可以提高数据读写效率,提高多任务的执行效率。In this embodiment, by dividing the memory into different storage spaces, each task reads and writes data in the corresponding storage space, which can improve the data reading and writing efficiency and improve the execution efficiency of multiple tasks.
在一种可能的实现方式中,以第一周期在前、第二周期在后组成的执行周期执行各任务。In a possible implementation, each task is executed in an execution cycle consisting of a first cycle in front and a second cycle in the back.
在一种可能的实现方式中,用于执行本公开实施例的Scrypt算法工作量证明方法的芯片,可以在同一时刻只读或只写。当本公开实施例中的方法应用于在同一时刻只读或只写的芯片时,可以将以第二周期在前、第一周期在后组成的执行周期执行各任务。In a possible implementation, a chip for executing the Scrypt algorithm workload proof method of the embodiment of the present disclosure may be read-only or write-only at the same time. When the method of the embodiment of the present disclosure is applied to a chip that is read-only or write-only at the same time, each task may be executed in an execution cycle consisting of the second cycle in front and the first cycle in the back.
例如,第二周期时长为T2,第一周期时长为T1,以T3=T1+T2为执行周期的时长。执行周期中先执行第二周期T2后执行第一周期T1。以执行周期T3依次执行各任务,在T3中的T2时长内,执行各任务的第一阶段。在T3中的T1时长内,执行各任务的第二阶段。For example, the second cycle duration is T2, the first cycle duration is T1, and T3=T1+T2 is the duration of the execution cycle. In the execution cycle, the second cycle T2 is executed first and then the first cycle T1 is executed. Each task is executed in sequence in the execution cycle T3. During the duration T2 in T3, the first stage of each task is executed. During the duration T1 in T3, the second stage of each task is executed.
在本实施例中,以第二周期在前、第一周期在后组成的执行周期执行各任务,可以满足在同一时刻只读或只写的芯片的使用环境,提高本公开实施例的适用性。In this embodiment, each task is executed in an execution cycle consisting of the second cycle in front and the first cycle in the back, which can meet the use environment of the chip that is only read or only write at the same time, and improve the applicability of the embodiment of the present disclosure.
在一种可能的实现方式中,第一周期还包括空闲时隙,空闲时隙的数量或时长根据存储器的延迟确定。In a possible implementation, the first cycle further includes idle time slots, and the number or duration of the idle time slots is determined according to a delay of the memory.
在一种可能的实现方式中,由于各任务的第二阶段的耗时比第一阶段长,第一周期中还可以包括空闲时隙。包括空闲时隙的第一周期的时长可以长于第二周期的时长。空闲时隙的数量或时长,可以根据存储器的延迟特性确定。空闲时隙可以用于对应各任务的运算开销所需的时长,使得第一周期中的第一时隙能够与各任务对齐。In a possible implementation, since the second phase of each task takes longer than the first phase, the first cycle may further include an idle time slot. The duration of the first cycle including the idle time slot may be longer than the duration of the second cycle. The number or duration of the idle time slot may be determined according to the delay characteristics of the memory. The idle time slot may be used to correspond to the duration required for the computational overhead of each task, so that the first time slot in the first cycle can be aligned with each task.
在本实施例中,第一周期还可以包括空闲时隙。空闲时隙用于对应各任务的运算开销所需时长,将第一周期中的各第一时隙与各任务对齐,提高各任务的执行效率。In this embodiment, the first cycle may further include idle time slots. The idle time slots are used to correspond to the duration required for the computational overhead of each task, and each first time slot in the first cycle is aligned with each task to improve the execution efficiency of each task.
在一种可能的实现方式中,第一周期和第二周期并行。In a possible implementation, the first cycle and the second cycle are performed in parallel.
在一种可能的实现方式中,用于执行本公开实施例的Scrypt算法工作量证明方法的芯片,可以在同一时刻同时读写。本公开实施例中的方法应用于在同一时刻可以同时读写的芯片时,第一周期可以和第二周期并行。In a possible implementation, a chip for executing the Scrypt algorithm workload proof method of the embodiment of the present disclosure can read and write at the same time. When the method in the embodiment of the present disclosure is applied to a chip that can read and write at the same time, the first cycle can be parallel to the second cycle.
在本实施例中,第一周期和第二周期并行可以满足在同一时刻可以同时读写的芯片的使用环境,提高本公开实施例的适用性。In this embodiment, the first cycle and the second cycle are carried out in parallel to meet the use environment of the chip that can read and write at the same time, thereby improving the applicability of the embodiment of the present disclosure.
图4示出根据本公开一实施例的Scrypt算法工作量证明装置的框图,如图4所示,装置用于执行多个工作量证明的任务,任务包括第一阶段和第二阶段,装置包括:FIG4 shows a block diagram of a Scrypt algorithm workload proof device according to an embodiment of the present disclosure. As shown in FIG4 , the device is used to perform multiple workload proof tasks, the tasks include a first stage and a second stage, and the device includes:
抽取模块10,用于在各任务的第一阶段,在第一数据中抽取部分数据作为存储数据进行存储,存储数据的数量少于第一数据的数量;An extraction module 10 is used to extract part of the data from the first data and store it as storage data in the first stage of each task, and the amount of the storage data is less than the amount of the first data;
第一周期执行模块20,用于在各任务的第二阶段,将各任务分别对应至第一周期内不同的第一时隙,在与目标任务对应的第一时隙内,根据目标任务的存储数据确定对应的第一数据,根据对应的第一数据生成第二数据,目标任务包括任一任务,第一周期包括多个第一时隙,第一时隙的数量大于或等于任务的数量。The first cycle execution module 20 is used to correspond each task to a different first time slot in the first cycle in the second stage of each task, determine the corresponding first data according to the storage data of the target task in the first time slot corresponding to the target task, and generate second data according to the corresponding first data. The target task includes any task, and the first cycle includes multiple first time slots, and the number of first time slots is greater than or equal to the number of tasks.
在一种可能的实现方式中,抽取模块10,包括:In a possible implementation, the extraction module 10 includes:
第二周期执行子模块,用于在各任务的第一阶段,将各任务分别对应至第二周期内不同的第二时隙,在与目标任务对应的第二时隙内,生成第一数据,并在第一数据中抽取部分数据作为存储数据写入存储器,第二周期包括多个第二时隙,第二时隙的数量大于或等于任务的数量。The second cycle execution submodule is used to correspond each task to a different second time slot in the second cycle in the first stage of each task, generate first data in the second time slot corresponding to the target task, and extract part of the first data and write it into the memory as storage data. The second cycle includes multiple second time slots, and the number of second time slots is greater than or equal to the number of tasks.
在一种可能的实现方式中,第一周期执行模块20,包括:In a possible implementation, the first cycle execution module 20 includes:
对应数据查找子模块,用于在目标任务的存储数据中查找与当前第二数据对应的第一数据;A corresponding data search submodule, used to search the stored data of the target task for the first data corresponding to the current second data;
对应数据确定子模块,用于当无法在存储数据中查找到与当前第二数据对应的第一数据时,根据最接近的存储数据,确定与当前第二数据对应的第一数据;A corresponding data determination submodule, for determining the first data corresponding to the current second data according to the closest stored data when the first data corresponding to the current second data cannot be found in the stored data;
第二数据获取子模块,用于根据与当前第二数据对应的第一数据和当前第二数据,得到当前第二数据的下一个第二数据。The second data acquisition submodule is used to obtain the next second data of the current second data according to the first data corresponding to the current second data and the current second data.
在一种可能的实现方式中,第一数据为有序序列,抽取模块10,包括:In a possible implementation, the first data is an ordered sequence, and the extraction module 10 includes:
存储地址子模块,用于根据存储数据的序列号确定存储数据的存储地址;A storage address submodule, used to determine the storage address of the stored data according to the serial number of the stored data;
对应数据查找子模块,用于:The corresponding data search submodule is used for:
根据在目标任务的当前第二数据中预设数位上的数据生成索引地址,在存储地址中查找索引地址,根据查找结果确定与当前第二数据对应的第一数据。An index address is generated according to data at a preset digit in the current second data of the target task, the index address is searched in the storage address, and the first data corresponding to the current second data is determined according to the search result.
在一种可能的实现方式中,对应数据确定子模块,用于:In a possible implementation, the corresponding data determination submodule is used to:
确定最接近的存储地址与索引地址之间的差值;determining the difference between the closest storage address and the index address;
根据差值确定的迭代次数,将最接近的存储地址中的存储数据进行迭代运算,得到与索引地址对应的第一数据。According to the number of iterations determined by the difference, the storage data in the closest storage address is iteratively calculated to obtain the first data corresponding to the index address.
在一种可能的实现方式中,在第一数据中抽取部分数据作为存储数据进行存储,包括以下任意一种:In a possible implementation, extracting part of the data from the first data as storage data for storage includes any of the following:
在第一数据中按照预设的抽取间隔抽取存储数据进行存储;Extracting and storing the stored data in the first data according to a preset extraction interval;
在第一数据中按照预设的序列号范围抽取存储数据进行存储;Extracting and storing the stored data in the first data according to a preset sequence number range;
在第一数据中随机抽取预设数量的存储数据进行存储。A preset number of storage data are randomly selected from the first data for storage.
在一种可能的实现方式中,各任务的存储数据存储在存储器的不同存储空间,存储空间的数量大于或等于任务的数量。In a possible implementation, the storage data of each task is stored in different storage spaces of the memory, and the number of the storage spaces is greater than or equal to the number of tasks.
在一种可能的实现方式中,以第二周期在前、第一周期在后组成的执行周期执行各任务。In a possible implementation, each task is executed in an execution cycle consisting of a second cycle in front and a first cycle in the back.
在一种可能的实现方式中,第一周期还包括空闲时隙,空闲时隙的数量或时长根据存储器的延迟确定。In a possible implementation, the first cycle further includes idle time slots, and the number or duration of the idle time slots is determined according to a delay of the memory.
在一种可能的实现方式中,第一周期和第二周期并行。In a possible implementation, the first cycle and the second cycle are performed in parallel.
在一种可能的实现方式中,装置还包括:分配模块,用于当多个任务中的至少一个任务执行完毕时,将执行完毕的任务对应的第一时隙分配至新的任务。In a possible implementation, the device further includes: an allocation module, configured to allocate a first time slot corresponding to the completed task to a new task when at least one of the multiple tasks is completed.
以上已经描述了本公开的各实施例,上述说明是示例性的,并非穷尽性的,并且也不限于所披露的各实施例。在不偏离所说明的各实施例的范围和精神的情况下,对于本技术领域的普通技术人员来说许多修改和变更都是显而易见的。本文中所用术语的选择,旨在最好地解释各实施例的原理、实际应用或对市场中的技术的技术改进,或者使本技术领域的其它普通技术人员能理解本文披露的各实施例。The embodiments of the present disclosure have been described above, and the above description is exemplary, not exhaustive, and is not limited to the disclosed embodiments. Many modifications and variations will be apparent to those of ordinary skill in the art without departing from the scope and spirit of the described embodiments. The selection of terms used herein is intended to best explain the principles of the embodiments, practical applications, or technical improvements to the technology in the market, or to enable other persons of ordinary skill in the art to understand the embodiments disclosed herein.
Claims (16)
Priority Applications (1)
| Application Number | Priority Date | Filing Date | Title |
|---|---|---|---|
| CN201910068396.6A CN109815372B (en) | 2019-01-24 | 2019-01-24 | Scrypt algorithm workload proof method and device |
Applications Claiming Priority (1)
| Application Number | Priority Date | Filing Date | Title |
|---|---|---|---|
| CN201910068396.6A CN109815372B (en) | 2019-01-24 | 2019-01-24 | Scrypt algorithm workload proof method and device |
Publications (2)
| Publication Number | Publication Date |
|---|---|
| CN109815372A CN109815372A (en) | 2019-05-28 |
| CN109815372B true CN109815372B (en) | 2024-11-08 |
Family
ID=66604932
Family Applications (1)
| Application Number | Title | Priority Date | Filing Date |
|---|---|---|---|
| CN201910068396.6A Active CN109815372B (en) | 2019-01-24 | 2019-01-24 | Scrypt algorithm workload proof method and device |
Country Status (1)
| Country | Link |
|---|---|
| CN (1) | CN109815372B (en) |
Family Cites Families (11)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| JP4580845B2 (en) * | 2005-08-24 | 2010-11-17 | パナソニック株式会社 | Task execution device |
| CN1971710B (en) * | 2006-12-08 | 2010-09-29 | 中兴通讯股份有限公司 | A scheduling method for multi-channel multi-speech codec based on single chip |
| JP5957357B2 (en) * | 2012-10-15 | 2016-07-27 | 株式会社日立ハイテクノロジーズ | Pattern inspection / measurement apparatus and program |
| WO2016147279A1 (en) * | 2015-03-13 | 2016-09-22 | 富士通株式会社 | Data management control program, data management control device, and data management control method |
| CN105515565B (en) * | 2015-12-14 | 2018-07-13 | 天津光电通信技术有限公司 | A kind of method that hardware logic resource multiplex module and multiplexing are realized |
| CN106919628A (en) * | 2015-12-28 | 2017-07-04 | 阿里巴巴集团控股有限公司 | A kind for the treatment of method and apparatus of diagram data |
| CN107396447B (en) * | 2017-08-02 | 2023-06-13 | 苏州欧普照明有限公司 | Time slot allocation method, device and system for LoRa star networking |
| CN107451292A (en) * | 2017-08-16 | 2017-12-08 | 北京京东尚科信息技术有限公司 | Scene feature data storage method, system and data extraction system on line |
| CN107748794B (en) * | 2017-11-03 | 2021-03-12 | 中国人民解放军陆军工程大学 | Spatial data storage method |
| CN108322304B (en) * | 2018-02-28 | 2021-12-07 | 海峡小鹿有限公司 | Calculation method and apparatus for workload certification, electronic device, program, and medium |
| CN108549830A (en) * | 2018-04-11 | 2018-09-18 | 思力科(深圳)电子科技有限公司 | A kind of RFID reader and block chain network applied to block chain |
-
2019
- 2019-01-24 CN CN201910068396.6A patent/CN109815372B/en active Active
Non-Patent Citations (1)
| Title |
|---|
| 阿尔文德 林华等.区块链:技术驱动金融.中信出版社,2016,(第2016年8月第1版版),第249-280页. * |
Also Published As
| Publication number | Publication date |
|---|---|
| CN109815372A (en) | 2019-05-28 |
Similar Documents
| Publication | Publication Date | Title |
|---|---|---|
| US11349639B2 (en) | Circuit and method for overcoming memory bottleneck of ASIC-resistant cryptographic algorithms | |
| US9489409B2 (en) | Rollover strategies in a N-bit dictionary compressed column store | |
| US20150120774A1 (en) | Modified b+ tree node searching method and apparatus | |
| US11074246B2 (en) | Cluster-based random walk processing | |
| WO2018027706A1 (en) | Fft processor and algorithm | |
| CN117539546A (en) | Sparse matrix vector multiplication acceleration method and device based on non-empty column storage | |
| CN108171327A (en) | A kind of matrix method for transformation, device and medium based on convolution algorithm | |
| CN112579595A (en) | Data processing method and device, electronic equipment and readable storage medium | |
| WO2025044317A1 (en) | Method and apparatus for accelerating model training, storage medium, and electronic device | |
| CN111126619A (en) | A machine learning method and device | |
| CN118519768A (en) | Method, device, equipment and storage medium for overflowing data to shared buffer memory | |
| CN110968538B (en) | Data buffering method and device | |
| CN112464157B (en) | Vector ordering method and system | |
| CN109815372B (en) | Scrypt algorithm workload proof method and device | |
| CN112035380B (en) | Data processing method, device and equipment and readable storage medium | |
| US20080162856A1 (en) | Method for dynamic memory allocation on reconfigurable logic | |
| CN111341374B (en) | Memory test method and device and readable memory | |
| CN109799961B (en) | Circuit Architecture | |
| Awais | Memory management: Challenges and techniques for traditional memory allocation algorithms in relation with today’s real time needs | |
| CN110019975B (en) | Random walk, cluster-based random walk method, apparatus, and apparatus | |
| CN116880780A (en) | Tree data writing method, device, machine-readable medium and memory | |
| CN113641872B (en) | Hashing method, hashing device, hashing equipment and hashing medium | |
| CN111104435B (en) | Metadata organization method, device and equipment and computer readable storage medium | |
| CN109816110B (en) | Scrypt algorithm workload proving method and Scrypt algorithm workload proving device | |
| JPWO2019008715A1 (en) | Data load program, data load method and data load device |
Legal Events
| Date | Code | Title | Description |
|---|---|---|---|
| PB01 | Publication | ||
| PB01 | Publication | ||
| TA01 | Transfer of patent application right | ||
| TA01 | Transfer of patent application right |
Effective date of registration: 20211025 Address after: 200436 room 138, No. 5 and 6, Lane 1188, Wanrong Road, Jing'an District, Shanghai Applicant after: Shanghai Canaan Jiesi Information Technology Co.,Ltd. Address before: 310026 room 1203, floor 12, building 4, No. 9, Jiuhuan Road, Jianggan District, Hangzhou, Zhejiang Province Applicant before: Hangzhou Canaan Creative Information Technology Ltd. |
|
| SE01 | Entry into force of request for substantive examination | ||
| SE01 | Entry into force of request for substantive examination | ||
| GR01 | Patent grant | ||
| GR01 | Patent grant |