Skip to content

Commit

Permalink
verifyOracleData passing
Browse files Browse the repository at this point in the history
  • Loading branch information
tkernell committed Dec 14, 2023
1 parent 7ab766b commit 09ea9b9
Show file tree
Hide file tree
Showing 7 changed files with 77 additions and 116 deletions.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"_format": "hh-sol-dbg-1",
"buildInfo": "../../../build-info/ad3ff5239657765be100e630e19a9bad.json"
"buildInfo": "../../../build-info/1a333890ddd82adacbe56d6ded10c3eb.json"
}

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions evm/cache/solidity-files-cache.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
"_format": "hh-sol-cache-2",
"files": {
"/Users/timothykernell/Documents/tellor/cosmos/layer/evm/contracts/bridge/BlobstreamO.sol": {
"lastModificationDate": 1702526944428,
"contentHash": "00c5f3c861597e8be3bca344a9d45c80",
"lastModificationDate": 1702562434384,
"contentHash": "5b51be545d9600071f6b0665c54ceb01",
"sourceName": "contracts/bridge/BlobstreamO.sol",
"solcConfig": {
"version": "0.8.22",
Expand Down
1 change: 1 addition & 0 deletions evm/contracts/bridge/BlobstreamO.sol
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ contract BlobstreamO is ECDSA {
revert SuppliedValidatorSetInvalid();
}

// possibly no nonce input needed here,
if (_attest.validatorNonce != validatorNonce) {
revert InvalidValidatorSetNonce();
}
Expand Down
79 changes: 40 additions & 39 deletions evm/test/BridgeTestManualDelete.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ describe("BlobstreamO Manual - Function Tests", function () {
await bridge.deployed();
});

it("init test", async function () {
it("constructor", async function () {
valSet = [accounts[0].address, accounts[1].address]
powers = [1, 2]
nonce = 1
Expand All @@ -34,10 +34,9 @@ describe("BlobstreamO Manual - Function Tests", function () {
console.log("valCheckpoint: ", valCheckpoint)
})

it.only("updateValidatorSet", async function() {
it("updateValidatorSet", async function() {
newValAddrs = [accounts[1].address, accounts[2].address, accounts[3].address]
newPowers = [1, 2, 3]
newNonce = 2
newThreshold = 4
newValHash = await h.calculateValHash(newValAddrs, newPowers)
newValCheckpoint = h.calculateValCheckpoint(newValAddrs, newPowers, nonce, newThreshold)
Expand All @@ -46,47 +45,49 @@ describe("BlobstreamO Manual - Function Tests", function () {
sig1 = await accounts[1].signMessage(ethers.utils.arrayify(newValCheckpoint))
sig2 = await accounts[2].signMessage(ethers.utils.arrayify(newValCheckpoint))
sigStructArray = await h.getSigStructArray([sig1, sig2])
console.log("sig1: ", sig1)
console.log("sig2: ", sig2)
// resp = await bridge.deleteThisInputValSet([{addr: accounts[1].address, power: 1}, {addr: accounts[2].address, power: 2}])
tryRecoverResp = await bridge.tryRecoverPublic(newDigest, sig1)
console.log("tryRecoverResp: ", tryRecoverResp)
console.log("addr1: ", accounts[1].address)
console.log("testNewCheckpoint: ", newValCheckpoint)
await bridge.updateValidatorSet(newValHash, newThreshold, valSetArray, sigStructArray);
})

it("sigs", async function() {
const signer = accounts[1]
message0 = 'Hello, world!'
messageHash0 = ethers.utils.hashMessage(message0)
mysig = await signer.signMessage(message0)
console.log("mysig: ", mysig)
tryRecoverResp = await bridge.tryRecoverPublic(messageHash0, mysig)
console.log("tryRecoverResp: ", tryRecoverResp)
console.log("addr1: ", accounts[1].address)

console.log("\n\nBREAK\n\n")
const message = 'Hello, world!';
const messageHash = ethers.utils.hashMessage(message);
console.log("messageHash: ", messageHash)
console.log("message type: ", typeof(message))
console.log("messageHash type: ", typeof(messageHash))
const signature = await signer.signMessage(message);
console.log("sig type: ", typeof(signature))
console.log("signature: ", signature)

// Pass the hashed message and signature to tryRecover
const recoveredAddress = await bridge.tryRecoverPublic(messageHash, signature);

console.log('Original address:', signer.address);
console.log('Recovered address:', recoveredAddress);
it("verifyOracleData", async function() {
queryId = h.hash("myquery")
value = abiCoder.encode(["uint256"], [2000])
blocky = await h.getBlock()
timestamp = blocky.timestamp - 2
consensusThreshold = 3
blockTimestamp = timestamp + 1
valHash = await h.calculateValHash(initialValAddrs, initialPowers)

dataDigest = await h.getDataDigest(
queryId,
value,
timestamp,
consensusThreshold,
nonce,
threshold,
valHash,
blockTimestamp
)

})


valSetArray = await h.getValSetStructArray(initialValAddrs, initialPowers)
sig1 = await accounts[1].signMessage(ethers.utils.arrayify(dataDigest))
sig2 = await accounts[2].signMessage(ethers.utils.arrayify(dataDigest))
sigStructArray = await h.getSigStructArray([sig1, sig2])
oracleDataStruct = await h.getOracleDataStruct(
queryId,
value,
timestamp,
consensusThreshold,
nonce,
threshold,
valHash,
blockTimestamp
)


await bridge.verifyOracleData(
oracleDataStruct,
valSetArray,
sigStructArray
)
})

})
102 changes: 30 additions & 72 deletions evm/test/helpers/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,16 +100,21 @@ getEthSignedMessageHash = (messageHash) => {
return digest;
}

// getValSetStructArray = (valAddrs, powers) => {
// structArray = []
// for (i = 0; i < valAddrs.length; i++) {
// structArray[i] = {
// addr: abiCoder.encode(["address"], [valAddrs[i]]),
// power: abiCoder.encode(["uint256"], [powers[i]])
// }
// }
// return structArray
// }
getDataDigest = (queryId, value, timestamp, consensusThreshold, validatorNonce, powerThreshold, validatorSetHash, blockTimestamp) => {
const DOMAIN_SEPARATOR = "0x74656c6c6f7243757272656e744174746573746174696f6e0000000000000000"
console.log("DOMAIN_SEPARATOR: ", DOMAIN_SEPARATOR)
console.log("queryId: ", queryId)
console.log("value: ", value)
console.log("timestamp: ", timestamp)
console.log("consensusThreshold: ", consensusThreshold)
console.log("validatorNonce: ", validatorNonce)
console.log("powerThreshold: ", powerThreshold)
console.log("validatorSetHash: ", validatorSetHash)
console.log("blockTimestamp: ", blockTimestamp)
enc = abiCoder.encode(["bytes32", "bytes32", "bytes", "uint256", "uint256", "uint256", "uint256", "bytes32", "uint256"],
[DOMAIN_SEPARATOR, queryId, value, timestamp, consensusThreshold, validatorNonce, powerThreshold, validatorSetHash, blockTimestamp])
return hash(enc)
}

getValSetStructArray = (valAddrs, powers) => {
structArray = []
Expand All @@ -135,63 +140,18 @@ getSigStructArray = (sigs) => {
return structArray
}

getBlockHeaderMerkleParts = async (height) => {
url = "http://localhost:1317/layer/bridge/blockheadermerkleevm?height=" + height
try {
const response = await axios.get(url)
headerParts = response.data.blockheaderMerkleEvm
enc = {
versionAndChainIdHash: abiCoder.encode(["bytes32"], [headerParts.versionChainidHash]),
height: abiCoder.encode(["uint64"], [headerParts.height]),
timeSecond: abiCoder.encode(["uint64"], [headerParts.timeSecond]),
timeNanoSecondFraction: abiCoder.encode(["uint32"], [headerParts.timeNanosecond]),
lastBlockIdAndOther: abiCoder.encode(["bytes32"], [headerParts.lastblockidCommitHash]),
nextValidatorHashAndConsensusHash: abiCoder.encode(["bytes32"], [headerParts.nextvalidatorConsensusHash]),
lastResultsHash: abiCoder.encode(["bytes32"], [headerParts.lastresultsHash]),
evidenceAndProposerHash: abiCoder.encode(["bytes32"], [headerParts.evidenceProposerHash])
}
return enc
} catch (error) {
console.log(error)
}
}

getCommonEncodedVoteParts = async (height) => {
url = "http://localhost:1317/layer/bridge/tmsig?height=" + height
try {
const response = await axios.get(url)
common = response.data.common
// convert Base64 common parts to hex
prefix = "0x" + Buffer.from(common.SignedDataPrefix, 'base64').toString('hex')
suffix = "0x" + Buffer.from(common.SignedDataSuffix, 'base64').toString('hex')
notenc = {
signedDataPrefix: prefix,
signedDataSuffix: suffix
}
return notenc
} catch (error) {
console.log(error)
}
}

getTmSig = async (height) => {
url = "http://localhost:1317/layer/bridge/tmsig?height=" + height
try {
const response = await axios.get(url)
tmSig = response.data.tmSig
tmSigEnc = []
for (i = 0; i < tmSig.length; i++) {
tmSigEnc.push({
r: abiCoder.encode(["bytes32"], [tmSig[i].R]),
s: abiCoder.encode(["bytes32"], [tmSig[i].S]),
v: abiCoder.encode(["uint8"], [tmSig[i].V]),
// encodedTimestamp: abiCoder.encode(["bytes"], [tmSig[i].EncodedTimestamp])
encodedTimestamp: removeLeadingZeros(tmSig[i].EncodedTimestamp)
})
}
return tmSigEnc
} catch (error) {
console.log(error)
getOracleDataStruct = (queryId, value, timestamp, consensusThreshold, validatorNonce, powerThreshold, validatorSetHash, blockTimestamp) => {
return {
queryId: queryId,
report: {
value: value,
timestamp: timestamp,
consensusThreshold: consensusThreshold
},
validatorNonce: validatorNonce,
powerThreshold: powerThreshold,
validatorSetHash: validatorSetHash,
blockTimestamp: blockTimestamp
}
}

Expand Down Expand Up @@ -307,13 +267,11 @@ module.exports = {
expectThrow,
getLatestBlockNumber,
getValidatorSet,
getMultistore,
getBlockHeaderMerkleParts,
getCommonEncodedVoteParts,
getTmSig,
calculateValCheckpoint,
calculateValHash,
getEthSignedMessageHash,
getValSetStructArray,
getSigStructArray
getSigStructArray,
getOracleDataStruct,
getDataDigest
};

0 comments on commit 09ea9b9

Please sign in to comment.