当前位置:网站首页>在 sCrypt 中实现高效的椭圆曲线点加法和乘法
在 sCrypt 中实现高效的椭圆曲线点加法和乘法
2022-06-30 10:04:00 【sCrypt 智能合约】
我们提出了一种新颖有效的方法,用于在比特币脚本中计算椭圆曲线上的点加法和标量乘法。对于点添加,我们将超过 1MB 的脚本大小减少到 ~400 字节。

点加法
对于每个 i,每个点 Pi 由两个坐标 (xi, yj) 表示。为了计算 P3 = P1 + P2,我们使用以下公式

加点公式
如果 P1 != P2,

否则

一个简单的实现需要计算模倒数,应用扩展的欧几里德算法。然而,这会导致脚本大小过大,因为算法中的确切循环数事先未知,并且必须使用大的保守上限。
高效的解决方案
我们不是直接计算加点,而是通过在解锁脚本中传递预期点 P3 来解决这个问题。我们只在脚本中验证 P3 = P1 + P2。为了避免验证中的模倒数,我们将公式转化为以下等价形式。
当 P1 != P2

当 P1 == P2

与 P3 一样,λ 也是链下预先计算的,并在解锁脚本中传递,如下所示。这将产生非常紧凑的脚本,大小只有 ~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 是标量 x 的位表示,从最低有效位到最高有效位。我们预先计算 2P, 4P, 8P, …, 2²⁵⁵P 链下并将它们传递到解锁脚本中,这些在锁定脚本中得到验证,如下面的第 21-24 行所示。
// 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;
}
致谢
本文基于 Craig Wright 和 Owen Vaughan 的工作,以及来自 nChain 的 Enrique Larraia 和 Owen Vaughan 的宝贵反馈。
边栏推荐
- 滴滴开源敏捷测试用例管理平台!
- Google 辟谣放弃 TensorFlow,它还活着!
- Using LVM to resize partitions
- 【Proteus仿真】Arduino UNO LED模拟交通灯
- 我的远程办公深度体验 | 社区征文
- Enter the world of helium (hNT) hotspot servers to bring you different benefits
- Why can't you rob scientists of NFT
- June training (day 30) - topology sorting
- R语言plotly可视化:使用plotly可视化多分类模型的预测置信度、模型在2D网格中每个数据点预测的置信度、置信度定义为在某一点上最高分与其他类别得分之和之间的差值
- mysql数据库基础:存储过程和函数
猜你喜欢

Yixian e - commerce publie un rapport trimestriel: adhérer à la R & D et à l’investissement de la marque, réaliser un développement durable et de haute qualité

Remember the experience of an internship. It is necessary to go to the pit (I)

Using LVM to resize partitions
[email protected]+ Alibaba cloud +nbiot+dht11+bh1750+ soil moisture sensor +oled"/>Skill sorting [email protected]+ Alibaba cloud +nbiot+dht11+bh1750+ soil moisture sensor +oled

Configure Yii: display MySQL extension module verification failed

CSDN blog operation team 2022 H1 summary

mysql数据库基础:约束、标识列

苹果5G芯片被曝研发失败,QQ密码bug引热议,蔚来回应做空传闻,今日更多大新闻在此...

How to seize the opportunity of NFT's "chaos"?

ArcGIS PRO + PS vectorized land use planning map
随机推荐
技能梳理[email protected]基于51系列单片机的智能仪器教具
Leetcode question brushing (IV) -- greedy thought (go Implementation)
GD32 RT-Thread OTA/Bootloader驱动函数
CSDN daily one practice 2021.11.06 question 1 (C language)
逸仙電商發布一季報:堅持研發及品牌投入,實現可持續高質量發展
Gd32 RT thread PWM drive function
JS FAQs
[deep learning] common methods for deep learning to detect small targets
Es common curl finishing
MATLAB image histogram equalization, namely spatial filtering
机器学习面试准备(一)KNN
Questions about cookies and sessions
Use keil5 software to simulate and debug gd32f305 from 0
Curl --- the request fails when the post request parameter is too long (more than 1024b)
历史上的今天:微软收购 PowerPoint 开发商;SGI 和 MIPS 合并
Gd32 RT thread ota/bootloader driver function
腾讯云数据库工程师能力认证重磅推出,各界共话人才培养难题
Skill combing [email protected] control a dog's running on OLED
Overview of currency
前嗅ForeSpider教程:抽取数据