From dffb2e491c8d1f609d038ab2be19df30c328ebd8 Mon Sep 17 00:00:00 2001 From: ChenYe Date: Wed, 23 Oct 2024 09:13:06 +0800 Subject: [PATCH 1/3] v0.5 --- aggregator/aggregator.go | 10 ++- aggregator/client.go | 7 +- .../TEELivenessVerifier.go | 64 ++++++++++++++++++- .../script/DeployTEELivenessService.s.sol | 2 + contracts/src/core/TEELivenessVerifier.sol | 22 +++++-- operator/operator.go | 14 ++-- scripts/attestation.sh | 4 +- xtask/prover_client.go | 11 ++-- xtask/task_manager.go | 13 ++-- 9 files changed, 119 insertions(+), 28 deletions(-) diff --git a/aggregator/aggregator.go b/aggregator/aggregator.go index d640711..5adc019 100644 --- a/aggregator/aggregator.go +++ b/aggregator/aggregator.go @@ -80,6 +80,8 @@ type Config struct { GenTaskSampling uint64 ExecTaskSampling uint64 + LineaMaxBlock int64 + OpenTelemetry *xmetric.OpenTelemetryConfig TaskFetcher []*xtask.TaskManagerConfig @@ -91,6 +93,9 @@ func (cfg *Config) Init() error { if cfg.Sampling == 0 { cfg.Sampling = 2000 } + if cfg.LineaMaxBlock == 0 { + cfg.LineaMaxBlock = 100 + } if cfg.ExecTaskSampling == 0 { cfg.ExecTaskSampling = cfg.Sampling } @@ -179,7 +184,7 @@ func NewAggregator(ctx context.Context, cfg *Config) (*Aggregator, error) { collector := xmetric.NewAggregatorCollector("avs") - taskManager, err := xtask.NewTaskManager(collector, int64(cfg.GenTaskSampling), eigenClients.EthHttpClient, cfg.TaskFetcher) + taskManager, err := xtask.NewTaskManager(collector, int64(cfg.GenTaskSampling), cfg.LineaMaxBlock, eigenClients.EthHttpClient, cfg.TaskFetcher) if err != nil { return nil, logex.Trace(err) } @@ -264,12 +269,13 @@ func (agg *Aggregator) startUpdateOperators(ctx context.Context) (func() error, } func (agg *Aggregator) verifyKey(x [32]byte, y [32]byte) (bool, error) { - for _, layer := range agg.attestationLayer { + for idx, layer := range agg.attestationLayer { pass, err := layer.caller.VerifyLivenessProof(nil, x, y) if err != nil { return false, logex.Trace(err, "v1") } if pass { + logex.Info("pass attestation check in", idx) return true, nil } } diff --git a/aggregator/client.go b/aggregator/client.go index aa11f54..a696172 100644 --- a/aggregator/client.go +++ b/aggregator/client.go @@ -34,9 +34,10 @@ type Metadata struct { } type TaskRequest struct { - Task *StateHeader - Signature *bls.Signature - OperatorId types.OperatorId + Task *StateHeader + Signature *bls.Signature + OperatorId types.OperatorId + ProverSignature hexutil.Bytes } type StateHeader struct { diff --git a/contracts/bindings/TEELivenessVerifier/TEELivenessVerifier.go b/contracts/bindings/TEELivenessVerifier/TEELivenessVerifier.go index 3c7277a..285ffff 100644 --- a/contracts/bindings/TEELivenessVerifier/TEELivenessVerifier.go +++ b/contracts/bindings/TEELivenessVerifier/TEELivenessVerifier.go @@ -45,7 +45,7 @@ type TEELivenessVerifierReportDataV2 struct { // TEELivenessVerifierMetaData contains all meta data concerning the TEELivenessVerifier contract. var TEELivenessVerifierMetaData = &bind.MetaData{ - ABI: "[{\"type\":\"constructor\",\"inputs\":[],\"stateMutability\":\"nonpayable\"},{\"type\":\"function\",\"name\":\"attestValiditySeconds\",\"inputs\":[],\"outputs\":[{\"name\":\"\",\"type\":\"uint256\",\"internalType\":\"uint256\"}],\"stateMutability\":\"view\"},{\"type\":\"function\",\"name\":\"attestedProvers\",\"inputs\":[{\"name\":\"\",\"type\":\"bytes32\",\"internalType\":\"bytes32\"}],\"outputs\":[{\"name\":\"pubkey\",\"type\":\"tuple\",\"internalType\":\"structTEELivenessVerifier.Pubkey\",\"components\":[{\"name\":\"x\",\"type\":\"bytes32\",\"internalType\":\"bytes32\"},{\"name\":\"y\",\"type\":\"bytes32\",\"internalType\":\"bytes32\"}]},{\"name\":\"time\",\"type\":\"uint256\",\"internalType\":\"uint256\"}],\"stateMutability\":\"view\"},{\"type\":\"function\",\"name\":\"attestedReports\",\"inputs\":[{\"name\":\"\",\"type\":\"bytes32\",\"internalType\":\"bytes32\"}],\"outputs\":[{\"name\":\"\",\"type\":\"bool\",\"internalType\":\"bool\"}],\"stateMutability\":\"view\"},{\"type\":\"function\",\"name\":\"changeAttestValiditySeconds\",\"inputs\":[{\"name\":\"val\",\"type\":\"uint256\",\"internalType\":\"uint256\"}],\"outputs\":[],\"stateMutability\":\"nonpayable\"},{\"type\":\"function\",\"name\":\"changeAttestationImpl\",\"inputs\":[{\"name\":\"_attestationAddr\",\"type\":\"address\",\"internalType\":\"address\"}],\"outputs\":[],\"stateMutability\":\"nonpayable\"},{\"type\":\"function\",\"name\":\"changeMaxBlockNumberDiff\",\"inputs\":[{\"name\":\"_maxBlockNumberDiff\",\"type\":\"uint256\",\"internalType\":\"uint256\"}],\"outputs\":[],\"stateMutability\":\"nonpayable\"},{\"type\":\"function\",\"name\":\"dcapAttestation\",\"inputs\":[],\"outputs\":[{\"name\":\"\",\"type\":\"address\",\"internalType\":\"contractIAttestation\"}],\"stateMutability\":\"view\"},{\"type\":\"function\",\"name\":\"initialize\",\"inputs\":[{\"name\":\"_initialOwner\",\"type\":\"address\",\"internalType\":\"address\"},{\"name\":\"_attestationAddr\",\"type\":\"address\",\"internalType\":\"address\"},{\"name\":\"_maxBlockNumberDiff\",\"type\":\"uint256\",\"internalType\":\"uint256\"},{\"name\":\"_attestValiditySeconds\",\"type\":\"uint256\",\"internalType\":\"uint256\"}],\"outputs\":[],\"stateMutability\":\"nonpayable\"},{\"type\":\"function\",\"name\":\"maxBlockNumberDiff\",\"inputs\":[],\"outputs\":[{\"name\":\"\",\"type\":\"uint256\",\"internalType\":\"uint256\"}],\"stateMutability\":\"view\"},{\"type\":\"function\",\"name\":\"owner\",\"inputs\":[],\"outputs\":[{\"name\":\"\",\"type\":\"address\",\"internalType\":\"address\"}],\"stateMutability\":\"view\"},{\"type\":\"function\",\"name\":\"reinitialize\",\"inputs\":[{\"name\":\"i\",\"type\":\"uint8\",\"internalType\":\"uint8\"},{\"name\":\"_initialOwner\",\"type\":\"address\",\"internalType\":\"address\"},{\"name\":\"_attestationAddr\",\"type\":\"address\",\"internalType\":\"address\"},{\"name\":\"_maxBlockNumberDiff\",\"type\":\"uint256\",\"internalType\":\"uint256\"},{\"name\":\"_attestValiditySeconds\",\"type\":\"uint256\",\"internalType\":\"uint256\"}],\"outputs\":[],\"stateMutability\":\"nonpayable\"},{\"type\":\"function\",\"name\":\"renounceOwnership\",\"inputs\":[],\"outputs\":[],\"stateMutability\":\"nonpayable\"},{\"type\":\"function\",\"name\":\"submitLivenessProofV2\",\"inputs\":[{\"name\":\"_data\",\"type\":\"tuple\",\"internalType\":\"structTEELivenessVerifier.ReportDataV2\",\"components\":[{\"name\":\"pubkey\",\"type\":\"tuple\",\"internalType\":\"structTEELivenessVerifier.Pubkey\",\"components\":[{\"name\":\"x\",\"type\":\"bytes32\",\"internalType\":\"bytes32\"},{\"name\":\"y\",\"type\":\"bytes32\",\"internalType\":\"bytes32\"}]},{\"name\":\"referenceBlockNumber\",\"type\":\"uint256\",\"internalType\":\"uint256\"},{\"name\":\"referenceBlockHash\",\"type\":\"bytes32\",\"internalType\":\"bytes32\"},{\"name\":\"proverAddressHash\",\"type\":\"bytes32\",\"internalType\":\"bytes32\"}]},{\"name\":\"_report\",\"type\":\"bytes\",\"internalType\":\"bytes\"}],\"outputs\":[],\"stateMutability\":\"nonpayable\"},{\"type\":\"function\",\"name\":\"transferOwnership\",\"inputs\":[{\"name\":\"newOwner\",\"type\":\"address\",\"internalType\":\"address\"}],\"outputs\":[],\"stateMutability\":\"nonpayable\"},{\"type\":\"function\",\"name\":\"verifyAttestationV2\",\"inputs\":[{\"name\":\"pubkeyX\",\"type\":\"bytes32\",\"internalType\":\"bytes32\"},{\"name\":\"pubkeyY\",\"type\":\"bytes32\",\"internalType\":\"bytes32\"},{\"name\":\"data\",\"type\":\"bytes\",\"internalType\":\"bytes\"}],\"outputs\":[{\"name\":\"\",\"type\":\"bool\",\"internalType\":\"bool\"}],\"stateMutability\":\"view\"},{\"type\":\"function\",\"name\":\"verifyLivenessProof\",\"inputs\":[{\"name\":\"pubkeyX\",\"type\":\"bytes32\",\"internalType\":\"bytes32\"},{\"name\":\"pubkeyY\",\"type\":\"bytes32\",\"internalType\":\"bytes32\"}],\"outputs\":[{\"name\":\"\",\"type\":\"bool\",\"internalType\":\"bool\"}],\"stateMutability\":\"view\"},{\"type\":\"function\",\"name\":\"verifyMrEnclave\",\"inputs\":[{\"name\":\"_mrenclave\",\"type\":\"bytes32\",\"internalType\":\"bytes32\"}],\"outputs\":[{\"name\":\"\",\"type\":\"bool\",\"internalType\":\"bool\"}],\"stateMutability\":\"view\"},{\"type\":\"function\",\"name\":\"verifyMrSigner\",\"inputs\":[{\"name\":\"_mrsigner\",\"type\":\"bytes32\",\"internalType\":\"bytes32\"}],\"outputs\":[{\"name\":\"\",\"type\":\"bool\",\"internalType\":\"bool\"}],\"stateMutability\":\"view\"},{\"type\":\"event\",\"name\":\"Initialized\",\"inputs\":[{\"name\":\"version\",\"type\":\"uint8\",\"indexed\":false,\"internalType\":\"uint8\"}],\"anonymous\":false},{\"type\":\"event\",\"name\":\"OwnershipTransferred\",\"inputs\":[{\"name\":\"previousOwner\",\"type\":\"address\",\"indexed\":true,\"internalType\":\"address\"},{\"name\":\"newOwner\",\"type\":\"address\",\"indexed\":true,\"internalType\":\"address\"}],\"anonymous\":false}]", + ABI: "[{\"type\":\"constructor\",\"inputs\":[],\"stateMutability\":\"nonpayable\"},{\"type\":\"function\",\"name\":\"attestValiditySeconds\",\"inputs\":[],\"outputs\":[{\"name\":\"\",\"type\":\"uint256\",\"internalType\":\"uint256\"}],\"stateMutability\":\"view\"},{\"type\":\"function\",\"name\":\"attestedProverAddr\",\"inputs\":[{\"name\":\"proverKey\",\"type\":\"bytes32\",\"internalType\":\"bytes32\"}],\"outputs\":[{\"name\":\"proverAddr\",\"type\":\"address\",\"internalType\":\"address\"}],\"stateMutability\":\"view\"},{\"type\":\"function\",\"name\":\"attestedProvers\",\"inputs\":[{\"name\":\"\",\"type\":\"bytes32\",\"internalType\":\"bytes32\"}],\"outputs\":[{\"name\":\"pubkey\",\"type\":\"tuple\",\"internalType\":\"structTEELivenessVerifier.Pubkey\",\"components\":[{\"name\":\"x\",\"type\":\"bytes32\",\"internalType\":\"bytes32\"},{\"name\":\"y\",\"type\":\"bytes32\",\"internalType\":\"bytes32\"}]},{\"name\":\"time\",\"type\":\"uint256\",\"internalType\":\"uint256\"}],\"stateMutability\":\"view\"},{\"type\":\"function\",\"name\":\"attestedReports\",\"inputs\":[{\"name\":\"\",\"type\":\"bytes32\",\"internalType\":\"bytes32\"}],\"outputs\":[{\"name\":\"\",\"type\":\"bool\",\"internalType\":\"bool\"}],\"stateMutability\":\"view\"},{\"type\":\"function\",\"name\":\"changeAttestValiditySeconds\",\"inputs\":[{\"name\":\"val\",\"type\":\"uint256\",\"internalType\":\"uint256\"}],\"outputs\":[],\"stateMutability\":\"nonpayable\"},{\"type\":\"function\",\"name\":\"changeAttestationImpl\",\"inputs\":[{\"name\":\"_attestationAddr\",\"type\":\"address\",\"internalType\":\"address\"}],\"outputs\":[],\"stateMutability\":\"nonpayable\"},{\"type\":\"function\",\"name\":\"changeMaxBlockNumberDiff\",\"inputs\":[{\"name\":\"_maxBlockNumberDiff\",\"type\":\"uint256\",\"internalType\":\"uint256\"}],\"outputs\":[],\"stateMutability\":\"nonpayable\"},{\"type\":\"function\",\"name\":\"dcapAttestation\",\"inputs\":[],\"outputs\":[{\"name\":\"\",\"type\":\"address\",\"internalType\":\"contractIAttestation\"}],\"stateMutability\":\"view\"},{\"type\":\"function\",\"name\":\"initialize\",\"inputs\":[{\"name\":\"_initialOwner\",\"type\":\"address\",\"internalType\":\"address\"},{\"name\":\"_attestationAddr\",\"type\":\"address\",\"internalType\":\"address\"},{\"name\":\"_maxBlockNumberDiff\",\"type\":\"uint256\",\"internalType\":\"uint256\"},{\"name\":\"_attestValiditySeconds\",\"type\":\"uint256\",\"internalType\":\"uint256\"}],\"outputs\":[],\"stateMutability\":\"nonpayable\"},{\"type\":\"function\",\"name\":\"maxBlockNumberDiff\",\"inputs\":[],\"outputs\":[{\"name\":\"\",\"type\":\"uint256\",\"internalType\":\"uint256\"}],\"stateMutability\":\"view\"},{\"type\":\"function\",\"name\":\"owner\",\"inputs\":[],\"outputs\":[{\"name\":\"\",\"type\":\"address\",\"internalType\":\"address\"}],\"stateMutability\":\"view\"},{\"type\":\"function\",\"name\":\"reinitialize\",\"inputs\":[{\"name\":\"i\",\"type\":\"uint8\",\"internalType\":\"uint8\"},{\"name\":\"_initialOwner\",\"type\":\"address\",\"internalType\":\"address\"},{\"name\":\"_attestationAddr\",\"type\":\"address\",\"internalType\":\"address\"},{\"name\":\"_maxBlockNumberDiff\",\"type\":\"uint256\",\"internalType\":\"uint256\"},{\"name\":\"_attestValiditySeconds\",\"type\":\"uint256\",\"internalType\":\"uint256\"}],\"outputs\":[],\"stateMutability\":\"nonpayable\"},{\"type\":\"function\",\"name\":\"renounceOwnership\",\"inputs\":[],\"outputs\":[],\"stateMutability\":\"nonpayable\"},{\"type\":\"function\",\"name\":\"submitLivenessProofV2\",\"inputs\":[{\"name\":\"_data\",\"type\":\"tuple\",\"internalType\":\"structTEELivenessVerifier.ReportDataV2\",\"components\":[{\"name\":\"pubkey\",\"type\":\"tuple\",\"internalType\":\"structTEELivenessVerifier.Pubkey\",\"components\":[{\"name\":\"x\",\"type\":\"bytes32\",\"internalType\":\"bytes32\"},{\"name\":\"y\",\"type\":\"bytes32\",\"internalType\":\"bytes32\"}]},{\"name\":\"referenceBlockNumber\",\"type\":\"uint256\",\"internalType\":\"uint256\"},{\"name\":\"referenceBlockHash\",\"type\":\"bytes32\",\"internalType\":\"bytes32\"},{\"name\":\"proverAddressHash\",\"type\":\"bytes32\",\"internalType\":\"bytes32\"}]},{\"name\":\"_report\",\"type\":\"bytes\",\"internalType\":\"bytes\"}],\"outputs\":[],\"stateMutability\":\"nonpayable\"},{\"type\":\"function\",\"name\":\"transferOwnership\",\"inputs\":[{\"name\":\"newOwner\",\"type\":\"address\",\"internalType\":\"address\"}],\"outputs\":[],\"stateMutability\":\"nonpayable\"},{\"type\":\"function\",\"name\":\"verifyAttestationV2\",\"inputs\":[{\"name\":\"pubkeyX\",\"type\":\"bytes32\",\"internalType\":\"bytes32\"},{\"name\":\"pubkeyY\",\"type\":\"bytes32\",\"internalType\":\"bytes32\"},{\"name\":\"data\",\"type\":\"bytes\",\"internalType\":\"bytes\"}],\"outputs\":[{\"name\":\"\",\"type\":\"bool\",\"internalType\":\"bool\"}],\"stateMutability\":\"view\"},{\"type\":\"function\",\"name\":\"verifyLivenessProof\",\"inputs\":[{\"name\":\"pubkeyX\",\"type\":\"bytes32\",\"internalType\":\"bytes32\"},{\"name\":\"pubkeyY\",\"type\":\"bytes32\",\"internalType\":\"bytes32\"}],\"outputs\":[{\"name\":\"\",\"type\":\"bool\",\"internalType\":\"bool\"}],\"stateMutability\":\"view\"},{\"type\":\"function\",\"name\":\"verifyLivenessProofV2\",\"inputs\":[{\"name\":\"pubkeyX\",\"type\":\"bytes32\",\"internalType\":\"bytes32\"},{\"name\":\"pubkeyY\",\"type\":\"bytes32\",\"internalType\":\"bytes32\"},{\"name\":\"proverKey\",\"type\":\"address\",\"internalType\":\"address\"}],\"outputs\":[{\"name\":\"\",\"type\":\"bool\",\"internalType\":\"bool\"}],\"stateMutability\":\"view\"},{\"type\":\"function\",\"name\":\"verifyMrEnclave\",\"inputs\":[{\"name\":\"_mrenclave\",\"type\":\"bytes32\",\"internalType\":\"bytes32\"}],\"outputs\":[{\"name\":\"\",\"type\":\"bool\",\"internalType\":\"bool\"}],\"stateMutability\":\"view\"},{\"type\":\"function\",\"name\":\"verifyMrSigner\",\"inputs\":[{\"name\":\"_mrsigner\",\"type\":\"bytes32\",\"internalType\":\"bytes32\"}],\"outputs\":[{\"name\":\"\",\"type\":\"bool\",\"internalType\":\"bool\"}],\"stateMutability\":\"view\"},{\"type\":\"event\",\"name\":\"Initialized\",\"inputs\":[{\"name\":\"version\",\"type\":\"uint8\",\"indexed\":false,\"internalType\":\"uint8\"}],\"anonymous\":false},{\"type\":\"event\",\"name\":\"OwnershipTransferred\",\"inputs\":[{\"name\":\"previousOwner\",\"type\":\"address\",\"indexed\":true,\"internalType\":\"address\"},{\"name\":\"newOwner\",\"type\":\"address\",\"indexed\":true,\"internalType\":\"address\"}],\"anonymous\":false}]", } // TEELivenessVerifierABI is the input ABI used to generate the binding from. @@ -225,6 +225,37 @@ func (_TEELivenessVerifier *TEELivenessVerifierCallerSession) AttestValiditySeco return _TEELivenessVerifier.Contract.AttestValiditySeconds(&_TEELivenessVerifier.CallOpts) } +// AttestedProverAddr is a free data retrieval call binding the contract method 0x80c19970. +// +// Solidity: function attestedProverAddr(bytes32 proverKey) view returns(address proverAddr) +func (_TEELivenessVerifier *TEELivenessVerifierCaller) AttestedProverAddr(opts *bind.CallOpts, proverKey [32]byte) (common.Address, error) { + var out []interface{} + err := _TEELivenessVerifier.contract.Call(opts, &out, "attestedProverAddr", proverKey) + + if err != nil { + return *new(common.Address), err + } + + out0 := *abi.ConvertType(out[0], new(common.Address)).(*common.Address) + + return out0, err + +} + +// AttestedProverAddr is a free data retrieval call binding the contract method 0x80c19970. +// +// Solidity: function attestedProverAddr(bytes32 proverKey) view returns(address proverAddr) +func (_TEELivenessVerifier *TEELivenessVerifierSession) AttestedProverAddr(proverKey [32]byte) (common.Address, error) { + return _TEELivenessVerifier.Contract.AttestedProverAddr(&_TEELivenessVerifier.CallOpts, proverKey) +} + +// AttestedProverAddr is a free data retrieval call binding the contract method 0x80c19970. +// +// Solidity: function attestedProverAddr(bytes32 proverKey) view returns(address proverAddr) +func (_TEELivenessVerifier *TEELivenessVerifierCallerSession) AttestedProverAddr(proverKey [32]byte) (common.Address, error) { + return _TEELivenessVerifier.Contract.AttestedProverAddr(&_TEELivenessVerifier.CallOpts, proverKey) +} + // AttestedProvers is a free data retrieval call binding the contract method 0x3b7a3d82. // // Solidity: function attestedProvers(bytes32 ) view returns((bytes32,bytes32) pubkey, uint256 time) @@ -456,6 +487,37 @@ func (_TEELivenessVerifier *TEELivenessVerifierCallerSession) VerifyLivenessProo return _TEELivenessVerifier.Contract.VerifyLivenessProof(&_TEELivenessVerifier.CallOpts, pubkeyX, pubkeyY) } +// VerifyLivenessProofV2 is a free data retrieval call binding the contract method 0xa14065dc. +// +// Solidity: function verifyLivenessProofV2(bytes32 pubkeyX, bytes32 pubkeyY, address proverKey) view returns(bool) +func (_TEELivenessVerifier *TEELivenessVerifierCaller) VerifyLivenessProofV2(opts *bind.CallOpts, pubkeyX [32]byte, pubkeyY [32]byte, proverKey common.Address) (bool, error) { + var out []interface{} + err := _TEELivenessVerifier.contract.Call(opts, &out, "verifyLivenessProofV2", pubkeyX, pubkeyY, proverKey) + + if err != nil { + return *new(bool), err + } + + out0 := *abi.ConvertType(out[0], new(bool)).(*bool) + + return out0, err + +} + +// VerifyLivenessProofV2 is a free data retrieval call binding the contract method 0xa14065dc. +// +// Solidity: function verifyLivenessProofV2(bytes32 pubkeyX, bytes32 pubkeyY, address proverKey) view returns(bool) +func (_TEELivenessVerifier *TEELivenessVerifierSession) VerifyLivenessProofV2(pubkeyX [32]byte, pubkeyY [32]byte, proverKey common.Address) (bool, error) { + return _TEELivenessVerifier.Contract.VerifyLivenessProofV2(&_TEELivenessVerifier.CallOpts, pubkeyX, pubkeyY, proverKey) +} + +// VerifyLivenessProofV2 is a free data retrieval call binding the contract method 0xa14065dc. +// +// Solidity: function verifyLivenessProofV2(bytes32 pubkeyX, bytes32 pubkeyY, address proverKey) view returns(bool) +func (_TEELivenessVerifier *TEELivenessVerifierCallerSession) VerifyLivenessProofV2(pubkeyX [32]byte, pubkeyY [32]byte, proverKey common.Address) (bool, error) { + return _TEELivenessVerifier.Contract.VerifyLivenessProofV2(&_TEELivenessVerifier.CallOpts, pubkeyX, pubkeyY, proverKey) +} + // VerifyMrEnclave is a free data retrieval call binding the contract method 0x18a98d6f. // // Solidity: function verifyMrEnclave(bytes32 _mrenclave) view returns(bool) diff --git a/contracts/script/DeployTEELivenessService.s.sol b/contracts/script/DeployTEELivenessService.s.sol index 4303e97..15eb979 100644 --- a/contracts/script/DeployTEELivenessService.s.sol +++ b/contracts/script/DeployTEELivenessService.s.sol @@ -200,6 +200,7 @@ contract DeployTEELivenessVerifier is Script, DcapTestUtils, CRLParser { ); console.log("reuse proxy"); console.logAddress(verifierProxyAddr); + console.logAddress(address(proxyAdmin)); } else { console.log("Deploy new proxy"); EmptyContract emptyContract = new EmptyContract(); @@ -229,6 +230,7 @@ contract DeployTEELivenessVerifier is Script, DcapTestUtils, CRLParser { attestValiditySecs ); } + proxyAdmin.upgradeAndCall( ITransparentUpgradeableProxy(verifierProxyAddr), address(verifierImpl), diff --git a/contracts/src/core/TEELivenessVerifier.sol b/contracts/src/core/TEELivenessVerifier.sol index 54cf05d..fe84d05 100644 --- a/contracts/src/core/TEELivenessVerifier.sol +++ b/contracts/src/core/TEELivenessVerifier.sol @@ -31,6 +31,7 @@ contract TEELivenessVerifier is OwnableUpgradeable { // added at v2 uint256 public maxBlockNumberDiff; + mapping(bytes32 proverKey => address proverAddr) public attestedProverAddr; constructor() { _disableInitializers(); @@ -97,13 +98,13 @@ contract TEELivenessVerifier is OwnableUpgradeable { bytes32 reportHash = keccak256(_report); require(!attestedReports[reportHash], "report is already used"); - (, bytes32 reportDataHash) = splitBytes64(reportData); + (bytes32 proverBytes, bytes32 reportDataHash) = splitBytes64(reportData); require(dataHash == reportDataHash, "report data hash mismatch"); Prover memory prover = Prover(_data.pubkey, block.timestamp); - attestedProvers[ - keccak256(abi.encode(_data.pubkey.x, _data.pubkey.y)) - ] = prover; + bytes32 proverKey = keccak256(abi.encode(_data.pubkey.x, _data.pubkey.y)); + attestedProvers[proverKey] = prover; + attestedProverAddr[proverKey] = address(uint160(uint256(proverBytes))); attestedReports[reportHash] = true; } @@ -117,6 +118,19 @@ contract TEELivenessVerifier is OwnableUpgradeable { block.timestamp; } + function verifyLivenessProofV2( + bytes32 pubkeyX, + bytes32 pubkeyY, + address proverKey + ) public view returns (bool) { + bytes32 signer = keccak256(abi.encode(pubkeyX, pubkeyY)); + bool succ = attestedProvers[signer].time + attestValiditySeconds > block.timestamp; + if (!succ) { + return false; + } + return attestedProverAddr[signer] == proverKey; + } + function verifyAttestationV2( bytes32 pubkeyX, bytes32 pubkeyY, diff --git a/operator/operator.go b/operator/operator.go index 78b8d2b..abed5ae 100644 --- a/operator/operator.go +++ b/operator/operator.go @@ -324,9 +324,10 @@ func (o *Operator) processLineaTask(ctx context.Context, resp *aggregator.FetchT submitTaskTime := time.Now() // submit to aggregator if err := o.aggregator.SubmitTask(ctx, &aggregator.TaskRequest{ - Task: stateHeader, - Signature: sig, - OperatorId: o.operatorId, + Task: stateHeader, + Signature: sig, + OperatorId: o.operatorId, + ProverSignature: poe.PoeSignature, }); err != nil { return logex.Trace(err) } @@ -399,9 +400,10 @@ func (o *Operator) processScrollTask(ctx context.Context, resp *aggregator.Fetch submitTaskTime := time.Now() // submit to aggregator if err := o.aggregator.SubmitTask(ctx, &aggregator.TaskRequest{ - Task: stateHeader, - Signature: sig, - OperatorId: o.operatorId, + Task: stateHeader, + Signature: sig, + OperatorId: o.operatorId, + ProverSignature: poe.PoeSignature, }); err != nil { return logex.Trace(err) } diff --git a/scripts/attestation.sh b/scripts/attestation.sh index 6b38197..7c6ca74 100755 --- a/scripts/attestation.sh +++ b/scripts/attestation.sh @@ -22,9 +22,7 @@ function deploy() { ENV=$ENV \ _script script/DeployTEELivenessService.s.sol --sig $1'()' - teeVerifierAddr=$(_get_key $TEE_DEPLOY .TEELivenessVerifierProxy) - _set_key config/aggregator.json TEELivenessVerifierContractAddress $teeVerifierAddr - _set_key config/operator.json TEELivenessVerifierAddress $teeVerifierAddr + cat $TEE_DEPLOY } function set_validity_secs() { diff --git a/xtask/prover_client.go b/xtask/prover_client.go index 3c0f4a4..e8d0f70 100644 --- a/xtask/prover_client.go +++ b/xtask/prover_client.go @@ -53,11 +53,12 @@ func NewProverClient(url string) (*ProverClient, error) { } type PoeResponse struct { - NotReady bool `json:"not_ready"` - BatchId uint64 `json:"batch_id"` - StartBlock uint64 `json:"start_block"` - EndBlock uint64 `json:"end_block"` - Poe *Poe `json:"poe"` + NotReady bool `json:"not_ready"` + BatchId uint64 `json:"batch_id"` + StartBlock uint64 `json:"start_block"` + EndBlock uint64 `json:"end_block"` + Poe *Poe `json:"poe"` + PoeSignature hexutil.Bytes `json:"poe_signature"` } type Poe struct { diff --git a/xtask/task_manager.go b/xtask/task_manager.go index 76d128f..b6bb9c1 100644 --- a/xtask/task_manager.go +++ b/xtask/task_manager.go @@ -113,7 +113,8 @@ type TaskManager struct { tasksMutex sync.Mutex tasks map[TaskType]*TaskTuple - lineaPrevLog *types.Log + lineaMaxBlock int64 + lineaPrevLog *types.Log } type TaskTuple struct { @@ -128,7 +129,7 @@ type TaskInfo struct { Ext json.RawMessage } -func NewTaskManager(collector *xmetric.AggregatorCollector, sampling int64, referenceClient eth.Client, tasks []*TaskManagerConfig) (*TaskManager, error) { +func NewTaskManager(collector *xmetric.AggregatorCollector, sampling int64, lineaMaxBlock int64, referenceClient eth.Client, tasks []*TaskManagerConfig) (*TaskManager, error) { sources := make(map[string]*ethclient.Client) tracers := make(map[TaskType]*utils.LogTracer) contexts := make(map[TaskType]*TaskContext) @@ -139,6 +140,7 @@ func NewTaskManager(collector *xmetric.AggregatorCollector, sampling int64, refe contexts: contexts, collector: collector, referenceClient: referenceClient, + lineaMaxBlock: lineaMaxBlock, tasks: make(map[TaskType]*TaskTuple, MaxTaskType), } @@ -296,6 +298,9 @@ func (t *TaskManager) onLineaTask(ctx context.Context, _ *ethclient.Client, log startBlock := new(big.Int).SetBytes(prevLog.Topics[1][:]).Int64() + 1 endBlock := new(big.Int).SetBytes(log.Topics[1][:]).Int64() + if endBlock-startBlock > t.lineaMaxBlock { + startBlock = startBlock - endBlock + } batchId := endBlock // can't determine the batch, so we use the end block number logex.Infof("generating task[linea] for #%v, refblk: %v", batchId, referenceBlockNumber) @@ -323,7 +328,7 @@ func (t *TaskManager) onLineaTask(ctx context.Context, _ *ethclient.Client, log return nil } if err != nil { - return logex.Trace(err, fmt.Sprintf("fetching context for scroll batchId#%v", batchId)) + return logex.Trace(err, fmt.Sprintf("fetching context for linea batchId#%v", batchId)) } generateContextCost := time.Since(startGenerateContext).Truncate(time.Millisecond) @@ -395,7 +400,7 @@ func (t *TaskManager) onScrollTask(ctx context.Context, source *ethclient.Client return logex.Trace(err) } - t.updateTask(*taskInfo) + // t.updateTask(*taskInfo) startGenerateContext := time.Now() taskCtx, ignore, err := prover.GenerateScrollContext(ctx, startBlock, endBlock, taskInfo.Type) From 0dce95d56c65ab9a720eb4fedbdc8a1ac5e61585 Mon Sep 17 00:00:00 2001 From: ChenYe Date: Wed, 23 Oct 2024 07:01:20 +0000 Subject: [PATCH 2/3] add datrylock log --- xtask/prover_client.go | 1 + 1 file changed, 1 insertion(+) diff --git a/xtask/prover_client.go b/xtask/prover_client.go index e8d0f70..11ac3af 100644 --- a/xtask/prover_client.go +++ b/xtask/prover_client.go @@ -94,6 +94,7 @@ func (p *ProverClient) DaTryLock(ctx context.Context, hash common.Hash) (string, if err := p.client.CallContext(ctx, &result, "da_tryLock", hash); err != nil { return "", logex.Trace(err) } + logex.Infof("DA TryLock[%v]: %v", hash, result) return result, nil } From f6fad83f293582b30472f8e26c7fb86dde9d7f00 Mon Sep 17 00:00:00 2001 From: ChenYe Date: Wed, 23 Oct 2024 07:49:19 +0000 Subject: [PATCH 3/3] update sgx-prover commit --- sgx-prover | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sgx-prover b/sgx-prover index ce877eb..69c8a11 160000 --- a/sgx-prover +++ b/sgx-prover @@ -1 +1 @@ -Subproject commit ce877ebc1489fda3d24296d45bc525a5badbc581 +Subproject commit 69c8a1179fbea477c0f996b38b2704c6c3381fc6