Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
O
openzeppelin-contracts-upgradeable
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
俞永鹏
openzeppelin-contracts-upgradeable
Commits
635c0437
Commit
635c0437
authored
Jun 15, 2017
by
Augusto
Committed by
Francisco Giordano
Jul 18, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Removed ECRecovery mock contract, ECRecovery funcions are public constants
parent
227c7aae
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
16 additions
and
38 deletions
+16
-38
ECRecovery.sol
contracts/ECRecovery.sol
+2
-2
ECRecovery.js
test/ECRecovery.js
+14
-16
ECRecoveryMock.sol
test/helpers/ECRecoveryMock.sol
+0
-20
No files found.
contracts/ECRecovery.sol
View file @
635c0437
...
@@ -8,7 +8,7 @@ pragma solidity ^0.4.11;
...
@@ -8,7 +8,7 @@ pragma solidity ^0.4.11;
library ECRecovery {
library ECRecovery {
// Duplicate Solidity's ecrecover, but catching the CALL return value
// Duplicate Solidity's ecrecover, but catching the CALL return value
function safeRecover(bytes32 hash, uint8 v, bytes32 r, bytes32 s)
internal
returns (bool, address) {
function safeRecover(bytes32 hash, uint8 v, bytes32 r, bytes32 s)
constant
returns (bool, address) {
// We do our own memory management here. Solidity uses memory offset
// We do our own memory management here. Solidity uses memory offset
// 0x40 to store the current end of memory. We write past it (as
// 0x40 to store the current end of memory. We write past it (as
// writes are memory extensions), but don't update the offset so
// writes are memory extensions), but don't update the offset so
...
@@ -34,7 +34,7 @@ library ECRecovery {
...
@@ -34,7 +34,7 @@ library ECRecovery {
return (ret, addr);
return (ret, addr);
}
}
function recover(bytes32 hash, bytes sig)
internal
returns (address) {
function recover(bytes32 hash, bytes sig)
constant
returns (address) {
bytes32 r;
bytes32 r;
bytes32 s;
bytes32 s;
uint8 v;
uint8 v;
...
...
test/ECRecovery.js
View file @
635c0437
var
ECRecovery
Mock
=
artifacts
.
require
(
"./helpers/ECRecoveryMock
.sol"
);
var
ECRecovery
=
artifacts
.
require
(
"../contracts/ECRecovery
.sol"
);
contract
(
'ECRecovery'
,
function
(
accounts
)
{
contract
(
'ECRecovery'
,
function
(
accounts
)
{
let
ecrecovery
;
let
ecrecovery
;
before
(
async
function
()
{
before
(
async
function
()
{
ecrecovery
=
await
ECRecovery
Mock
.
new
();
ecrecovery
=
await
ECRecovery
.
new
();
});
});
it
(
"recover v0"
,
async
function
()
{
it
.
only
(
"recover v0"
,
async
function
()
{
let
signer
=
'0x2cc1166f6212628a0deef2b33befb2187d35b86c'
;
let
signer
=
'0x2cc1166f6212628a0deef2b33befb2187d35b86c'
;
let
message
=
'0x7dbaf558b0a1a5dc7a67202117ab143c1d8605a983e4a743bc06fcc03162dc0d'
;
// web3.sha3('OpenZeppelin')
let
message
=
'0x7dbaf558b0a1a5dc7a67202117ab143c1d8605a983e4a743bc06fcc03162dc0d'
;
// web3.sha3('OpenZeppelin')
let
signature
=
'0x5d99b6f7f6d1f73d1a26497f2b1c89b24c0993913f86e9a2d02cd69887d9c94f3c880358579d811b21dd1b7fd9bb01c1d81d10e69f0384e675c32b39643be89200'
;
let
signature
=
'0x5d99b6f7f6d1f73d1a26497f2b1c89b24c0993913f86e9a2d02cd69887d9c94f3c880358579d811b21dd1b7fd9bb01c1d81d10e69f0384e675c32b39643be89200'
;
await
ecrecovery
.
recover
(
message
,
signature
);
assert
.
equal
(
signer
,
await
ecrecovery
.
recover
(
message
,
signature
));
assert
.
equal
(
signer
,
await
ecrecovery
.
signer
());
});
});
it
(
"recover v1"
,
async
function
()
{
it
.
only
(
"recover v1"
,
async
function
()
{
let
signer
=
'0x1e318623ab09fe6de3c9b8672098464aeda9100e'
;
let
signer
=
'0x1e318623ab09fe6de3c9b8672098464aeda9100e'
;
let
message
=
'0x7dbaf558b0a1a5dc7a67202117ab143c1d8605a983e4a743bc06fcc03162dc0d'
;
// web3.sha3('OpenZeppelin')
let
message
=
'0x7dbaf558b0a1a5dc7a67202117ab143c1d8605a983e4a743bc06fcc03162dc0d'
;
// web3.sha3('OpenZeppelin')
let
signature
=
'0x331fe75a821c982f9127538858900d87d3ec1f9f737338ad67cad133fa48feff48e6fa0c18abc62e42820f05943e47af3e9fbe306ce74d64094bdf1691ee53e001'
;
let
signature
=
'0x331fe75a821c982f9127538858900d87d3ec1f9f737338ad67cad133fa48feff48e6fa0c18abc62e42820f05943e47af3e9fbe306ce74d64094bdf1691ee53e001'
;
await
ecrecovery
.
recover
(
message
,
signature
);
assert
.
equal
(
signer
,
await
ecrecovery
.
recover
(
message
,
signature
));
assert
.
equal
(
signer
,
await
ecrecovery
.
signer
());
});
});
it
(
"safeRecover v0"
,
async
function
()
{
it
.
only
(
"safeRecover v0"
,
async
function
()
{
let
signer
=
'0x58d5f9f841bcf9e502b438cc81d1ea3ba3f8f7f3'
;
let
signer
=
'0x58d5f9f841bcf9e502b438cc81d1ea3ba3f8f7f3'
;
let
message
=
'0x7dbaf558b0a1a5dc7a67202117ab143c1d8605a983e4a743bc06fcc03162dc0d'
;
// web3.sha3('OpenZeppelin')
let
message
=
'0x7dbaf558b0a1a5dc7a67202117ab143c1d8605a983e4a743bc06fcc03162dc0d'
;
// web3.sha3('OpenZeppelin')
let
signature
=
'3690f285f30200dfacd35b9ee9af4beaf2c2f4b7880d93dd9bdf776e8fdbec6a095d00c80e20e95a68c8effc038707dd740aabf94a6ca37c09733874f772d6e000'
;
let
signature
=
'3690f285f30200dfacd35b9ee9af4beaf2c2f4b7880d93dd9bdf776e8fdbec6a095d00c80e20e95a68c8effc038707dd740aabf94a6ca37c09733874f772d6e000'
;
let
v
=
(
signature
.
substring
(
128
,
130
)
==
'01'
)
?
28
:
27
;
let
v
=
(
signature
.
substring
(
128
,
130
)
==
'01'
)
?
28
:
27
;
let
r
=
'0x'
+
signature
.
substring
(
0
,
64
);
let
r
=
'0x'
+
signature
.
substring
(
0
,
64
);
let
s
=
'0x'
+
signature
.
substring
(
64
,
128
);
let
s
=
'0x'
+
signature
.
substring
(
64
,
128
);
await
ecrecovery
.
safeRecover
(
message
,
v
,
r
,
s
);
let
result
=
await
ecrecovery
.
safeRecover
(
message
,
v
,
r
,
s
);
assert
.
equal
(
signer
,
await
ecrecovery
.
signer
()
);
assert
.
equal
(
signer
,
result
[
1
]
);
assert
.
equal
(
true
,
await
ecrecovery
.
result
()
);
assert
.
equal
(
true
,
result
[
0
]
);
});
});
it
(
"safeRecover v1"
,
async
function
()
{
it
.
only
(
"safeRecover v1"
,
async
function
()
{
let
signer
=
'0x0b8124c2429c44e8ca31e7db6f85845abf146415'
;
let
signer
=
'0x0b8124c2429c44e8ca31e7db6f85845abf146415'
;
let
message
=
'0x7dbaf558b0a1a5dc7a67202117ab143c1d8605a983e4a743bc06fcc03162dc0d'
;
// web3.sha3('OpenZeppelin')
let
message
=
'0x7dbaf558b0a1a5dc7a67202117ab143c1d8605a983e4a743bc06fcc03162dc0d'
;
// web3.sha3('OpenZeppelin')
let
signature
=
'7696f87b3f14e2f1c408c552c0005479bfe35df3a9efb493a2ad2bdf25d95c8c605b6f83699faca9bcbc3c665b434ed8d9c717aa71a1916f054fc41671dd38ad01'
;
let
signature
=
'7696f87b3f14e2f1c408c552c0005479bfe35df3a9efb493a2ad2bdf25d95c8c605b6f83699faca9bcbc3c665b434ed8d9c717aa71a1916f054fc41671dd38ad01'
;
let
v
=
(
signature
.
substring
(
128
,
130
)
==
'01'
)
?
28
:
27
;
let
v
=
(
signature
.
substring
(
128
,
130
)
==
'01'
)
?
28
:
27
;
let
r
=
'0x'
+
signature
.
substring
(
0
,
64
);
let
r
=
'0x'
+
signature
.
substring
(
0
,
64
);
let
s
=
'0x'
+
signature
.
substring
(
64
,
128
);
let
s
=
'0x'
+
signature
.
substring
(
64
,
128
);
await
ecrecovery
.
safeRecover
(
message
,
v
,
r
,
s
);
let
result
=
await
ecrecovery
.
safeRecover
(
message
,
v
,
r
,
s
);
assert
.
equal
(
signer
,
await
ecrecovery
.
signer
()
);
assert
.
equal
(
signer
,
result
[
1
]
);
assert
.
equal
(
true
,
await
ecrecovery
.
result
()
);
assert
.
equal
(
true
,
result
[
0
]
);
});
});
});
});
test/helpers/ECRecoveryMock.sol
deleted
100644 → 0
View file @
227c7aae
pragma solidity ^0.4.11;
import '../../contracts/ECRecovery.sol';
contract ECRecoveryMock {
bool public result;
address public signer;
function safeRecover(bytes32 hash, uint8 v, bytes32 r, bytes32 s) {
(result, signer) = ECRecovery.safeRecover(hash, v, r, s);
}
function recover(bytes32 hash, bytes sig) {
signer = ECRecovery.recover(hash, sig);
}
}
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