Skip to content

Commit f37b9af

Browse files
authored
Merge 66514bb into 5f65aff
2 parents 5f65aff + 66514bb commit f37b9af

File tree

11 files changed

+158
-93
lines changed

11 files changed

+158
-93
lines changed

src/bitcoin-cli.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1216,8 +1216,8 @@ static int CommandLineRPC(int argc, char *argv[])
12161216
// Export main() and ensure working ASLR on Windows.
12171217
// Exporting a symbol will prevent the linker from stripping
12181218
// the .reloc section from the binary, which is a requirement
1219-
// for ASLR. This is a temporary workaround until a fixed
1220-
// version of binutils is used for releases.
1219+
// for ASLR. While release builds are not affected, anyone
1220+
// building with a binutils < 2.36 is subject to this ld bug.
12211221
__declspec(dllexport) int main(int argc, char* argv[])
12221222
{
12231223
util::WinCmdLineArgs winArgs;

src/bitcoin-tx.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -854,7 +854,16 @@ static int CommandLineRawTx(int argc, char* argv[])
854854
return nRet;
855855
}
856856

857+
#ifdef WIN32
858+
// Export main() and ensure working ASLR on Windows.
859+
// Exporting a symbol will prevent the linker from stripping
860+
// the .reloc section from the binary, which is a requirement
861+
// for ASLR. While release builds are not affected, anyone
862+
// building with a binutils < 2.36 is subject to this ld bug.
863+
__declspec(dllexport) int main(int argc, char* argv[])
864+
#else
857865
int main(int argc, char* argv[])
866+
#endif
858867
{
859868
SetupEnvironment();
860869

src/bitcoin-util.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,8 +145,8 @@ static int Grind(const std::vector<std::string>& args, std::string& strPrint)
145145
// Export main() and ensure working ASLR on Windows.
146146
// Exporting a symbol will prevent the linker from stripping
147147
// the .reloc section from the binary, which is a requirement
148-
// for ASLR. This is a temporary workaround until a fixed
149-
// version of binutils is used for releases.
148+
// for ASLR. While release builds are not affected, anyone
149+
// building with a binutils < 2.36 is subject to this ld bug.
150150
__declspec(dllexport) int main(int argc, char* argv[])
151151
#else
152152
int main(int argc, char* argv[])

src/bitcoin-wallet.cpp

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,13 +88,21 @@ static bool WalletAppInit(ArgsManager& args, int argc, char* argv[])
8888
return true;
8989
}
9090

