Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
Benjamin Allred
crown-core
Commits
6a5c024f
Commit
6a5c024f
authored
11 years ago
by
Pieter Wuille
Committed by
Pieter Wuille
11 years ago
Browse files
Options
Download
Email Patches
Plain Diff
Make signature cache store CPubKeys
parent
acc9a294
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/allocators.h
+4
-0
src/allocators.h
src/key.h
+3
-4
src/key.h
src/script.cpp
+12
-8
src/script.cpp
with
19 additions
and
12 deletions
+19
-12
src/allocators.h
View file @
6a5c024f
...
...
@@ -176,6 +176,10 @@ private:
{}
};
//
// Functions for directly locking/unlocking memory objects.
// Intended for non-dynamically allocated structures.
//
template
<
typename
T
>
void
LockObject
(
const
T
&
t
)
{
LockedPageManager
::
instance
.
LockRange
((
void
*
)(
&
t
),
sizeof
(
T
));
}
...
...
This diff is collapsed.
Click to expand it.
src/key.h
View file @
6a5c024f
...
...
@@ -84,7 +84,7 @@ public:
Set
(
vch
.
begin
(),
vch
.
end
());
}
// Simpl
y
read-only vector-like interface to the pubkey data.
// Simpl
e
read-only vector-like interface to the pubkey data.
unsigned
int
size
()
const
{
return
GetLen
(
vch
[
0
]);
}
const
unsigned
char
*
begin
()
const
{
return
vch
;
}
const
unsigned
char
*
end
()
const
{
return
vch
+
size
();
}
...
...
@@ -109,12 +109,11 @@ public:
}
template
<
typename
Stream
>
void
Serialize
(
Stream
&
s
,
int
nType
,
int
nVersion
)
const
{
unsigned
int
len
=
size
();
::
Serialize
(
s
,
VARINT
(
len
),
nType
,
nVersio
n
);
::
WriteCompactSize
(
s
,
le
n
);
s
.
write
((
char
*
)
vch
,
len
);
}
template
<
typename
Stream
>
void
Unserialize
(
Stream
&
s
,
int
nType
,
int
nVersion
)
{
unsigned
int
len
;
::
Unserialize
(
s
,
VARINT
(
len
),
nType
,
nVersion
);
unsigned
int
len
=
::
ReadCompactSize
(
s
);
if
(
len
<=
65
)
{
s
.
read
((
char
*
)
vch
,
len
);
}
else
{
...
...
This diff is collapsed.
Click to expand it.
src/script.cpp
View file @
6a5c024f
...
...
@@ -16,7 +16,7 @@ using namespace boost;
#include "sync.h"
#include "util.h"
bool
CheckSig
(
vector
<
unsigned
char
>
vchSig
,
vector
<
unsigned
char
>
vchPubKey
,
CScript
scriptCode
,
const
CTransaction
&
txTo
,
unsigned
int
nIn
,
int
nHashType
,
int
flags
);
bool
CheckSig
(
vector
<
unsigned
char
>
vchSig
,
const
vector
<
unsigned
char
>
&
vchPubKey
,
const
CScript
&
scriptCode
,
const
CTransaction
&
txTo
,
unsigned
int
nIn
,
int
nHashType
,
int
flags
);
...
...
@@ -1033,13 +1033,13 @@ class CSignatureCache
{
private:
// sigdata_type is (signature hash, signature, public key):
typedef
boost
::
tuple
<
uint256
,
std
::
vector
<
unsigned
char
>
,
std
::
vector
<
unsigned
char
>
>
sigdata_type
;
typedef
boost
::
tuple
<
uint256
,
std
::
vector
<
unsigned
char
>
,
CPubKey
>
sigdata_type
;
std
::
set
<
sigdata_type
>
setValid
;
boost
::
shared_mutex
cs_sigcache
;
public:
bool
Get
(
uint256
hash
,
const
std
::
vector
<
unsigned
char
>&
vchSig
,
const
std
::
vector
<
unsigned
char
>
&
pubKey
)
Get
(
const
uint256
&
hash
,
const
std
::
vector
<
unsigned
char
>&
vchSig
,
const
CPubKey
&
pubKey
)
{
boost
::
shared_lock
<
boost
::
shared_mutex
>
lock
(
cs_sigcache
);
...
...
@@ -1050,7 +1050,7 @@ public:
return
false
;
}
void
Set
(
uint256
hash
,
const
std
::
vector
<
unsigned
char
>&
vchSig
,
const
std
::
vector
<
unsigned
char
>
&
pubKey
)
void
Set
(
const
uint256
&
hash
,
const
std
::
vector
<
unsigned
char
>&
vchSig
,
const
CPubKey
&
pubKey
)
{
// DoS prevention: limit cache size to less than 10MB
// (~200 bytes per cache entry times 50,000 entries)
...
...
@@ -1081,11 +1081,15 @@ public:
}
};
bool
CheckSig
(
vector
<
unsigned
char
>
vchSig
,
vector
<
unsigned
char
>
vchPubKey
,
CScript
scriptCode
,
bool
CheckSig
(
vector
<
unsigned
char
>
vchSig
,
const
vector
<
unsigned
char
>
&
vchPubKey
,
const
CScript
&
scriptCode
,
const
CTransaction
&
txTo
,
unsigned
int
nIn
,
int
nHashType
,
int
flags
)
{
static
CSignatureCache
signatureCache
;
CPubKey
pubkey
(
vchPubKey
);
if
(
!
pubkey
.
IsValid
())
return
false
;
// Hash type is one byte tacked on to the end of the signature
if
(
vchSig
.
empty
())
return
false
;
...
...
@@ -1097,14 +1101,14 @@ bool CheckSig(vector<unsigned char> vchSig, vector<unsigned char> vchPubKey, CSc
uint256
sighash
=
SignatureHash
(
scriptCode
,
txTo
,
nIn
,
nHashType
);
if
(
signatureCache
.
Get
(
sighash
,
vchSig
,
vchP
ub
K
ey
))
if
(
signatureCache
.
Get
(
sighash
,
vchSig
,
p
ub
k
ey
))
return
true
;
if
(
!
CPubKey
(
vchP
ub
K
ey
)
.
Verify
(
sighash
,
vchSig
))
if
(
!
p
ub
k
ey
.
Verify
(
sighash
,
vchSig
))
return
false
;
if
(
!
(
flags
&
SCRIPT_VERIFY_NOCACHE
))
signatureCache
.
Set
(
sighash
,
vchSig
,
vchP
ub
K
ey
);
signatureCache
.
Set
(
sighash
,
vchSig
,
p
ub
k
ey
);
return
true
;
}
...
...
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment
Menu
Projects
Groups
Snippets
Help