Skip to content

Commit

Permalink
eth-sign like signature hash (ethereum#15)
Browse files Browse the repository at this point in the history
* eth-sign: initial implementation

* sighash: pre-refactor

* sighash: refactor, all old tests pass

* sighash: test ovmsigner code paths for eip155 and eth_sign

* sighash: tx serialization tests

* sighash: refactor to sign bytes

* common/varbytes: use varbytes serialization from btcd

* transactionmeta: implement and test

* rawdb: add new index

* types/transaction: use txmeta

* blockchain: index tx meta on new block

* rpc: fix sendrawethsigntransaction docstring

* meta test: remove dead code

* ethapi: clean up comment

* lint: fix

* txmeta: clean up compares

* ethapi: remove rlp tag

* signer: remove rlp encoding tags from struct

* types: use factory pattern for getting sighash type

* sighash: migrate to using const

* tx pool: use ovmsigner for tx validation

* tx signing: fix eth_sign serialization

* sighash: new version

* sighash: commit to chainid

* sighash: bugfixes

* core/types: prevent panic on tx sort

* core/types: rename to transaction_meta

* core/blockchain: index txmeta

* sighash: no native value

* ethapi: use ovm signer

* sighash: move chainid
  • Loading branch information
tynes committed Sep 13, 2020
1 parent 538ddf8 commit 680b4f8
Show file tree
Hide file tree
Showing 45 changed files with 1,270 additions and 304 deletions.
16 changes: 8 additions & 8 deletions accounts/abi/bind/backends/simulated_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ func TestSimulatedBackend_NonceAt(t *testing.T) {
}

// create a signed transaction to send
tx := types.NewTransaction(nonce, testAddr, big.NewInt(1000), params.TxGas, big.NewInt(1), nil, nil, nil)
tx := types.NewTransaction(nonce, testAddr, big.NewInt(1000), params.TxGas, big.NewInt(1), nil, nil, nil, types.SighashEIP155)
signedTx, err := types.SignTx(tx, types.HomesteadSigner{}, testKey)
if err != nil {
t.Errorf("could not sign tx: %v", err)
Expand Down Expand Up @@ -281,7 +281,7 @@ func TestSimulatedBackend_SendTransaction(t *testing.T) {
bgCtx := context.Background()

// create a signed transaction to send
tx := types.NewTransaction(uint64(0), testAddr, big.NewInt(1000), params.TxGas, big.NewInt(1), nil, nil, nil)
tx := types.NewTransaction(uint64(0), testAddr, big.NewInt(1000), params.TxGas, big.NewInt(1), nil, nil, nil, types.SighashEIP155)
signedTx, err := types.SignTx(tx, types.HomesteadSigner{}, testKey)
if err != nil {
t.Errorf("could not sign tx: %v", err)
Expand Down Expand Up @@ -316,7 +316,7 @@ func TestSimulatedBackend_TransactionByHash(t *testing.T) {
bgCtx := context.Background()

// create a signed transaction to send
tx := types.NewTransaction(uint64(0), testAddr, big.NewInt(1000), params.TxGas, big.NewInt(1), nil, nil, nil)
tx := types.NewTransaction(uint64(0), testAddr, big.NewInt(1000), params.TxGas, big.NewInt(1), nil, nil, nil, types.SighashEIP155)
signedTx, err := types.SignTx(tx, types.HomesteadSigner{}, testKey)
if err != nil {
t.Errorf("could not sign tx: %v", err)
Expand Down Expand Up @@ -481,7 +481,7 @@ func TestSimulatedBackend_TransactionCount(t *testing.T) {
}

// create a signed transaction to send
tx := types.NewTransaction(uint64(0), testAddr, big.NewInt(1000), params.TxGas, big.NewInt(1), nil, nil, nil)
tx := types.NewTransaction(uint64(0), testAddr, big.NewInt(1000), params.TxGas, big.NewInt(1), nil, nil, nil, types.SighashEIP155)
signedTx, err := types.SignTx(tx, types.HomesteadSigner{}, testKey)
if err != nil {
t.Errorf("could not sign tx: %v", err)
Expand Down Expand Up @@ -540,7 +540,7 @@ func TestSimulatedBackend_TransactionInBlock(t *testing.T) {
}

// create a signed transaction to send
tx := types.NewTransaction(uint64(0), testAddr, big.NewInt(1000), params.TxGas, big.NewInt(1), nil, nil, nil)
tx := types.NewTransaction(uint64(0), testAddr, big.NewInt(1000), params.TxGas, big.NewInt(1), nil, nil, nil, types.SighashEIP155)
signedTx, err := types.SignTx(tx, types.HomesteadSigner{}, testKey)
if err != nil {
t.Errorf("could not sign tx: %v", err)
Expand Down Expand Up @@ -599,7 +599,7 @@ func TestSimulatedBackend_PendingNonceAt(t *testing.T) {
}

// create a signed transaction to send
tx := types.NewTransaction(uint64(0), testAddr, big.NewInt(1000), params.TxGas, big.NewInt(1), nil, nil, nil)
tx := types.NewTransaction(uint64(0), testAddr, big.NewInt(1000), params.TxGas, big.NewInt(1), nil, nil, nil, types.SighashEIP155)
signedTx, err := types.SignTx(tx, types.HomesteadSigner{}, testKey)
if err != nil {
t.Errorf("could not sign tx: %v", err)
Expand All @@ -622,7 +622,7 @@ func TestSimulatedBackend_PendingNonceAt(t *testing.T) {
}

// make a new transaction with a nonce of 1
tx = types.NewTransaction(uint64(1), testAddr, big.NewInt(1000), params.TxGas, big.NewInt(1), nil, nil, nil)
tx = types.NewTransaction(uint64(1), testAddr, big.NewInt(1000), params.TxGas, big.NewInt(1), nil, nil, nil, types.SighashEIP155)
signedTx, err = types.SignTx(tx, types.HomesteadSigner{}, testKey)
if err != nil {
t.Errorf("could not sign tx: %v", err)
Expand Down Expand Up @@ -655,7 +655,7 @@ func TestSimulatedBackend_TransactionReceipt(t *testing.T) {
bgCtx := context.Background()

// create a signed transaction to send
tx := types.NewTransaction(uint64(0), testAddr, big.NewInt(1000), params.TxGas, big.NewInt(1), nil, nil, nil)
tx := types.NewTransaction(uint64(0), testAddr, big.NewInt(1000), params.TxGas, big.NewInt(1), nil, nil, nil, types.SighashEIP155)
signedTx, err := types.SignTx(tx, types.HomesteadSigner{}, testKey)
if err != nil {
t.Errorf("could not sign tx: %v", err)
Expand Down
2 changes: 1 addition & 1 deletion accounts/abi/bind/base.go
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ func (c *BoundContract) transact(opts *TransactOpts, contract *common.Address, i
if contract == nil {
rawTx = types.NewContractCreation(nonce, value, gasLimit, gasPrice, input, nil, nil)
} else {
rawTx = types.NewTransaction(nonce, c.address, value, gasLimit, gasPrice, input, nil, nil)
rawTx = types.NewTransaction(nonce, c.address, value, gasLimit, gasPrice, input, nil, nil, types.SighashEIP155)
}
if opts.Signer == nil {
return nil, errors.New("no signer to authorize the transaction with")
Expand Down
2 changes: 1 addition & 1 deletion cmd/faucet/faucet.go
Original file line number Diff line number Diff line change
Expand Up @@ -490,7 +490,7 @@ func (f *faucet) apiHandler(w http.ResponseWriter, r *http.Request) {
amount = new(big.Int).Mul(amount, new(big.Int).Exp(big.NewInt(5), big.NewInt(int64(msg.Tier)), nil))
amount = new(big.Int).Div(amount, new(big.Int).Exp(big.NewInt(2), big.NewInt(int64(msg.Tier)), nil))

tx := types.NewTransaction(f.nonce+uint64(len(f.reqs)), address, amount, 21000, f.price, nil, nil, nil)
tx := types.NewTransaction(f.nonce+uint64(len(f.reqs)), address, amount, 21000, f.price, nil, nil, nil, types.SighashEIP155)
signed, err := f.keystore.SignTx(f.account, tx, f.config.ChainID)
if err != nil {
f.lock.Unlock()
Expand Down
Loading

0 comments on commit 680b4f8

Please sign in to comment.