91-
int main(int argc, char* argv[])
92-
{
93-
ArgsManager& args = gArgs;
9491
#ifdef WIN32
92+
// Export main() and ensure working ASLR on Windows.
93+
// Exporting a symbol will prevent the linker from stripping
94+
// the .reloc section from the binary, which is a requirement
95+
// for ASLR. While release builds are not affected, anyone
96+
// building with a binutils < 2.36 is subject to this ld bug.
97+
__declspec(dllexport) int main(int argc, char* argv[])
98+
{
9599
util::WinCmdLineArgs winArgs;
96100
std::tie(argc, argv) = winArgs.get();
101+
#else
102+
int main(int argc, char* argv[])
103+
{
97104
#endif
105+
ArgsManager& args = gArgs;
98106

99107
int exit_status;
100108
std::unique_ptr<interfaces::Init> init = interfaces::MakeWalletInit(argc, argv, exit_status);

src/bitcoind.cpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -253,11 +253,19 @@ static bool AppInit(NodeContext& node, int argc, char* argv[])
253253
return fRet;
254254
}
255255

256-
int main(int argc, char* argv[])
257-
{
258256
#ifdef WIN32
257+
// Export main() and ensure working ASLR on Windows.
258+
// Exporting a symbol will prevent the linker from stripping
259+
// the .reloc section from the binary, which is a requirement
260+
// for ASLR. While release builds are not affected, anyone
261+
// building with a binutils < 2.36 is subject to this ld bug.
262+
__declspec(dllexport) int main(int argc, char* argv[])
263+
{
259264
util::WinCmdLineArgs winArgs;
260265
std::tie(argc, argv) = winArgs.get();
266+
#else
267+
int main(int argc, char* argv[])
268+
{
261269
#endif
262270

263271
NodeContext node;

src/qt/main.cpp

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,16 @@ extern const std::function<std::string(const char*)> G_TRANSLATION_FUN = [](cons
1818
};
1919
UrlDecodeFn* const URL_DECODE = urlDecode;
2020

21-
int main(int argc, char* argv[]) { return GuiMain(argc, argv); }
21+
#ifdef WIN32
22+
// Export main() and ensure working ASLR on Windows.
23+
// Exporting a symbol will prevent the linker from stripping
24+
// the .reloc section from the binary, which is a requirement
25+
// for ASLR. While release builds are not affected, anyone
26+
// building with a binutils < 2.36 is subject to this ld bug.
27+
__declspec(dllexport) int main(int argc, char* argv[])
28+
#else
29+
int main(int argc, char* argv[])
30+
#endif
31+
{
32+
return GuiMain(argc, argv);
33+
}

src/secp256k1/build-aux/m4/bitcoin_secp.m4

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
dnl escape "$0x" below using the m4 quadrigaph @S|@, and escape it again with a \ for the shell.
22
AC_DEFUN([SECP_64BIT_ASM_CHECK],[
33
AC_MSG_CHECKING(for x86_64 assembly availability)
4-
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
4+
AC_LINK_IFELSE([AC_LANG_PROGRAM([[
55
#include <stdint.h>]],[[
66
uint64_t a = 11, tmp;
77
__asm__ __volatile__("movq \@S|@0x100000000,%1; mulq %%rsi" : "+a"(a) : "S"(tmp) : "cc", "%rdx");

src/secp256k1/include/secp256k1.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,9 +141,13 @@ typedef int (*secp256k1_nonce_function)(
141141
# define SECP256K1_NO_BUILD
142142
#endif
143143

144+
/** At secp256k1 build-time DLL_EXPORT is defined when building objects destined
145+
* for a shared library, but not for those intended for static libraries.
146+
*/
147+
144148
#ifndef SECP256K1_API
145149
# if defined(_WIN32)
146-
# ifdef SECP256K1_BUILD
150+
# if defined(SECP256K1_BUILD) && defined(DLL_EXPORT)
147151
# define SECP256K1_API __declspec(dllexport)
148152
# else
149153
# define SECP256K1_API

src/secp256k1/sage/prove_group_implementations.sage

Lines changed: 34 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -40,29 +40,26 @@ def formula_secp256k1_gej_add_var(branch, a, b):
4040
s2 = s2 * a.Z
4141
h = -u1
4242
h = h + u2
43-
i = -s1
44-
i = i + s2
43+
i = -s2
44+
i = i + s1
4545
if branch == 2:
4646
r = formula_secp256k1_gej_double_var(a)
4747
return (constraints(), constraints(zero={h : 'h=0', i : 'i=0', a.Infinity : 'a_finite', b.Infinity : 'b_finite'}), r)
4848
if branch == 3:
4949
return (constraints(), constraints(zero={h : 'h=0', a.Infinity : 'a_finite', b.Infinity : 'b_finite'}, nonzero={i : 'i!=0'}), point_at_infinity())
50-
i2 = i^2
50+
t = h * b.Z
51+
rz = a.Z * t
5152
h2 = h^2
53+
h2 = -h2
5254
h3 = h2 * h
53-
h = h * b.Z
54-
rz = a.Z * h
5555
t = u1 * h2
56-
rx = t
57-
rx = rx * 2
56+
rx = i^2
5857
rx = rx + h3
59-
rx = -rx
60-
rx = rx + i2
61-
ry = -rx
62-
ry = ry + t
63-
ry = ry * i
58+
rx = rx + t
59+
rx = rx + t
60+
t = t + rx
61+
ry = t * i
6462
h3 = h3 * s1
65-
h3 = -h3
6663
ry = ry + h3
6764
return (constraints(), constraints(zero={a.Infinity : 'a_finite', b.Infinity : 'b_finite'}, nonzero={h : 'h!=0'}), jacobianpoint(rx, ry, rz))
6865

@@ -80,43 +77,41 @@ def formula_secp256k1_gej_add_ge_var(branch, a, b):
8077
s2 = s2 * a.Z
8178
h = -u1
8279
h = h + u2
83-
i = -s1
84-
i = i + s2
80+
i = -s2
81+
i = i + s1
8582
if (branch == 2):
8683
r = formula_secp256k1_gej_double_var(a)
8784
return (constraints(zero={b.Z - 1 : 'b.z=1'}), constraints(zero={a.Infinity : 'a_finite', b.Infinity : 'b_finite', h : 'h=0', i : 'i=0'}), r)
8885
if (branch == 3):
8986
return (constraints(zero={b.Z - 1 : 'b.z=1'}), constraints(zero={a.Infinity : 'a_finite', b.Infinity : 'b_finite', h : 'h=0'}, nonzero={i : 'i!=0'}), point_at_infinity())
90-
i2 = i^2
91-
h2 = h^2
92-
h3 = h * h2
9387
rz = a.Z * h
88+
h2 = h^2
89+
h2 = -h2
90+
h3 = h2 * h
9491
t = u1 * h2
95-
rx = t
96-
rx = rx * 2
92+
rx = i^2
9793
rx = rx + h3
98-
rx = -rx
99-
rx = rx + i2
100-
ry = -rx
101-
ry = ry + t
102-
ry = ry * i
94+
rx = rx + t
95+
rx = rx + t
96+
t = t + rx
97+
ry = t * i
10398
h3 = h3 * s1
104-
h3 = -h3
10599
ry = ry + h3
106100
return (constraints(zero={b.Z - 1 : 'b.z=1'}), constraints(zero={a.Infinity : 'a_finite', b.Infinity : 'b_finite'}, nonzero={h : 'h!=0'}), jacobianpoint(rx, ry, rz))
107101

108102
def formula_secp256k1_gej_add_zinv_var(branch, a, b):
109103
"""libsecp256k1's secp256k1_gej_add_zinv_var"""
110104
bzinv = b.Z^(-1)
111105
if branch == 0:
112-
return (constraints(), constraints(nonzero={b.Infinity : 'b_infinite'}), a)
113-
if branch == 1:
106+
rinf = b.Infinity
114107
bzinv2 = bzinv^2
115108
bzinv3 = bzinv2 * bzinv
116109
rx = b.X * bzinv2
117110
ry = b.Y * bzinv3
118111
rz = 1
119-
return (constraints(), constraints(zero={b.Infinity : 'b_finite'}, nonzero={a.Infinity : 'a_infinite'}), jacobianpoint(rx, ry, rz))
112+
return (constraints(), constraints(nonzero={a.Infinity : 'a_infinite'}), jacobianpoint(rx, ry, rz, rinf))
113+
if branch == 1:
114+
return (constraints(), constraints(zero={a.Infinity : 'a_finite'}, nonzero={b.Infinity : 'b_infinite'}), a)
120115
azz = a.Z * bzinv
121116
z12 = azz^2
122117
u1 = a.X
@@ -126,29 +121,25 @@ def formula_secp256k1_gej_add_zinv_var(branch, a, b):
126121
s2 = s2 * azz
127122
h = -u1
128123
h = h + u2
129-
i = -s1
130-
i = i + s2
124+
i = -s2
125+
i = i + s1
131126
if branch == 2:
132127
r = formula_secp256k1_gej_double_var(a)
133128
return (constraints(), constraints(zero={a.Infinity : 'a_finite', b.Infinity : 'b_finite', h : 'h=0', i : 'i=0'}), r)
134129
if branch == 3:
135130
return (constraints(), constraints(zero={a.Infinity : 'a_finite', b.Infinity : 'b_finite', h : 'h=0'}, nonzero={i : 'i!=0'}), point_at_infinity())
136-
i2 = i^2
131+
rz = a.Z * h
137132
h2 = h^2
138-
h3 = h * h2
139-
rz = a.Z
140-
rz = rz * h
133+
h2 = -h2
134+
h3 = h2 * h
141135
t = u1 * h2
142-
rx = t
143-
rx = rx * 2
136+
rx = i^2
144137
rx = rx + h3
145-
rx = -rx
146-
rx = rx + i2
147-
ry = -rx
148-
ry = ry + t
149-
ry = ry * i
138+
rx = rx + t
139+
rx = rx + t
140+
t = t + rx
141+
ry = t * i
150142
h3 = h3 * s1
151-
h3 = -h3
152143
ry = ry + h3
153144
return (constraints(), constraints(zero={a.Infinity : 'a_finite', b.Infinity : 'b_finite'}, nonzero={h : 'h!=0'}), jacobianpoint(rx, ry, rz))
154145

src/secp256k1/src/bench_internal.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,15 @@ void bench_group_add_affine_var(void* arg, int iters) {
254254
}
255255
}
256256

257+
void bench_group_add_zinv_var(void* arg, int iters) {
258+
int i;
259+
bench_inv *data = (bench_inv*)arg;
260+
261+
for (i = 0; i < iters; i++) {
262+
secp256k1_gej_add_zinv_var(&data->gej[0], &data->gej[0], &data->ge[1], &data->gej[0].y);
263+
}
264+
}
265+
257266
void bench_group_to_affine_var(void* arg, int iters) {
258267
int i;
259268
bench_inv *data = (bench_inv*)arg;
@@ -376,6 +385,7 @@ int main(int argc, char **argv) {
376385
if (d || have_flag(argc, argv, "group") || have_flag(argc, argv, "add")) run_benchmark("group_add_var", bench_group_add_var, bench_setup, NULL, &data, 10, iters*10);
377386
if (d || have_flag(argc, argv, "group") || have_flag(argc, argv, "add")) run_benchmark("group_add_affine", bench_group_add_affine, bench_setup, NULL, &data, 10, iters*10);
378387
if (d || have_flag(argc, argv, "group") || have_flag(argc, argv, "add")) run_benchmark("group_add_affine_var", bench_group_add_affine_var, bench_setup, NULL, &data, 10, iters*10);
388+
if (d || have_flag(argc, argv, "group") || have_flag(argc, argv, "add")) run_benchmark("group_add_zinv_var", bench_group_add_zinv_var, bench_setup, NULL, &data, 10, iters*10);
379389
if (d || have_flag(argc, argv, "group") || have_flag(argc, argv, "to_affine")) run_benchmark("group_to_affine_var", bench_group_to_affine_var, bench_setup, NULL, &data, 10, iters);
380390

381391
if (d || have_flag(argc, argv, "ecmult") || have_flag(argc, argv, "wnaf")) run_benchmark("wnaf_const", bench_wnaf_const, bench_setup, NULL, &data, 10, iters);

0 commit comments

Comments
 (0)