Skip to content

Commit

Permalink
Merge pull request #3 from divaprotocol/fix/2-tellor-evmcall
Browse files Browse the repository at this point in the history
Fix Tellor EVMCall implementation in DIVAOwnershipSecondary and update OZ libs
  • Loading branch information
Walodja1987 authored Apr 25, 2023
2 parents 72bcd26 + 6da81ca commit b9f8b75
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 16 deletions.
7 changes: 5 additions & 2 deletions contracts/DIVAOwnershipSecondary.sol
Original file line number Diff line number Diff line change
Expand Up @@ -110,11 +110,14 @@ contract DIVAOwnershipSecondary is UsingTellor, IDIVAOwnershipSecondary {
{
// Construct Tellor queryData and queryId:
// https://github.com/tellor-io/dataSpecs/blob/main/types/EVMCall.md
// 0xa18a186b = bytes4(keccak256(abi.encodePacked("getCurrentOwner()")));
queryData =
abi.encode(
"EVMCall",
abi.encode(_mainChainId, _ownershipContractMainChain, 0xa18a186b)
abi.encode(
_mainChainId,
_ownershipContractMainChain,
abi.encodeWithSignature("getCurrentOwner()")
)
);

queryId = keccak256(queryData);
Expand Down
2 changes: 1 addition & 1 deletion contracts/interfaces/IDIVAOwnershipSecondary.sol
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ interface IDIVAOwnershipSecondary is IDIVAOwnershipShared {
* for reporting values to Tellor protocol.
* @dev The query data is an encoded string consisting of the query type
* string "EVMCall", the main chain Id (1 for Ethereum), the address of
* the ownership contract on main chain as well as the function signature of the main
* the ownership contract on main chain as well as the encoded function signature of the main
* chain function `getCurrentOwner()` (`0xa18a186b`). The query Id is the `keccak256`
* hash of the query Data. Refer to the Tellor specs
* (https://github.com/tellor-io/dataSpecs/blob/main/types/EVMCall.md)
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,8 @@
"xdeployer": "^1.1.20"
},
"dependencies": {
"@openzeppelin/contracts": "^4.7.3",
"@openzeppelin/contracts-upgradeable": "^4.8.0-rc.1",
"@openzeppelin/contracts": "^4.8.3",
"@openzeppelin/contracts-upgradeable": "^4.8.3",
"eip-712": "^1.0.0",
"trees": "^0.0.4"
},
Expand Down
18 changes: 10 additions & 8 deletions test/DIVAOwnershipSecondary.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,19 @@ const network = "goerli"; // for tellorPlayground address; should be the same as
const mainChainId = 5;

const getQueryDataAndId = (chainId: number, ownershipContractAddressMain: string): [string, string] => {
// 0xa18a186b = bytes4(keccak256(abi.encodePacked("getCurrentOwner")));
// Encode bytes4 value according to the Ethereum ABI specification, i.e. pad it with leading zeros
// to fill an entire 32-byte (64 bits) slot.
const hexValue = 'a18a186b';
const paddedHexValue = hexValue.padStart(64, '0');
const prefixedHexValue = '0x' + paddedHexValue; // 00000000000000000000000000000000000000000000000000000000a18a186b

// Perform equivalent of `abi.encodeWithSignature("getCurrentOwner()")` in Solidity using ethers
const ABI = [
"function getCurrentOwner()"
];
const iface = new ethers.utils.Interface(ABI);
const encodedFunctionSignature = iface.encodeFunctionData("getCurrentOwner"); // 0xa18a186b

// Generate `queryData` and `queryId`
const abiCoder = new ethers.utils.AbiCoder();
const queryDataArgs = abiCoder.encode(
["uint256", "address", "bytes32"],
[chainId, ownershipContractAddressMain, prefixedHexValue] // 0xa18a186b = bytes4(keccak256(abi.encodePacked("getCurrentOwner")));
["uint256", "address", "bytes"],
[chainId, ownershipContractAddressMain, encodedFunctionSignature]
);
const queryData = abiCoder.encode(
["string", "bytes"],
Expand Down
6 changes: 3 additions & 3 deletions test/EIP712.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -865,7 +865,7 @@ describe("EIP712", async function () {
signature,
offerCreateContingentPool.takerCollateralAmount
)
).to.be.revertedWith("ECDSA: invalid signature 'v' value");
).to.be.revertedWith("ECDSA: invalid signature");
});

it("Reverts if offerExpiry has passed (offer status = EXPIRED)", async () => {
Expand Down Expand Up @@ -3234,7 +3234,7 @@ describe("EIP712", async function () {
signature,
offerAddLiquidity.takerCollateralAmount
)
).to.be.revertedWith("ECDSA: invalid signature 'v' value");
).to.be.revertedWith("ECDSA: invalid signature");
});

it("Reverts if offerExpiry has passed (offer status = EXPIRED)", async () => {
Expand Down Expand Up @@ -5668,7 +5668,7 @@ describe("EIP712", async function () {
signature,
offerRemoveLiquidity.positionTokenAmount
)
).to.be.revertedWith("ECDSA: invalid signature 'v' value");
).to.be.revertedWith("ECDSA: invalid signature");
});

it("Reverts if offerExpiry has passed (offer status = EXPIRED)", async () => {
Expand Down

0 comments on commit b9f8b75

Please sign in to comment.