Skip to content
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

Remove all identity-related code from celo-blockchain #572

Merged
merged 3 commits into from
Nov 11, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
112 changes: 0 additions & 112 deletions abe/abe.go

This file was deleted.

1 change: 0 additions & 1 deletion cmd/geth/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,6 @@ var (
utils.MinerLegacyExtraDataFlag,
utils.MinerRecommitIntervalFlag,
utils.MinerNoVerfiyFlag,
utils.MinerVerificationServiceUrlFlag,
utils.NATFlag,
utils.NoDiscoverFlag,
utils.DiscoveryV5Flag,
Expand Down
1 change: 0 additions & 1 deletion cmd/geth/usage.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,6 @@ var AppHelpFlagGroups = []flagGroup{
utils.MinerExtraDataFlag,
utils.MinerRecommitIntervalFlag,
utils.MinerNoVerfiyFlag,
utils.MinerVerificationServiceUrlFlag,
},
},
{
Expand Down
8 changes: 0 additions & 8 deletions cmd/utils/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -399,11 +399,6 @@ var (
Name: "miner.noverify",
Usage: "Disable remote sealing verification",
}
MinerVerificationServiceUrlFlag = cli.StringFlag{
Name: "miner.verificationpool",
Usage: "URL to the verification service to be used by the miner to attest users' phone numbers",
Value: eth.DefaultConfig.MinerVerificationServiceUrl,
}
// Account settings
UnlockedAccountFlag = cli.StringFlag{
Name: "unlock",
Expand Down Expand Up @@ -1306,9 +1301,6 @@ func SetEthConfig(ctx *cli.Context, stack *node.Node, cfg *eth.Config) {
if ctx.GlobalIsSet(MinerNoVerfiyFlag.Name) {
cfg.MinerNoverify = ctx.Bool(MinerNoVerfiyFlag.Name)
}
if ctx.GlobalIsSet(MinerVerificationServiceUrlFlag.Name) {
cfg.MinerVerificationServiceUrl = ctx.GlobalString(MinerVerificationServiceUrlFlag.Name)
}
if ctx.GlobalIsSet(VMEnableDebugFlag.Name) {
// TODO(fjl): force-enable this in --dev mode
cfg.EnablePreimageRecording = ctx.GlobalBool(VMEnableDebugFlag.Name)
Expand Down
1 change: 0 additions & 1 deletion core/state_processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,6 @@ func ApplyTransaction(config *params.ChainConfig, bc ChainContext, author *commo
if msg.To() == nil {
receipt.ContractAddress = crypto.CreateAddress(vmenv.Context.Origin, tx.Nonce())
}
receipt.AttestationRequests = vmenv.AttestationRequests
// Set the receipt logs and create a bloom for filtering
receipt.Logs = statedb.GetLogs(tx.Hash())
receipt.Bloom = types.CreateBloom(types.Receipts{receipt})
Expand Down
63 changes: 7 additions & 56 deletions core/types/receipt.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import (
"bytes"
"fmt"
"io"
"math/big"
"unsafe"

"github.com/ethereum/go-ethereum/common"
Expand All @@ -43,15 +42,6 @@ const (
ReceiptStatusSuccessful = uint64(1)
)

// AttestationRequest represents a request for verification in the Celo ABE protocol.
type AttestationRequest struct {
PhoneHash common.Hash
CodeHash common.Hash
Account common.Address
Verifier common.Address
EncryptedPhone hexutil.Bytes
}

// Receipt represents the results of a transaction.
type Receipt struct {
// Consensus fields
Expand All @@ -61,9 +51,6 @@ type Receipt struct {
Bloom Bloom `json:"logsBloom" gencodec:"required"`
Logs []*Log `json:"logs" gencodec:"required"`

// Celo fields
AttestationRequests []AttestationRequest

// Implementation fields (don't reorder!)
TxHash common.Hash `json:"transactionHash" gencodec:"required"`
ContractAddress common.Address `json:"contractAddress"`
Expand Down Expand Up @@ -93,9 +80,6 @@ type receiptStorageRLP struct {
ContractAddress common.Address
Logs []*LogForStorage
GasUsed uint64

// Celo fields
AttestationRequests []AttestationRequest
}

// NewReceipt creates a barebone transaction receipt, copying the init fields.
Expand All @@ -109,36 +93,6 @@ func NewReceipt(root []byte, failed bool, cumulativeGasUsed uint64) *Receipt {
return r
}

// Decode an AttestationRequest from raw input bytes.
// Input is expected to be encoded in the following manner:
// input[0:32]: bytes32 phoneHash
// input[32:64]: bytes32 codeHash
// input[64:96]: address account
// input[96:128]: address verifier
// input[128:160]: s - uint256 start of encryptedPhone data
// input[s:s+32]: l - length of encryptedPhoneData
// input[s+32:s+32+l]: bytes encryptedPhone
func DecodeAttestationRequest(input []byte) (AttestationRequest, error) {
var v AttestationRequest
v.PhoneHash = common.BytesToHash(input[0:32])
v.Account = common.BytesToAddress(input[64:96])
v.CodeHash = common.BytesToHash(input[32:64])
v.Verifier = common.BytesToAddress(input[96:128])

encodedEncryptedPhoneStart := big.NewInt(0)
encodedEncryptedPhoneLen := big.NewInt(0)

encodedEncryptedPhoneStart.SetBytes(input[128:160])
encryptedPhoneStart := encodedEncryptedPhoneStart.Uint64()

encodedEncryptedPhoneLen.SetBytes(input[encryptedPhoneStart:(encryptedPhoneStart + 32)])
encryptedPhoneLen := encodedEncryptedPhoneLen.Uint64()

// TODO(asa): Consider validating the length of EncryptedPhone
v.EncryptedPhone = input[(encryptedPhoneStart + 32):(encryptedPhoneStart + 32 + encryptedPhoneLen)]
return v, nil
}

// EncodeRLP implements rlp.Encoder, and flattens the consensus fields of a receipt
// into an RLP stream. If no post state is present, byzantium fork is assumed.
func (r *Receipt) EncodeRLP(w io.Writer) error {
Expand Down Expand Up @@ -203,14 +157,13 @@ type ReceiptForStorage Receipt
// into an RLP stream.
func (r *ReceiptForStorage) EncodeRLP(w io.Writer) error {
enc := &receiptStorageRLP{
PostStateOrStatus: (*Receipt)(r).statusEncoding(),
CumulativeGasUsed: r.CumulativeGasUsed,
Bloom: r.Bloom,
TxHash: r.TxHash,
ContractAddress: r.ContractAddress,
Logs: make([]*LogForStorage, len(r.Logs)),
GasUsed: r.GasUsed,
AttestationRequests: r.AttestationRequests,
PostStateOrStatus: (*Receipt)(r).statusEncoding(),
CumulativeGasUsed: r.CumulativeGasUsed,
Bloom: r.Bloom,
TxHash: r.TxHash,
ContractAddress: r.ContractAddress,
Logs: make([]*LogForStorage, len(r.Logs)),
GasUsed: r.GasUsed,
}
for i, log := range r.Logs {
enc.Logs[i] = (*LogForStorage)(log)
Expand Down Expand Up @@ -238,8 +191,6 @@ func (r *ReceiptForStorage) DecodeRLP(s *rlp.Stream) error {
// Assign the implementation fields
r.TxHash, r.ContractAddress, r.GasUsed = dec.TxHash, dec.ContractAddress, dec.GasUsed

// Assign the celo fields
r.AttestationRequests = dec.AttestationRequests
return nil
}

Expand Down
49 changes: 6 additions & 43 deletions core/vm/contracts.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ 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/core/types"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/crypto/bls"
"github.com/ethereum/go-ethereum/crypto/bn256"
Expand All @@ -53,7 +52,6 @@ var PrecompiledContractsHomestead = map[common.Address]PrecompiledContract{
}

var CeloPrecompiledContractsAddressOffset = byte(0xff)
var requestAttestationAddress = common.BytesToAddress(append([]byte{0}, CeloPrecompiledContractsAddressOffset))
var transferAddress = common.BytesToAddress(append([]byte{0}, (CeloPrecompiledContractsAddressOffset - 2)))
var fractionMulExpAddress = common.BytesToAddress(append([]byte{0}, (CeloPrecompiledContractsAddressOffset - 3)))
var proofOfPossessionAddress = common.BytesToAddress(append([]byte{0}, (CeloPrecompiledContractsAddressOffset - 4)))
Expand All @@ -74,13 +72,12 @@ var PrecompiledContractsByzantium = map[common.Address]PrecompiledContract{
common.BytesToAddress([]byte{8}): &bn256Pairing{},

// Celo Precompiled Contracts
requestAttestationAddress: &requestAttestation{},
transferAddress: &transfer{},
fractionMulExpAddress: &fractionMulExp{},
proofOfPossessionAddress: &proofOfPossession{},
getValidatorAddress: &getValidator{},
numberValidatorsAddress: &numberValidators{},
epochSizeAddress: &epochSize{},
transferAddress: &transfer{},
fractionMulExpAddress: &fractionMulExp{},
proofOfPossessionAddress: &proofOfPossession{},
getValidatorAddress: &getValidator{},
numberValidatorsAddress: &numberValidators{},
epochSizeAddress: &epochSize{},
}

// RunPrecompiledContract runs and evaluates the output of a precompiled contract.
Expand Down Expand Up @@ -431,40 +428,6 @@ func (c *bn256Pairing) Run(input []byte, caller common.Address, evm *EVM, gas ui
return false32Byte, gas, nil
}

// Requesting attestation in the Celo address based encryption protocol is implemented as a
// native contract.
type requestAttestation struct{}

func (c *requestAttestation) RequiredGas(input []byte) uint64 {
// TODO(asa): Charge less gas when the phone number is invalid.
return params.AttestationRequestGas
}

// Ensures that the input is parsable as a AttestationRequest.
func (c *requestAttestation) Run(input []byte, caller common.Address, evm *EVM, gas uint64) ([]byte, uint64, error) {
gas, err := debitRequiredGas(c, input, gas)
if err != nil {
return nil, gas, err
}

abeAddress, err := GetRegisteredAddressWithEvm(params.AttestationsRegistryId, evm)

if err != nil {
return nil, gas, err
}

if caller != *abeAddress {
return nil, gas, fmt.Errorf("Unable to call requestAttestation from unpermissioned address")
}
_, err = types.DecodeAttestationRequest(input)
if err != nil {
log.Error("[Celo] Unable to decode verification request", "err", err)
return nil, gas, err
} else {
return input, gas, nil
}
}

// Native transfer contract to make Celo Gold ERC20 compatible.
type transfer struct{}

Expand Down
3 changes: 0 additions & 3 deletions core/vm/evm.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,9 +140,6 @@ type EVM struct {
// available gas is calculated in gasCall* according to the 63/64 rule and later
// applied in opCall*.
callGasTemp uint64
// Maintains a queue of Celo attestation requests
// TODO(asa): Save this in StateDB
AttestationRequests []types.AttestationRequest

DontMeterGas bool
}
Expand Down
7 changes: 1 addition & 6 deletions core/vm/instructions.go
Original file line number Diff line number Diff line change
Expand Up @@ -765,12 +765,7 @@ func opCall(pc *uint64, interpreter *EVMInterpreter, contract *Contract, memory
gas += params.CallStipend
}
ret, returnGas, err := interpreter.evm.Call(contract, toAddr, args, gas, value)
// TODO(asa): Consider passing the EVM to RunPrecompiledContract instead.
if toAddr == requestAttestationAddress && err == nil {
// This should never return an error as we would have returned an error in Call.
request, _ := types.DecodeAttestationRequest(ret)
interpreter.evm.AttestationRequests = append(interpreter.evm.AttestationRequests, request)
}

if err != nil {
stack.push(interpreter.intPool.getZero())
} else {
Expand Down
2 changes: 1 addition & 1 deletion eth/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ func New(ctx *node.ServiceContext, config *Config) (*Ethereum, error) {
istanbul.SetChain(eth.blockchain, eth.blockchain.CurrentBlock)
}

eth.miner = miner.New(eth, eth.chainConfig, eth.EventMux(), eth.engine, config.MinerRecommit, config.MinerGasFloor, config.MinerGasCeil, eth.isLocalBlock, config.MinerVerificationServiceUrl, &chainDb)
eth.miner = miner.New(eth, eth.chainConfig, eth.EventMux(), eth.engine, config.MinerRecommit, config.MinerGasFloor, config.MinerGasCeil, eth.isLocalBlock, &chainDb)
eth.miner.SetExtra(makeExtraData(config.MinerExtraData))

eth.APIBackend = &EthAPIBackend{eth}
Expand Down
Loading