-
Notifications
You must be signed in to change notification settings - Fork 20.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
clef: make external signing work + follow up fixes #19003
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
947405e
signer/clef: make use of json-rpc notification
holiman 656b165
signer: tidy up output of OnApprovedTx
holiman af32f63
accounts/external, signer: implement remote signing of text, make acc…
holiman dfeb434
clef: added basic testscript
holiman 73e013f
signer, external, api: add clique signing test to debug rpc, fix cliq…
holiman 65ab280
signer: fix clique interoperability between geth and clef
holiman b248bc9
clef: rename networkid switch to chainid
holiman 9b7ab97
clef: enable chainid flag
holiman 1b84db0
clef, signer: minor changes from review
holiman a9e2b0f
clef: more tests for signer
holiman File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
// This file is a test-utility for testing clef-functionality | ||
// | ||
// Start clef with | ||
// | ||
// build/bin/clef --4bytedb=./cmd/clef/4byte.json --rpc | ||
// | ||
// Start geth with | ||
// | ||
// build/bin/geth --nodiscover --maxpeers 0 --signer http://localhost:8550 console --preload=cmd/clef/tests/testsigner.js | ||
// | ||
// and in the console simply invoke | ||
// | ||
// > test() | ||
// | ||
// You can reload the file via `reload()` | ||
|
||
function reload(){ | ||
loadScript("./cmd/clef/tests/testsigner.js"); | ||
} | ||
|
||
function init(){ | ||
if (typeof accts == 'undefined' || accts.length == 0){ | ||
accts = eth.accounts | ||
console.log("Got accounts ", accts); | ||
} | ||
} | ||
init() | ||
function testTx(){ | ||
if( accts && accts.length > 0) { | ||
var a = accts[0] | ||
var txdata = eth.signTransaction({from: a, to: a, value: 1, nonce: 1, gas: 1, gasPrice: 1}) | ||
var v = parseInt(txdata.tx.v) | ||
console.log("V value: ", v) | ||
if (v == 37 || v == 38){ | ||
console.log("Mainnet 155-protected chainid was used") | ||
} | ||
if (v == 27 || v == 28){ | ||
throw new Error("Mainnet chainid was used, but without replay protection!") | ||
} | ||
} | ||
} | ||
function testSignText(){ | ||
if( accts && accts.length > 0){ | ||
var a = accts[0] | ||
var r = eth.sign(a, "0x68656c6c6f20776f726c64"); //hello world | ||
console.log("signing response", r) | ||
} | ||
} | ||
function testClique(){ | ||
if( accts && accts.length > 0){ | ||
var a = accts[0] | ||
var r = debug.testSignCliqueBlock(a, 0); // Sign genesis | ||
console.log("signing response", r) | ||
if( a != r){ | ||
throw new Error("Requested signing by "+a+ " but got sealer "+r) | ||
} | ||
} | ||
} | ||
|
||
function test(){ | ||
var tests = [ | ||
testTx, | ||
testSignText, | ||
testClique, | ||
] | ||
for( i in tests){ | ||
try{ | ||
tests[i]() | ||
}catch(err){ | ||
console.log(err) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,6 +31,7 @@ import ( | |
"github.com/ethereum/go-ethereum/common" | ||
"github.com/ethereum/go-ethereum/common/hexutil" | ||
"github.com/ethereum/go-ethereum/common/math" | ||
"github.com/ethereum/go-ethereum/consensus/clique" | ||
"github.com/ethereum/go-ethereum/consensus/ethash" | ||
"github.com/ethereum/go-ethereum/core" | ||
"github.com/ethereum/go-ethereum/core/rawdb" | ||
|
@@ -1481,6 +1482,45 @@ func (api *PublicDebugAPI) GetBlockRlp(ctx context.Context, number uint64) (stri | |
return fmt.Sprintf("%x", encoded), nil | ||
} | ||
|
||
// TestSignCliqueBlock fetches the given block number, and attempts to sign it as a clique header with the | ||
// given address, returning the address of the recovered signature | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Reminder: Peter said that this should be noted as TODO/to remove |
||
// | ||
// This is a temporary method to debug the externalsigner integration, | ||
// TODO: Remove this method when the integration is mature | ||
func (api *PublicDebugAPI) TestSignCliqueBlock(ctx context.Context, address common.Address, number uint64) (common.Address, error) { | ||
block, _ := api.b.BlockByNumber(ctx, rpc.BlockNumber(number)) | ||
if block == nil { | ||
return common.Address{}, fmt.Errorf("block #%d not found", number) | ||
} | ||
header := block.Header() | ||
header.Extra = make([]byte, 32+65) | ||
encoded := clique.CliqueRLP(header) | ||
|
||
// Look up the wallet containing the requested signer | ||
account := accounts.Account{Address: address} | ||
wallet, err := api.b.AccountManager().Find(account) | ||
if err != nil { | ||
return common.Address{}, err | ||
} | ||
|
||
signature, err := wallet.SignData(account, accounts.MimetypeClique, encoded) | ||
if err != nil { | ||
return common.Address{}, err | ||
} | ||
sealHash := clique.SealHash(header).Bytes() | ||
log.Info("test signing of clique block", | ||
"Sealhash", fmt.Sprintf("%x", sealHash), | ||
"signature", fmt.Sprintf("%x", signature)) | ||
pubkey, err := crypto.Ecrecover(sealHash, signature) | ||
if err != nil { | ||
return common.Address{}, err | ||
} | ||
var signer common.Address | ||
copy(signer[:], crypto.Keccak256(pubkey[1:])[12:]) | ||
|
||
return signer, nil | ||
} | ||
|
||
// PrintBlock retrieves a block and returns its pretty printed form. | ||
func (api *PublicDebugAPI) PrintBlock(ctx context.Context, number uint64) (string, error) { | ||
block, _ := api.b.BlockByNumber(ctx, rpc.BlockNumber(number)) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could we also have tests to check the error conditions?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are there any particular error conditions you're thinking of?
I mean, there are quite a lot of ways for signing to fail. This js-test is meant as an integration test, to test the whole geth-external-ui and back again flow.
It's not for CI, but for a dev to run manually to test things more easily.
Individual tests within signer/clef should test things like rejection and tx validation etc.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm thinking of the 27/28 vs 0/1 in particular.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, added for transactions. For clique, the new debug endpoint will deliver the derived signer. And if the wrong v-type is used, it will derive another address as sealer of that block.
So the js-test already checks that the requested signer-address equals what the endpoint returns, thus checks that the geth and clef are in agreement (without explicitly checking
v
)