当前位置:网站首页>Efficient elliptic curve point addition and multiplication in scrypt
Efficient elliptic curve point addition and multiplication in scrypt
2022-06-30 12:35:00 【Scrypt smart contract】
We propose a novel and effective method , Used to calculate point addition and scalar multiplication on elliptic curve in bitcoin script . For points add , We will surpass 1MB Script size reduced to ~400 byte .

Point addition
For each i, Each point Pi By two coordinates (xi, yj) Express . For calculation P3 = P1 + P2, We use the following formula

Add some formula
If P1 != P2,

otherwise

A simple implementation requires computing the reciprocal of the modulus , Apply extended Euclidean algorithm . However , This will cause the script size to be too large , Because the exact number of cycles in the algorithm is unknown in advance , And must use a large conservative upper limit .
Efficient solutions
We don't just add points , But by passing the expected point in the unlock script P3 To solve this problem . We only verify in the script P3 = P1 + P2. To avoid modulo reciprocal in verification , We convert the formula into the following equivalent form .
When P1 != P2

When P1 == P2

And P3 equally ,λ It is also pre calculated under the chain , And pass... In the unlock script , As shown below . This produces a very compact script , The size is only ~400B.
static function isSumHelper(Point p1, Point p2, int lambda, Point p) : bool {
// check lambda is indeed gradient
bool lambdaOK = (p1 == p2) ?
(2 * lambda * p1.y - 3 * p1.x * p1.x) % P == 0 :
(lambda * (p2.x - p1.x) - (p2.y - p1.y)) % P == 0;
// also check p = p1 + p2
return lambdaOK && (lambda * lambda - p1.x - p2.x - p.x) % P == 0 &&
(lambda * (p1.x - p.x) - p1.y - p.y) % P == 0;
}
// return true if lambda is the gradient of the line between p1 and p2
// and p = p1 + p2
static function isSum(Point p1, Point p2, int lambda, Point p) : bool {
// special handling of point ZERO
bool ret = p1 == ZERO ? p2 == p : (p2 == ZERO ? p1 == p : (p1.x == p2.x && (p1.y + p2.y) % P == 0) ? p == ZERO : true);
return ret && isSumHelper(p1, p2, lambda, p);
}
x * P = (x0 + x1 * 2 + x2 * 4 + x3 * 8 + … + x255 * 2²⁵⁵) * P
= x0 * P + x1 * (2P) + x2 * (4P) + x3 * (8P) + … + x255 * (2²⁵⁵P)
x0, x1, x2, …, x255 It's scalar x The bit of "s" means , From least significant bit to most significant bit . We calculate in advance 2P, 4P, 8P, …, 2²⁵⁵P Chain them down and pass them to the unlock script , These are verified in the locking script , As shown in the following paragraph 21-24 Line .
// return true iff p * x == r
static function isMul(Point p, int x, Point r, Point[EC.N] pMultiples, Point[EC.N] qs, int[EC.N1] lambdas1, int[EC.N1] lambdas2) : bool {
// validate pMultiples = [p, 2p, 4p, 8p, ...]
loop (N) : i {
require(i == 0 ? pMultiples[i] == p : isSum(pMultiples[i - 1], pMultiples[i - 1], lambdas1[i - 1], pMultiples[i]));
}
// // x * p = x0 * p + x1 *(2p) + x2 * (4p) + x3 * (8p) + ...
// // xi is the i-th bit of x
Point P0 = ZERO;
loop (N) : i {
Point P = x % 2 ? pMultiples[i] : ZERO;
// right shift by 1
x /= 2;
if (i == 0) {
P0 = P;
} else if (i == 1) {
// first
require(isSum(P0, P, lambdas2[i - 1], qs[i - 1]));
} else {
// rest
require(isSum(qs[i - 1], P, lambdas2[i - 1], i < N1 ? qs[i] : r));
}
}
return true;
}
thank
This article is based on Craig Wright and Owen Vaughan The job of , As well as from nChain Of Enrique Larraia and Owen Vaughan Valuable feedback from .
边栏推荐
- 【一天学awk】数组的使用
- NoSQL - redis configuration and optimization
- Videos are stored in a folder every 100 frames, and pictures are transferred to videos after processing
- JMeter性能测试之相关术语及性能测试通过标准
- Substrate 源码追新导读: Call调用索引化, 存储层事物化全面完成
- Commands for redis basic operations
- Time function and clock_ Differences between gettime() functions
- 实现多方数据安全共享,解决普惠金融信息不对称难题
- Layout of pyqt5 interface and loading of resource files
- A high precision positioning approach for category support components with multiscale difference reading notes
猜你喜欢

90.(cesium篇)cesium高度监听事件

Set set

STM32 porting the fish component of RT thread Standard Edition

【一天学awk】运算符

Why should offline stores do new retail?

立创 EDA #学习笔记10# | 常用连接器元器件识别 和 无源蜂鸣器驱动电路

NoSQL - redis configuration and optimization

iServer发布ES服务查询设置最大返回数量

A new journey of the smart court, paperless office, escorting the green trial of the smart court

Some commonly used hardware information of the server (constantly updated)
随机推荐
立创 EDA #学习笔记10# | 常用连接器元器件识别 和 无源蜂鸣器驱动电路
List collection
移除无效的括号[用数组模拟栈]
品达通用权限系统(Day 7~Day 8)
MySQL composite query
edusoho企培版纯内网部署教程(解决播放器,上传,后台卡顿问题)
图解使用Navicat for MySQL创建存储过程
Essay: Research on smart home scheme
Redis cache problem
拆分电商系统为微服务
剑指 Offer 05. 替换空格: 把字符串 s 中的每个空格替换成“%20“
Introduction to the pursuit of new subtrate source code - early May: xcm officially launched
pyqt5界面的布局与资源文件的载入
[leetcode] 15. Sum of three numbers
Getting started with the go language is simple: go handles XML files
90.(cesium篇)cesium高度监听事件
通过EF Core框架根据SQL Server数据库表生成实体类
The format of RTSP address of each manufacturer is as follows:
SuperMap 3D SDKs_ Unity plug-in development - connect data services for SQL queries
使用Power Designer工具构建数据库模型